Moose Jaw Lawyer

Today in the Moose-Pen I decidedt to fillan give another go at trying to enforce my DAD writers to include a sub like this


sub retrieve {
my $self = shift;
if ( $self->alias() ) {
return $self->name() . " AS " . $self->alias();
}
else {
return $self->name();
}
}

in their DAD drivers that would be added in this case to the Database::Accessor::Element class. This you might remember from my earlier posts, the idea being each of by Database::Accessor classes would have their own function for each part of code generation.

So today I looked at 'MooseX::Role::Parameterized' as a way I might be able to do that. Well lets just asy I spend a good few hours setting it all up and in the end I had some code in my DAD role that looked like this;


role {

my $role = shift;
my %opts = @_;
my $consumer = $opts{consumer};

my $Eelement = $consumer->find_method_by_name('element_retrieve')
or confess "You must have a 'element_retrieve' method";
….

well I did on or two more of these until I was not gaining anything, except extra lines of coed, as I could of just did this

requires 'DB_Class';
requires 'Execute';
requires 'element_retrieve'';


Now my error messages where better than miles of Moose Poop one usually gets but that is a little high price to pay just for that. What I see now is that 'MooseX::Role::Parameterized' is a really good solution when you have some required Attributes for your role or you need to rename attributes coming into the role, neither of which I need.

What this MooseX is very good at is consuming very complex roles so if I have time I might see if I can use it in the section of my code that loads in the DADs. So for now I am just going to go on my merry way without it.

So I started adding in all the various required function for the differing Database::Accessor classes and then it dawned on my that I should not be doing this at all. Looking at things I would thing it is 100% up to the DAD writer to come up with her own functions to handle how the end code is created I need only supply the building block in the form of my static and dynamic attributes.

So no new code today just a few lessons learned.

find-a-moose-jaw-lawyer.png

I still don't know why a Moose would need a Jaw Lawyer??

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