Moose Loose Ends Part the VIII

Its quick add in day here in the Moose-Pen

Today I am going to add in another attribute called 'all_errors' a simple Boolean flag so my end user can either get a single error message of all the errors found or the 'MooseX::Constructor::AllErrors' object with all the errors when using the 'new'. Simple enough I can just add it here

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

The sticking point for me here is that this new attribute is only ever be used once at start up with a 'new' and as I do my little 'AllErrors' dance in the 'around BUILDARGS' call. It really does not make much sense to make this an attribute as all. I will just make in an 'ENV' var and now the name will be 'DA_ALL_ERRORS'.

To invoke this all I needed to do was re-arrange my code a little with a single 'if'

if (exists($ENV{'DA_ALL_ERRORS'}) and $ENV{'DA_ALL_ERRORS'} ){
die $@;
else {
my @errors;
foreach my $error ($@->missing()){
push(@errors, $class->_new_misc_error($error,$line,$filename));
foreach my $error ($@->invalid()){
push(@errors, $class->_new_misc_error($error,$line,$filename));
my $all = MooseX::Constructor::AllErrors::Error::Constructor->new(
caller => [ caller( Class::MOP::class_of($class)->is_immutable ? 2 : 4) ],
die $all;

Next I have to set up that loop above so I only get one error simple enough but a post for tomorrow;


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