Valiant/Proxy/Hash.pm

filter: Statementstmt 61.5% 8 / 13 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 66.6% 2 / 3 totaltotal 59.0% 13 / 22 CC 2 SCAR 6.2
CC
2
Cov
60%
read_attribute_for_validation
2.1
keys
2.0
values
2.0
CRAP 1.9
« Valiant/HTML/Util/Collection.pm ↑ Summary Valiant/Validator/Scalar.pm »
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
BranchTrueFalseTotal
if (exists $self->for->{$attribute}) { } 27 0 27
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
« Valiant/HTML/Util/Collection.pm ↑ Summary Valiant/Validator/Scalar.pm »