Created
April 18, 2012 13:48
-
-
Save jshirley/2413669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp::Model::DataManager; | |
use Moose; | |
use Data::Manager; | |
use Scalar::Util 'blessed'; | |
use Email::Valid; | |
use Data::Verifier; | |
use Try::Tiny; | |
extends 'Catalyst::Model'; | |
with 'Catalyst::Component::InstancePerContext'; | |
my $email_filter = sub { | |
my @ret = Email::Valid->address( shift ); | |
return $ret[0]; | |
}; | |
my $bool_filter = sub { $_[0] ? 1 : 0; }; | |
has 'profiles' => ( | |
is => 'ro', | |
isa => 'HashRef', | |
traits => [ 'Hash' ], | |
handles => { | |
'get_profile' => 'get', | |
'scopes' => 'keys', | |
}, | |
default => sub { { | |
'something' => { | |
filters => [ 'trim' ], | |
profile => { name => { type => 'Str' } } | |
} | |
} } | |
); | |
sub build_per_context_instance { | |
my ( $self, $c ) = @_; | |
delete $c->stash->{messages}; | |
my $dm = Data::Manager->new; | |
foreach my $scope ( $self->scopes ) { | |
$dm->set_verifier( | |
$scope => Data::Verifier->new( $self->get_profile($scope) ) | |
); | |
} | |
return $dm; | |
} | |
no Moose; | |
__PACKAGE__->meta->make_immutable; 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment