| 1 | package FormValidator::Nested::Filter; | ||||||||||||||
| 2 | 3 | ▶ | use Any::Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 3 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 3 | ▶ | use FormValidator::Nested::ProfileProvider; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 3 | ▶ | use Class::Param; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 3 | has 'profile_provider' => ( | |||||||||||||
| 11 | is => 'ro', | ||||||||||||||
| 12 | isa => 'FormValidator::Nested::ProfileProvider', | ||||||||||||||
| 13 | required => 1, | ||||||||||||||
| 14 | handles => [qw/get_profile/], | ||||||||||||||
| 15 | ); | ||||||||||||||
| 16 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 21 | ▶ | sub filter { | ||||||||||||
|
Subroutine
filter: called CC=7 SCAR=22.3
Pod
undocumented
| |||||||||||||||
| 19 | 21 | my $self = shift; | |||||||||||||
| 20 | 21 | my $req = shift; | |||||||||||||
| 21 | 21 | my $profile_key = shift; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 21 | my $hash = 0; | |||||||||||||
| 24 | 21 | ▶ | if ( blessed($req) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 25 | 21 | ▶ | if ( !$req->can('param') ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 0 | croak("req cannot call param method."); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | } | ||||||||||||||
| 29 | elsif ( ref $req eq 'HASH' ) { | ||||||||||||||
| 30 | 0 | $req = Class::Param->new($req); | |||||||||||||
| 31 | 0 | $hash = 1; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 21 | my $profile = $self->get_profile($profile_key); | |||||||||||||
| 35 | |||||||||||||||
| 36 | 21 | foreach my $param ( $profile->get_params ) { | |||||||||||||
| 37 | 121 | foreach my $filter ( $param->get_filters ) { | |||||||||||||
| 38 | 121 | my $values_ref = $param->get_values($req); | |||||||||||||
| 39 | 121 | $filter->process($req, $values_ref); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 21 | ▶ | if ( $hash ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | return $req->as_hash; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 21 | return $req; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 3 | 1; | |||||||||||||
| 51 | __END__ | ||||||||||||||