package Anomaly v0.0.1; use 5.12.0; use Moose; use MooseX::ClassAttribute; use MooseX::NonMoose; extends qw(Exception::Class::Base); use namespace::autoclean; class_has generic_description => ( is => q{ro}, isa => q{Str}, default => q{Generic Anomaly}, ); around BUILDARGS => sub { my ($rc_constructor, $proto, @args) = @_; my $class = ref $proto || $proto; if (@args % 2) { push @args, q{message}; } return $class->$rc_constructor(@args); }; sub FOREIGNBUILDARGS { my ($proto, @args) = @_; my $class = ref $proto || $proto; my %wanted = (); if (@args % 2) { $wanted{message} = shift @args; } my %remaining = (@args); my %translation = (msg => q{message}); for my $key ($class->meta->get_attribute_list()) { if (exists $remaining{$key}) { if (exists $translation{$key}) { $wanted{$translation{$key}} = $remaining{$key}; } delete $remaining{$key}; } } if (exists $remaining{error}) { if (! exists $wanted{message}) { $wanted{message} = $remaining{error}; } delete $remaining{error}; } return (%wanted, %remaining); } has description => ( is => q{rw}, isa => q{Str}, default => sub { __PACKAGE__->generic_description() }, ); has detail => ( is => q{ro}, isa => q{Str}, default => q{}, ); has additional_info => ( is => q{ro}, isa => q{ArrayRef[HashRef]}, default => sub { [] }, lazy => 1, required => 0, ); sub add_additional_info { my ($self, $rh_new_info) = @_; my $ra_current_info = $self->additional_info(); push @$ra_current_info, $rh_new_info; $self->additional_info($ra_current_info); return; } no Exception::Class::Base; no MooseX::NonMoose; no MooseX::ClassAttribute; no Moose; __PACKAGE__->meta->make_immutable; 1;