Not Tomorrow for Moose

No!! Still on a case here in the Moose-Pen.

I just started my first test for '22_fields_extended.t' and then I saw one other little point I forgot to take into account. I should add in some validation for my 'Case' class as it is invalid to have a case that has only one condition.

Therefore this test;


like(exception {Database::Accessor::Case->new( {
whens => [
{
left => { name => 'Price', },
right => { value => '10' },
operator => '<',
statement => { whens => [
{
left => { name => 'Price', },
right => { value => '10' },
operator => '<',
statement => { name => 'price' }
},
] }
}]})},
qr /Validation failed for \'ArrayRefofWhens\'/,
"Case Fails with less than 2 whens"
);

should pass and of course it fails right now;

...
ok 25 - big when [4] statment is a Expression
not ok 26 - Case Fails with less than 2 whens

Now the fix is quite simple all I need to do is add in a little check on the '_element_coerce' sub in 'Database::Accessor::Types';

...
elsif ( exists( $hash->{value} ) || exists( $hash->{param} ) ) {
$object = Database::Accessor::Param->new( %{$hash} );
}
elsif ( exists( $hash->{whens} )) {
++ die "Attribute (whens) does not pass the type constraint because:
++ Validation failed for 'ArrayRefofWhens' with less than 2 whens"
++ if (exists($hash->{whens})
++ and ref($hash->{whens}) eq 'ARRAY'
++ and scalar(@{$hash->{whens}} <2));
$object = Database::Accessor::Case->new( %{$hash} );
}
else {

and when I run my test again I get;

ok 25 - big when [4] statement is a Expression
ok 26 - Case Fails with less than 2 whens

a full pass and I think, pray and hope that I can get into Driver::DBI tomorrow.
IMG_4309a.jpg

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