Skip to content

Instantly share code, notes, and snippets.

@dhoss
Forked from jshirley/gist:1223273
Created September 16, 2011 23:12
Show Gist options
  • Save dhoss/1223383 to your computer and use it in GitHub Desktop.
Save dhoss/1223383 to your computer and use it in GitHub Desktop.
package MyApp::Web::Model::DataManager;
use Moose;
use Email::Valid;
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 { {
# Personal/Account Information
'login' => {
# ...
}
} },
);
sub build_per_context_instance {
my ( $self, $c ) = @_;
my %dm_args = ();
if ( $c->stash->{messages} ) {
$dm_args{messages} = $c->stash->{messages};
}
my $dm = Data::Manager->new( %dm_args );
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