Reverted Moose Back on Track

Its pick and choose day here in the Moose-Pen

So I have made a decision to drop the new feature of checking dynamic adds as they come in. Fortunately I did this in a branch so all I really have to do is drop that branch from my repo and carry on where I left off.

Now before I do that I did have some good ideas while I was working with this branch which I plan to keep.

The first bit of code I am going to keep is the 'get_element_by_lookup' changes. I found this sub more useful than '_get_element_by_name' as the latter incorporates both the name and the view in the lookup. The code for ' get_element_by_lookup' was just not the addition to the 'elements' attribute it also included a new attribute on the 'elements'.

Now I did notice while I was playing within the branch I found another back-door in the system. I did have this;


has '_lookup_name' => (
is => 'ro',
isa => 'Str',
lazy=>1,
builder=>"_builder_lookup_name"
);

sub _builder_lookup_name {
my $self = shift;
return $self->view.$self->name;
}


and the back door was I could do this while adding for example a dynamic condition;

{
left => {
name => 'salary',
view => 'People',
_lookup_name =>'Peoplefirst_name'
},
right => { value => 'test' },
operator => '=',
},

I could fool the system by adding that _lookup_name on the in the config hash. Therefore I though I could to change it over to a private with this change;

has '_lookup_name' => (
is => 'rw',
isa => 'Str',
lazy=>1,
builder=>"_builder_lookup_name",
traits => [qw/Private/],
);

Unfortunately that doesn't do my any good as I now can't use that attribute from another class like this;

$da->elements->[0]->_lookup_name();

Will have to try this instead;

has '_lookup_name' => (
is => 'ro',
isa => 'Str',
lazy=>1,
builder=>"_builder_lookup_name",
++ init_arg => 'only_on_link',
);

Doesn't close the back door but it does make it a little harder to find it.

Now to get my tests in order. I really do not need a new one I just need to fix things up a little; Mostly I had to clean up 'Test::Database::Accessor::Utils' so it now handles the 'only_on_link' and the '_lookup_name' attribute correctly and that cleaned up all the test except '40_dynamic_not_present.t'
where we are back to;


not ok 1 - method add_condition attribute->condition is only allowed to have elements...
ok 2 - method add_gather attribute->view_elements is only allowed to have elements ...
not ok 3 - method add_gather attribute->elements is only allowed to have elements ...
not ok 4 - method add_gather attribute->conditions is only allowed to have elements ...
not ok 5 - method add_link attribute->link is only allowed to have elements that are in ...
not ok 6 - method add_sort attribute->sort is only allowed to have elements that are in ..

Now I have to fix things up for that test. I have to fix the test so it hits on the execute rather than the 'add_dynamic_xx';

foreach my $in_action (sort(keys(%{$params}))) {
my $action = $params->{$in_action}->{action};
my $da = Database::Accessor->new($in_hash);
my $command = "add_" . $action;
my $exception = $params->{$in_action}->{exception};
++ $da->$command( $params->{$in_action}->{query} );
like(
-- exception { $da->$command( $params->{$in_action}->{query} ) },
++ exception { $da->retrieve( Data::Test->new(), $return ) },
qr /$exception/,
"method add_$action attribute->".$params->{$in_action}->{caption}." is only allowed to have elements that are in the elements attribute"
);
}

and next a fix to the '_' function to account for that new 'get_element_by_lookup' call;

...
if (ref($element) eq 'Database::Accessor::Element'){
unless ( $element->view() ) {
$element->view( $self->view->name() );
}
++ die( "Gather view_element "
++ .$element->name()
++ ." in not in the elements array! Only elements from that array can be added" )
++ unless ($self->get_element_by_lookup($element->_lookup_name()));

}
elsif (ref($element) eq 'Database::Accessor::If'){


and get rid of the trigger on 'add_gater'

has dynamic_gather => (
isa => 'Gather|Undef',
traits => ['MooseX::MetaDescription::Meta::Trait'],
description => { not_in_DAD => 1 },
is => 'rw',
-- trigger => \&_check_elements_present
);

and now I get a full pass on that test;

ok 1 - method add_condition attribute->condition is only allowed to have elements...
ok 2 - method add_gather attribute->view_elements is only allowed to have elements ...
ok 3 - method add_gather attribute->elements is only allowed to have elements ...
ok 4 - method add_gather attribute->conditions is only allowed to have elements ...
ok 5 - method add_link attribute->link is only allowed to have elements that are in ...
ok 6 - method add_sort attribute->sort is only allowed to have elements that are in .

Now I can move on to see what test cases the above change has invalidate; This feels a little familiar but I guess that is a story for tomorrow.

moosetrack.jpg

2 Comments

To prevent setting the value on construction, set init_arg to undef

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