CatalystX-Eta

 view release on metacpan or  search on metacpan

t/lib/MyApp/Data/Manager.pm  view on Meta::CPAN

package MyApp::Data::Manager;
use namespace::autoclean;
use Moose;

extends 'Data::Manager';

use MyApp::Data::Visitor;

has _input => ( is => 'ro', isa => 'HashRef', init_arg => 'input' );

has actions => (
    is      => 'ro',
    isa     => 'HashRef',
    default => sub { +{} },
);

sub apply {
    my ($self) = @_;
    foreach my $scope ( keys %{ $self->verifiers } ) {
        my $results = $self->verify( $scope, $self->_input );
        return $self->actions->{$scope}->($results) if $results->success;
    }
    return;
}

sub errors {
    my $self = shift;
    my %errors;
    for my $msg ( @{ $self->messages->messages || [] } ) {
        $errors{ $msg->subject } = 'invalid'
          if $msg->msgid =~ /invalid/g;
        $errors{ $msg->subject } = 'missing'
          if $msg->msgid =~ /missing/g;
    }
    return unless scalar keys %errors;
    return \%errors;
}

around success => sub {
    my $orig = shift;
    my $self = shift;
    return !!( $self->$orig(@_) && scalar keys %{ $self->results } );
};

1;



( run in 3.008 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )