Yearling Moose
Final final final clean up day here in the Moose-Pen
Just a quick postette today cleaning up the last of my messages on my error retruns. Starting with this one;
'Database::Accessor Database::Accessor::add_condition Error:
The following Attribute is required: (conditions->left)
With constructor hash:
{
'predicates' => {
'operator' => undef,
so two thing to get rid of here, get rid of that 'Database::Accessor::' in front of 'add_condition' and change that constructor has so it dose not show that hidden 'predicates' key
the first fix is easy enough;
sub _one_error {
my ( $error_in, $ops, $call, $package, $filename, $line, $subroutine,$new,$raw_in) = @_;
++ $call =~ s/Database\:\:Accessor\:\://;
and the fix for the next part was equally as simple;
my $misc =
"Database::Accessor "
. $call
. " Error:\n";
if ($new !=1 and !defined($raw_in)){
$misc .= "You cannot add 'undef' with "
. $call;
}
else {
$misc .= $error
. $on
. "With constructor hash:\n"
-- . Dumper($raw_in);
++ . Dumper($ops);
}
and the error comes out right.
Now I did run into a problem with trying to iterate over my $da errors seems that $ALL_ERRORS is a little sticky and hangs about between iterations so my errors where collecting up caucusing me all sorts of problems. The fix was simple enough
use Moose::Role;
with qw(Database::Accessor::Roles::AllErrors);
--our $ALL_ERRORS = MooseX::Constructor::AllErrors::Error::Constructor->new(
-- caller => [ ], );
++our $ALL_ERRORS ;
…
sub _is_new {
my ($new) = @_;
if (defined($new)) {
$NEW = $new;
}
++ $ALL_ERRORS = MooseX::Constructor::AllErrors::Error::Constructor->new(
++ caller => [ ], );
return $NEW;
}
moved the init of that all errors into that '_is_new' sub and I was all fixed up;
I added in some 15 other tests but when I got to this one;
link => {
to => {
name => 'country',
alias => 'a_country'
},
type => 'bla',
conditions => undef
}
I got a hard crash;
Can't locate object method "has_errors" via package "Can't use string ("to") as a HASH ref while "strict refs" in use at D:\GitHub\database-accessor\lib/Database/Accessor.pm line 1516.
Turns out with the above I have no '$ERROR' object so I have to check for that;
-- if ($ALL_ERRORS->has_errors){
++ if (($ALL_ERRORS) and $ALL_ERRORS->has_errors){
and that plus this little change for 'gather'
if ($class eq 'Database::Accessor::Gather'){
$object = $class->new( %{$ops});
}
else {
$object = $class->new( $ops);
}
as gather is a singleton and need to converted to a hash before it is used in a new.
Now ' 42_new_validation.t ' passes with 37 oks
So not a bad for a years worth of posting.
Leave a comment