Cleaning Up Moose Poop

Well sometimes the Moose-pen is empty and sometimes it is filled up today I am sort of up in the air what state I am in today.

One thing we have seen in many of my posts is great lines of I like to call moose poop or the lines upon lines of error reports. Many times they even confuse me and send me running down all sorts of Moose holes.

So I am going to try to clean a few of them up. The first one I am going to get after is not even an error just a waring telling the programmer that a DAD cannot load which we first saw in this post. The moose poop was about 40 lines of stuff when really only the first line counted.

eval "require $classname";
if ($@) {
my $err = $@;
my $advice =
"Database/Accessor/DAD/$file ($classname) may not be an Database Accessor Driver (DAD)!\n\n";
"\n\n Load of Database/Accessor/DAD/$ failed: \n Error=$err \n $advice\n"

Above is my code from the _loadDADClassesFromDir sub in and as you can see I simply warn with the full $@ which starts with

Database::Accessor::Roles::DAD' requires the method 'execute' to be implemented by 'Database::Accessor::DAD::SQL' at C:\Dwimperl\perl\site\lib\Moose\ line 419
Moose::with('Database::Accessor::Roles::DAD') called at ..\t\lib\Database\Accessor\DAD\ line 8

Now it is a good thing about moose poop is that there is usually an ' at ' in the first line of the error and at least in this case I really only care about the message to that point so a quick change

– my $err = $@;
++ my $err = substr($@,0,index($@,' at '));

and now rater than 40 lines ow warning message I get

Load of Database/Accessor/DAD/ failed:
Error='Database::Accessor::Roles::DAD' requires the method 'execute' to be implemented by 'Database::Accessor::DAD::SQL'
Database/Accessor/DAD/SQL (Database::Accessor::DAD::SQL) may not be an Database Accessor Driver (DAD)!

Neat and easy to understand and enough for today and here is a better use for Moose Poop


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations