Even More Moose Attributes

Its extend API a little more Day here in the Moose-Pen

Since I was playing about with the API by adding in 'default_condition' for conditions I figured I might as well do the same for condition 'operator'. In my little abstract world the 'operator' is what I use to compare the 'left' and 'right' parts of a predicate.

Well first thing some tests;


$da = Database::Accessor->new($in_hash3);
ok($da->default_operator('!='),'Change Default operator to !=');
$da->retrieve( Data::Test->new());
ok(
$da->result->error->gather->conditions->[0]->predicates->operator() eq
'!=',
'First gather condition predicate operator is !='
);
ok( $da->result->error->gather->conditions->[1]->predicates->operator() eq '=',
'Second gather condition predicate is =' );

and next the new attribute;

has default_operator => (
is => 'rw',
isa => 'Operator',
traits => ['MooseX::MetaDescription::Meta::Trait'],
default => '=',
description => { not_in_DAD => 1 }

);


and a few changes else where for the above;

First get rid of its default value in the 'Database::Accessor::Predicate' class;


  has operator => (
            is      => 'rw',
            isa     => 'Operator',
--            default => '='
        );

Next add in the code to set the default value;

...
elsif (ref($element) eq 'Database::Accessor::Condition'){
++ $element->predicates->operator($self->default_operator())
++ if ( !$element->predicates->operator() );
$element->predicates->condition($self->default_condition())
if ( $self->_add_condition>=2 and !$element->predicates->condition() );


and give the tests a go;


ok 12 - OR not added to first gather condition predicate
ok 13 - Change Default operator to !=
ok 14 - First gather condition predicate operator is !=
ok 15 - Second gather condition predicate is =
ok 16 - Caught unbalanced parentheses


so that is two new attributes in a row without a major code breakdown. Might be a new record?

HPIM4886a.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