-
-
Save dhoss/1246207 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::DataManager; | |
use Moose; | |
extends 'Data::Manager'; | |
has 'scope_to_resultsource' => ( | |
is => 'ro', | |
isa => 'HashRef', | |
required => 1, | |
traits => [ 'Hash' ], | |
handles => { | |
resultsource_for_scope => 'get' | |
} | |
); | |
sub new_from_schema { | |
my ( $class, $schema, @classes ) = @_; | |
my $verifiers = {}; | |
my $scope_to_resultsource = {}; | |
foreach my $class ( @classes ) { | |
$verifiers = _extract_default_verification($class, $verifiers); | |
} | |
foreach my $name ( $schema->sources ) { | |
my $source = $schema->resultset($name)->new_result({}); | |
next unless $source->can('meta'); | |
next unless $source->meta->does_role('MyApp::TraitFor::DBIC::Result::Verifier'); | |
$verifiers->{$source->verify_scope} = $source->verifier; | |
$scope_to_resultsource->{ $source->verify_scope } = | |
"DBIC::$name"; | |
} | |
$class->new( | |
verifiers => $verifiers, | |
scope_to_resultsource => $scope_to_resultsource | |
); | |
}; | |
no Moose; | |
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 MyApp::Schema::Result::Something; | |
use Moose; | |
with 'Jarvis::Role::Verify::DBIC'; | |
... Normal DBIC Stuff ... | |
# Data::Verify Code (from ::Verify role) | |
sub _build_verify_scope { 'identity' } | |
sub _build__verify_profile { | |
my ( $self ) = @_; | |
my $rs = $self->resultset('Person::Identity') | |
->search({ active => 1, realm => 'local' }); | |
return { | |
'profile' => { | |
'ident' => { | |
'required' => 1, | |
'type' => 'Str', | |
'max_length' => '255', | |
'min_length' => 1, | |
'post_check' => sub { | |
my $r = shift; | |
my $count = $rs->search({ident => $r->get_value('ident')}); | |
$count->count == 0; | |
} | |
}, | |
'secret' => { | |
'required' => 1, | |
'type' => 'Str', | |
'min_length' => 1, | |
dependent => { | |
confirm_secret => { | |
required => 1, | |
} | |
}, | |
post_check => sub { | |
my $r = shift; | |
return $r->get_value('secret') eq $r->get_value('confirm_secret'); | |
} | |
}, | |
}, | |
'filters' => [ 'trim' ] | |
}; | |
} | |
no Moose; | |
__PACKAGE__->meta->make_immutable(inline_constructor => 0); |
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::TraitFor::DBIC::Result::Verifier; | |
use Moose::Role; | |
use Data::Verifier; | |
has 'verify_scope' => ( | |
is => 'ro', | |
isa => 'Str', | |
required => 1, | |
lazy_build => 1, | |
); | |
has 'verifier' => ( | |
is => 'ro', | |
isa => 'Data::Verifier', | |
lazy_build => 1, | |
handles => { | |
'verify' => 'verify' | |
} | |
); | |
has '_verify_profile' => ( | |
is => 'ro', | |
isa => 'HashRef', | |
lazy_build => 1, | |
); | |
sub _build_verifier { | |
my ( $self ) = @_; | |
Data::Verifier->new( $self->_verify_profile ); | |
} | |
requires '_build__verify_profile'; | |
no Moose::Role; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment