Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2011 18:35
Show Gist options
  • Save anonymous/1227212 to your computer and use it in GitHub Desktop.
Save anonymous/1227212 to your computer and use it in GitHub Desktop.
package PerlFu::Web::Model::Validator;
use Moose;
use namespace::autoclean;
use Data::Manager;
use Data::Verifier;
use Data::Dumper;
use Carp qw( croak );
extends 'Catalyst::Model';
with 'Catalyst::Component::InstancePerContext';
has 'profiles' => (
is => 'rw',
isa => 'HashRef',
traits => ['Hash'],
required => 1,
builder => '_build_profiles',
lazy => 1,
handles => {
'get_profile' => 'get',
'scopes' => 'keys',
},
);
sub build_per_context_instance {
my ( $self, $c ) = @_;
my %dm_args = ();
if ( $c->stash->{messages} ) {
$dm_args{messages} = $c->stash->{messages};
}
$c->log->debug("args: " . Dumper \%dm_args);
my $dm = Data::Manager->new(%dm_args);
foreach my $scope ( $self->scopes ) {
$c->log->debug("SCOPE " . Dumper $self->get_profile($scope));
$dm->set_verifier(
$scope => Data::Verifier->new( $self->get_profile($scope) ) );
}
return $dm;
}
sub _build_profiles {
return {};
}
__PACKAGE__->meta->make_immutable;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment