Big Moose Almost Ready

Its back to view day here in the Moose-Pen

Today I am going to carry on with getting full coverage for test case '57_dad_elements.t' and fixing the bug I found in yesterays post.

First the bug. I am missing the view in the last left of this nested element;

bless( {
'predicates' => bless( {
'operator' => '=',
'left' => bless( {
'left' => bless( {
'name' => 'bonus'
'Database::Accessor::Element' ),

and the test for it is

$elements->[3]->predicates->left->left->view() eq 'People',
'Fourth condition left->left inherits view'

now I have checked the call with the underlying code for any typos and miss calls and I have confirmed that I most not be drilling down into this second nested 'left'. The problem must be in '_parentheses_check' sub and a quick read of that sub I see that in the where code I do the parentheses_check and I also drill down on the 'left' and 'right' only if they are an Element;

$self->check_view( $predicate->right )
if (
ref( $predicate->right ) eq 'Database::Accessor::Element' );
$self->check_view( $predicate->left )
if (
ref( $predicate->left ) eq 'Database::Accessor::Element' );

however in this case the first 'left' is an 'Database::Accessor::Expression' so I am skipping the drill down. To boot I also noticed that the I should be doing the parentheses checking at each level of nesting, the way I am doing it here will only check the top most layer of predicates and skip any of the nested layers. Time for a rewrite!

First I simplified the iteration code in the '_parentheses_check' sub to just this;

foreach my $condition (@items) {

now I am free to do recursion on all elements. Next I fixed up the 'check_view' sub by first renaming it to '_check_view' to be consistent with the other private methods in the code. I then modified it to account for a 'Condition' class

if (ref($element) eq 'Database::Accessor::Element'){
unless ( $element->view() ) {
$element->view( $self->view->name() );
$element->view( $self->view()->alias() )
if ( $self->view()->alias() );
++ elsif (ref($element) eq 'Database::Accessor::Condition'){
++ $self->_check_view($element->predicates->right);
++ $self->_check_view($element->predicates->left);
++ }
else {

and in that modification I simply drill down on the left and right attributes of the conditions' predicate attribute. Finally I noticed I could clean up the last bit of code by using a little Moose so I fixed that as well

else {
++ unless(does_role($element,"Database::Accessor::Roles::Comparators"));
-- if ((ref($element) ne "Database::Accessor::Function")
-- and
-- (ref($element) ne "Database::Accessor::Expression")
-- and
-- (ref($element) ne "Database::Accessor::Predicate"));

So with that in place I re-ran '57_dad_elements.t' and what I have so far passes.

At this point I am going to continue and finish off the above test case as a have a few more nested predicates in attributes to check. Starting with links and dynamic links I will now have to handles those different that the others as they both have individual 'conditions' attributes.

First I pull them out of the general @items build

push( @items,
@{ $self->conditions },
@{ $self->dynamic_conditions },
-- @{ $self->links },
-- @{ $self->dynamic_links },

and then because they are both array-refs I have to add in

@{ $self->elements } );

++ foreach my $link ((@{ $self->links },@{ $self->dynamic_links })){
++ push(@items,$link->conditions);
++ }
if ( $self->gather() ) {

a little loop here to add in all the conditions and I get a full pass on my test;

Finally I set the last test up for Sorts and as they are just an array of elements they all passed which is sweet.

Just for kicks I ran '40_joins.t' case from Driver::DBI, which was failing before with a missing 'view' and now it passes so not a bad days work;


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