Yep. You guessed it. Yet Another Moose Post. Today in the Moose-Pen just a quick bit of code cleanup

I stumbled upon some of my early notes for this project today and it seems I forgot to include a MooseX I was keen on using from the beginning, I guess I forgot about it, so a little back programming today.

The MooseX is called 'MooseX::AlwaysCoerce' and it does what it says, forces all of your attributes to have

coerce => 1,

unless you set them to

coerce => 0,

It is quite funny really because if I used the above since the start I think I would of never run into some of the bugs I know I memtioned in other posts. Reading the POD for this MooseX the author says much the same.

Anyway on with the code. I really only added in this

use MooseX::AccessorsOnly;
++ use MooseX::AlwaysCoerce;
use Carp;

at the top of Accessor.pm and then did the old search and replace to get rid of my coerce commands. The first test cases worked great but when I ran the more complicated test cases like 33_conditions.t I ran into this

Attribute (predicates) does not pass the type constraint because: Validation failed for 'ArrayRefofPredicates' with value ..

opps another silly mistake took out too many of my 'coerce' commands. A few minutes later, after I added the 'coerce' command back into my Database::Accessor::* classes, I re-ran my tests and they all passed.

Now it is the old dilemma of taking one line of code out just to add one other line. In Accessor.pm I do have some four-teen lines that are replace by one but all of the other Classes in that file it is just the one to one swap so not much to gain there.

I also noticed that I reuse the same 'use' and 'with' statements over and over again. There must be a better way to fix that up.

Oh well at least I have post for tomorrow.


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