| 1 | package Valiant::Proxy::Hash; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | with 'Valiant::Proxy'; | |||||||||
| 5 | |||||||||||
| 6 | 27 | ▶ | sub read_attribute_for_validation { | ||||||||
|
Subroutine
read_attribute_for_validation: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 7 | 27 | my ($self, $attribute) = @_; | |||||||||
| 8 | 27 | ▶ | if(exists $self->for->{$attribute}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 9 | 27 | return $self->for->{$attribute}; | |||||||||
| 10 | } else { | ||||||||||
| 11 | 0 | return undef; # TODO Might need a flag to allow die here? | |||||||||
| 12 | } | ||||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub keys { return keys %{ $_[0]->for } } | ||||||||
|
Subroutine
keys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | 0 | ▶ | sub values { return map { $_[0]->for->{$_} } $_[0]->keys } | ||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | 1; | |||||||||
| 19 | |||||||||||
| 20 | =head1 NAME | ||||||||||
| 21 | |||||||||||
| 22 | Valiant::Proxy::Hash - Wrap a hashref in a result object for validation. | ||||||||||
| 23 | |||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||
| 25 | |||||||||||
| 26 | my $proxy = Valiant::Proxy::Hash->new( | ||||||||||
| 27 | validations => [ | ||||||||||
| 28 | [ name => presence => 1, length => [2,15] ], | ||||||||||
| 29 | ], | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | my $result = $proxy->validate({ name => 'Jo' }); | ||||||||||
| 33 | $result->valid; | ||||||||||
| 34 | |||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||
| 36 | |||||||||||
| 37 | Allows you to run validations against a HashRef. | ||||||||||
| 38 | |||||||||||
| 39 | You probably won't use this directly, although you can. | ||||||||||
| 40 | |||||||||||
| 41 | =head1 METHODS | ||||||||||
| 42 | |||||||||||
| 43 | In addition to the interface defined by L<Valiant::Proxy> this class provides: | ||||||||||
| 44 | |||||||||||
| 45 | =head2 keys | ||||||||||
| 46 | |||||||||||
| 47 | Returns the keys of the wrapped hashref. | ||||||||||
| 48 | |||||||||||
| 49 | =head2 values | ||||||||||
| 50 | |||||||||||
| 51 | Returns the values of the wrapped hashref, in the same order as L</keys>. | ||||||||||
| 52 | |||||||||||
| 53 | =head1 SEE ALSO | ||||||||||
| 54 | |||||||||||
| 55 | This does the interface defined by L<Valiant::Proxy> so see the docs on that. | ||||||||||
| 56 | |||||||||||
| 57 | Also: L<Valiant>, L<Valiant::Validator>, L<Valiant::Validator::Each>. | ||||||||||
| 58 | |||||||||||
| 59 | =head1 AUTHOR | ||||||||||
| 60 | |||||||||||
| 61 | See L<Valiant> | ||||||||||
| 62 | |||||||||||
| 63 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 64 | |||||||||||
| 65 | See L<Valiant> | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||