Mostly Tested Moose

Its get nowhere day here in the Moose-Pen

So I was all set to for today's post to move from playing with Database::Accessor and start playing with Driver::DBI again but just as I was finishing off the tests which I did not want to bore you with I got this:


...
ok 7 - Balanced parentheses
no ok 8 - AND not added to first gather condition predicate
ok 9 - AND added to last gather condition predicate

ok 26 - AND not present on first link predicate
not ok 27 - AND not present on first link predicate
not ok 28 - AND not present on second link predicate
ok 29 - AND added to second link predicate
...

Better get that fixed before I move along.

In all the fails above, I am dealing with the situation where the 'conditions' that are being checked will come into the check function as an 'Array-Ref' as both Gather and Link use a 'conditions' key like
this;


conditions => [
{
left => {name=>'salary'},
right => { value => '200' },
operator => '=',
},
{
left => {name=>'bonus'},
right => { value => '50' },
operator => '=',
}
]
}

Which represents this conditional predicate set

salary=200 and bonus =50


My last code to handle the above was;

     if (ref($condition) eq 'ARRAY'){
               $self->_reset_conditions();                
               $self->_inc_conditions()
                  if (scalar(@{$condition}) >=2 and ref($condition->[0]) eq 'Database::Accessor::Condition');
                map( $self->_check_element($_),@{$condition});


}
else {


What is happing is this check;

$self->_inc_conditions()
                  if (scalar(@{$condition}) >=2 and ref($condition->[0]) eq 'Database::Accessor::Condition');

will set up the proper value when there is only more that one 'condition' but will fail when there are say two links present each and one or more had more that one condition.

After a great deal of debugging I finally had to take that 'map' out of the code as it was there that my increment counts where getting buggered up, I was not incrementing during the map. In the end I swapped out that map with a foreach and only incrementing when the $item was a 'Condition' class like this;


if (ref($condition) eq 'ARRAY'){
$self->_reset_conditions();
foreach my $item (@{$condition}){
$self->_inc_conditions()
if (ref($item) eq 'Database::Accessor::Condition');
$self->_check_element($item);
}

and I now get

... ok 7 - Balanced parentheses ok 8 - AND not added to first gather condition predicate ok 9 - AND added to last gather condition predicate … ok 26 - AND not present on first link predicate ok 27 - AND not present on first link predicate ok 28 - AND not present on second link predicate ok 29 - AND added to second link predicate ...
Well that is the postette for today. As I had a little extra time and was still in Accessor.pm I took the opportunity to swap about out some var names, rename an attribute or two and dump out a bunch of commented out code, to make the Accessor.pm a little easier to read.


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