Backtracking Baby Moose

Well no progress day here in the Moose-Pen

After yesterday's post where I decided to much more validation on the Accessor side of things I had a chance to takke a deep and close look at Accessor.pm.

A code review is always a good thing and I found a few problems right from the start, in mose of my CRUD functions I was still doing this


return $container;

which is dead wrong and funny thing I did not have a check for this. So today I added that in with a simple change to 20_dad_load.t

ok($da_new->$type(Data::Test->new(),$container),"$type Query ran");
--ok($da_new->$type(Data::Test->new(),$container) == 1,"$type Query ran");

now I will get a fail if anything other than '1' is returned and as I am using canned data I know this will be the case. The good thing as this ran I got this fail

not ok 4 - Role DAD can all_elements_present

so I had to make this change;

has [
qw(da_compose_only
da_no_effect
da_warning
-- all_elements_present
)
] => (
is => 'rw',
isa => 'Bool',
default => 0,
traits => ['ENV'],
);

has [
qw(all_elements_present
)
] => (
is => 'rw',
isa => 'Bool',
default => 0,
traits => ['ENV', 'MooseX::MetaDescription::Meta::Trait'],
description => { not_in_DAD => 1 }
);


as I no longer want to do any check on this in any DAD as I make it at the Accessor level.

Next I noticed that is is possible to enter an Element without a view, as I would assume it is just the same as the accessors View. As a result I will have to some checking for the view in my validation logic and I will also force my DAD writers to add in logic for it as well. This I want to avoid so in 'around BUILDARGS' I added this in;


foreach my $element (@{ $ops->{elements}}){
$element->{view} = $view_name
if (!exists($element->{expression})
and !exists($element->{function})
and !exists($element->{value})
and $element->{view} eq undef );
}

which will set the view of all 'elements' as they go in if they happen to be empty. I also modified 31_elements.t by takeing out the 'view' key on the first element and then adding this test

ok($da->elements->[0]->view eq 'People', "View taked from DA view name");

Finally for today I noticed I had this;

has dynamic_elements => (
isa => 'ArrayRefofElements',
traits => ['Array'],
is => 'rw',
default => sub { [] },
init_arg => undef,
handles => {
add_element => 'push',
dynamic_element_count => 'count',
},
);

This attribute meas I can add in elements on the fly something that was a flaw in the first Data::Accessor as an end user was able to do CRUD operations on fields that they may not of had access to. So I commented it out for now and I will have to drop the 41_dynamic_elements.t test case.

Well that is a bunch of things done and I still have not done a full code review. Oh well most post fodder.

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