More Moose Attibutes

It new attribute day here in the Moose-Pen.

Just a quick postette here today. I was thinking that it might be a good idea if I expanded my Database::Accessor API a little and give the end user the option of specifying a different 'default' condition that the present 'AND'.

As a good programmer I first added in a test;

$da = Database::Accessor->new($in_hash3);
ok($da->default_condition('OR'),'Change Defalut condition to OR');
$da->retrieve( Data::Test->new());
$da->result->error->gather->conditions->[1]->predicates->condition() eq
'OR added to last gather condition predicate'
ok( !$da->result->error->gather->conditions->[0]->predicates->condition(),
'OR not added to first gather condition predicate' );

and then my new attribute;

has default_condition => (
is => 'rw',
isa => 'Operator',
traits => ['MooseX::MetaDescription::Meta::Trait'],
default => Database::Accessor::Constants::AND(),
description => { not_in_DAD => 1 }


and then change the code to use the above;

--         $element->predicates->condition(Database::Accessor::Constants::AND)
++         $element->predicates->condition($self->default_condition())

and run my tests;

ok 9 - AND added to last gather condition predicate
ok 10 - Change Defalut condition to OR
ok 11 - OR added to last gather condition predicate
ok 12 - OR not added to first gather condition predicate
ok 13 - Caught unbalanced parentheses

can't get any better than that;

Now I was thinking what would happen is some smarty-pants did this;


the expected outcome would be two predicates without a conditional clause. Thanks to Moose what actually happens is;

Attribute (default_condition) does not pass the type
constraint because: The Operator '', is not a valid Accessor Operator!
Try one of '!=', '<', '<=', '<>', '=', '>', '>=', 'AND',
at accessor Database::Accessor::default_condition...

So Mrs smarty-pants can't get very far.


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