Skip to content

Instantly share code, notes, and snippets.

@jshirley
Created April 18, 2012 13:48
Show Gist options
  • Save jshirley/2413669 to your computer and use it in GitHub Desktop.
Save jshirley/2413669 to your computer and use it in GitHub Desktop.
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