-
-
Save dhoss/1227214 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 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; |
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 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; | |
## error: | |
'Caught exception in PerlFu::Web::Controller::Forum::Thread->create "Attribute (profile) is required at constructor Data::Verifier::new (defined at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Data/Verifier.pm line 313) line 44 Data::Verifier::new(\'Data::Verifier\', \'HASH(0xb61ff68)\') called at /home/devin/web-devel/PerlFu/script/../lib/PerlFu/Web/Model/Validator.pm line 36 PerlFu::Web::Model::Validator::build_per_context_instance(\'PerlFu::Web::Model::Validator::Post=HASH(0xb2973c0)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Component/InstancePerContext.pm line 24 Catalyst::Component::InstancePerContext::ACCEPT_CONTEXT(\'PerlFu::Web::Model::Validator::Post=HASH(0xb2973c0)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 629 Catalyst::_filter_component(\'PerlFu::Web=HASH(0xb439e98)\', \'PerlFu::Web::Model::Validator::Post=HASH(0xb2973c0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 701 Catalyst::model(\'PerlFu::Web=HASH(0xb439e98)\', \'Validator::Post\') called at /home/devin/web-devel/PerlFu/script/../lib/PerlFu/Web/Controller/Forum/Thread.pm line 64 PerlFu::Web::Controller::Forum::Thread::create(\'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 65 Catalyst::Action::execute(\'Catalyst::Action=HASH(0xb36c9f0)\', \'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 eval {...} called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 Catalyst::execute(\'PerlFu::Web=HASH(0xb439e98)\', \'PerlFu::Web::Controller::Forum::Thread\', \'Catalyst::Action=HASH(0xb36c9f0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 60 Catalyst::Action::dispatch(\'Catalyst::Action=HASH(0xb36c9f0)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/ActionChain.pm line 39 Catalyst::ActionChain::dispatch(\'Catalyst::ActionChain=HASH(0xb43a158)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Controller.pm line 125 Catalyst::Controller::_ACTION(\'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 65 Catalyst::Action::execute(\'Catalyst::Action=HASH(0xb338420)\', \'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 eval {...} called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 Catalyst::execute(\'PerlFu::Web=HASH(0xb439e98)\', \'PerlFu::Web::Controller::Forum::Thread\', \'Catalyst::Action=HASH(0xb338420)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 60 Catalyst::Action::dispatch(\'Catalyst::Action=HASH(0xb338420)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Dispatcher.pm line 257 Catalyst::Dispatcher::_do_forward(\'Catalyst::Dispatcher=HASH(0x9a64b68)\', \'forward\', \'PerlFu::Web=HASH(0xb439e98)\', \'_ACTION\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Dispatcher.pm line 237 Catalyst::Dispatcher::forward(\'Catalyst::Dispatcher=HASH(0x9a64b68)\', \'PerlFu::Web=HASH(0xb439e98)\', \'_ACTION\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 382 Catalyst::forward(\'PerlFu::Web=HASH(0xb439e98)\', \'_ACTION\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Controller.pm line 99 Catalyst::Controller::_DISPATCH(\'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 65 Catalyst::Action::execute(\'Catalyst::Action=HASH(0xb3330a8)\', \'PerlFu::Web::Controller::Forum::Thread=HASH(0xb29d8f8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 eval {...} called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1676 Catalyst::execute(\'PerlFu::Web=HASH(0xb439e98)\', \'PerlFu::Web::Controller::Forum::Thread\', \'Catalyst::Action=HASH(0xb3330a8)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Action.pm line 60 Catalyst::Action::dispatch(\'Catalyst::Action=HASH(0xb3330a8)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Dispatcher.pm line 257 Catalyst::Dispatcher::_do_forward(\'Catalyst::Dispatcher=HASH(0x9a64b68)\', \'forward\', \'PerlFu::Web=HASH(0xb439e98)\', \'/forum/thread/_DISPATCH\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Dispatcher.pm line 237 Catalyst::Dispatcher::forward(\'Catalyst::Dispatcher=HASH(0x9a64b68)\', \'PerlFu::Web=HASH(0xb439e98)\', \'/forum/thread/_DISPATCH\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 382 Catalyst::forward(\'PerlFu::Web=HASH(0xb439e98)\', \'/forum/thread/_DISPATCH\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Dispatcher.pm line 105 Catalyst::Dispatcher::dispatch(\'Catalyst::Dispatcher=HASH(0x9a64b68)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1622 Catalyst::dispatch(\'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Plugin/MessageStack.pm line 111 Catalyst::Plugin::MessageStack::dispatch(\'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Plugin/Static/Simple.pm line 76 Class::MOP::Class:::around(\'CODE(0xa500d10)\', \'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux/Class/MOP/Method/Wrapped.pm line 162 Class::MOP::Method::Wrapped::__ANON__(\'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux/Class/MOP/Method/Wrapped.pm line 91 PerlFu::Web::dispatch(\'PerlFu::Web=HASH(0xb439e98)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1963 Catalyst::__ANON__() called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Try/Tiny.pm line 76 eval {...} called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Try/Tiny.pm line 67 Try::Tiny::try(\'CODE(0xb3f68c8)\', \'Try::Tiny::Catch=REF(0x9a4d020)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 1969 Catalyst::handle_request(\'PerlFu::Web\', \'env\', \'HASH(0xadd0dc0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Engine.pm line 852 Catalyst::Engine::__ANON__(\'CODE(0xb1e8d30)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Plack/Util.pm line 324 Plack::Util::__ANON__(\'CODE(0xb1e91b0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/HTTP/Server/PSGI.pm line 185 HTTP::Server::PSGI::handle_connection(\'HTTP::Server::PSGI=HASH(0xb3f6178)\', \'HASH(0xadd0dc0)\', \'IO::Socket::INET=GLOB(0xb2c10f0)\', \'CODE(0xb3f6248)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/HTTP/Server/PSGI.pm line 134 HTTP::Server::PSGI::accept_loop(\'HTTP::Server::PSGI=HASH(0xb3f6178)\', \'CODE(0xb3f5fa8)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/HTTP/Server/PSGI.pm line 62 HTTP::Server::PSGI::run(\'HTTP::Server::PSGI=HASH(0xb3f6178)\', \'CODE(0xb3f5fa8)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Plack/Handler/HTTP/Server/PSGI.pm line 14 Plack::Handler::HTTP::Server::PSGI::run(\'Plack::Handler::Standalone=HASH(0xa321da0)\', \'CODE(0xb3f5fa8)\', \'HASH(0x9a649e8)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Engine.pm line 833 Catalyst::Engine::run(\'Catalyst::Engine=HASH(0xa0198b8)\', \'PerlFu::Web\', \'CODE(0xb3f5fa8)\', 3000, undef, \'HASH(0x9a649e8)\', \'Plack::Handler::Standalone=HASH(0xa321da0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst.pm line 2418 Catalyst::run(\'PerlFu::Web\', 3000, undef, \'HASH(0x9a649e8)\', \'Plack::Handler::Standalone=HASH(0xa321da0)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/ScriptRole.pm line 85 Catalyst::ScriptRole::_run_application(\'Catalyst::Script::Server=HASH(0x9a66880)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/Script/Server.pm line 239 Catalyst::Script::Server::run(\'Catalyst::Script::Server=HASH(0x9a66880)\') called at /home/devin/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Catalyst/ScriptRunner.pm line 20 Catalyst::ScriptRunner::run(\'Catalyst::ScriptRunner\', \'PerlFu::Web\', \'Server\') called at script/perlfu_web_server.pl line 8 |
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 PerlFu::Web::Model::Validator::Post; | |
use Moose; | |
use namespace::autoclean; | |
extends 'PerlFu::Web::Model::Validator'; | |
sub _build_profiles { | |
my $self = shift; | |
return { | |
title => { | |
required => 1, | |
type => 'Str', | |
max_length => 255, | |
min_length => 1 | |
}, | |
tags => { | |
required => 0, | |
type => 'Str', | |
max_length => 1024, | |
min_length => 1, | |
}, | |
body => { | |
required => 1, | |
type => 'Str', | |
min_length => 1, | |
}, | |
author => { | |
required => 1, | |
type => 'Int', | |
}, | |
parent => { | |
required => 0, | |
type => 'Int', | |
}, | |
path => { | |
required => 0, | |
type => 'Str', | |
min_length => 1, | |
}, | |
}; | |
} | |
__PACKAGE__->meta->make_immutable; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment