Moose should of stayed in bed

Still cleaning in here in the Moose-Pen

Well was all ready to move onto the final documentation and distzila stage of Database::Accessor and then I ran into a few little tings when I reran the full test suite.

First there was this annoying warning;


Use of uninitialized value $error_package in string eq at \GitHub\database-accessor\lib/Database/Accessor/Roles/AllErrors.pm line 59.

a simple fix really just this;

my $on ="";
-- if ($error_package eq "Database::Accessor::Element"){
++ if (($error_package) and ($error_package eq "Database::Accessor::Element")){
$on = " Possible missing/invalid key in or near:\n"
. Dumper($Database::Accessor::Types::LAST);
}

on the appropriate line in AllErrors.

Now the next error or bug really proved a little harder to solve. It only popped up when I fixed up one of my tests in '42_new_validation.t' and looked like this on testing


'Attribute (predicates) does not pass the type constraint because: Validation failed for 'Predicate' with value undef (not isa Database::Accessor::Predicate) at D:\GitHub\database-accessor\lib/Database/Accessor/Types.pm line 358'
# doesn't match '(?^:(conditions->operator))'

which it as the problem in the test was this;

conditions => {
left => {
name => 'last_name',
view => 'People'
},
right => { value => 'test' },
operator => undef,
}

the operator is 'undef' which should throw another error; more like this

Database::Accessor add_condition Error:
The following Attribute did not pass validation:
'conditions->operator' Constraint: The Operator 'undef', is not a valid Accessor Operator! Try one of '!=', '<', '<=', '<>', '=', '>', '>=', 'ALL', 'AND', 'ANY', 'BETWEEN', 'EXISTS', 'IN', 'IS NOT NULL', 'IS NULL', 'LIKE', 'NOT EXISTS', 'NOT IN', 'NOT LIKE', 'OR' With constructor hash:
{
'operator' => undef,
'left' => {
'view' => 'People',
'name' => 'last_name'
},
'right' => {
'value' => 'test'
}
}

Something odd was happening on the 'add_conditions' when it was running with the Test::Fatal as when I run the above inline I get the correct error.

Well after pocking about for a good 45 minutes I finally found the problem. I made a typo in my test and instead of passing the above 'conditions' hash I was passing in 'undef' like this


$da->add_condition(undef);

Well one more test to add;

This was very similar to the 'Link' conditions one I had a few posts ago except this time round I have this in Accessor.pm


has dynamic_conditions => (
isa => 'ArrayRefofConditions',
traits => ['Array','MooseX::MetaDescription::Meta::Trait'],


The dynamic is an ' ArrayRefofConditions' which allows undef or empty array ref. All that was needed is a new subtype that allows and empty arrayref but not undef in the 'Types” class;

subtype 'NoUndefArrayRefofConditions' => as 'ArrayRef[Condition]',
where { (ref($_)) }, message {
"conditions can not be a undef";
};

--foreach my $subtypes (qw(LinkArrayRefofConditions ArrayRefofConditions )) {
++foreach my $subtypes (qw(NoUndefArrayRefofConditions LinkArrayRefofConditions ArrayRefofConditions )) {
coerce $subtypes, from 'ArrayRef', via {
++


and then a quick change in Accessor.pm;

has dynamic_conditions => (
-- isa => 'ArrayRefofConditions',
++ isa => 'NoUndefArrayRefofConditions',
traits => ['Array','MooseX::MetaDescription::Meta::Trait'],


and I was getting a nice error like this;

Attribute (dynamic_conditions) does not pass the type constraint because: conditions can not be undef! at accessor Database::Accessor::dynamic_conditions (defined at D:\GitHub\database-accessor\lib\Database\Accessor.pm line 451) line 8

However on my next tests stopped dead in its tracks with this hard error;

Attribute (dynamic_conditions) does not pass the type constraint because: conditions can not be undef! at accessor Database::Accessor::dynamic_conditions (defined at D:\GitHub\database-accessor\lib\Database\Accessor.pm line 451) l


On this line of code

$da->reset_conditions;

which should only reset the dynamic_condition back to an empty array but Moose in its wisdom it setting it to 'undef' and thus I have just made my application almost totally useless with today's change.

Oh well sometimes it does not pay to get out of bed.

img_0540.jpg

1 Comment

"Should have" (which abbreviates to "should've", not "should of") :-)

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