lib/WebService/Braintree/ValidationErrorCollection.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 98.0% 50 / 51 CC 3 SCAR 4.7
CC
3
Cov
100%
BUILD
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« lib/WebService/Braintree/WebhookNotificationGateway.pm ↑ Summary lib/WebService/Braintree/CreditCardVerification.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package WebService::Braintree::ValidationErrorCollection;
4 22 $WebService::Braintree::ValidationErrorCollection::VERSION = '1.7';
5 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 WebService::Braintree::ValidationErrorCollection
11  
12 =head1 PURPOSE
13  
14 This class represents a collection of L<validation errors|WebService::Braintree::ValidationError>.
15  
16 This class will only be created as part of a L<error response|WebService::Braintree::ErrorResult>.
17  
18 =cut
19  
20 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 22 ▶use WebService::Braintree::ValidationError;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 =head1 METHODS
24  
25 =cut
26  
27 6 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
28 6 my ($self, $args) = @_;
29  
30 6 $self->{_errors} = [ map { WebService::Braintree::ValidationError->new($_) } @{$args->{errors}} ];
31 6 $self->{_nested} = {};
32  
33 6 ▶ while (my ($key, $value) = each %$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$args) 9 6 15
34 9 ▶ next if $key eq 'errors';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "errors" 6 3 9
35 3 $self->{_nested}->{$key} = __PACKAGE__->new($value);
36 }
37 }
38  
39 =head2 deep_errors()
40  
41 This returns a list of the errors for the underlying validation failures.
42  
43 =cut
44  
45 22 has 'deep_errors' => (is => 'ro', lazy => 1, builder => '_deep_errors');
46 4 ▶sub _deep_errors {
Subroutine _deep_errors: called CC=1 SCAR=0.0
47 4 my $self = shift;
48 4 my @nested = map { @{$_->deep_errors} } values %{$self->{_nested}};
49 4 return [ @{$self->{_errors}}, @nested ];
50 }
51  
52 =head2 for()
53  
54 This takes a target and returns a ValidationErrorCollection for that value (if
55 it exists).
56  
57 =cut
58  
59 4 ▶sub for {
Subroutine for: called CC=1 SCAR=0.0
Pod documented
60 4 my ($self, $target) = @_;
61 4 return $self->{_nested}->{$target};
62 }
63  
64 =head2 on()
65  
66 This takes an attribute and returns an arrayref of the L<ValidationErrors|WebService::Braintree::ValidationError/> for that attribute. If there aren't any, then
67 this will return an empty arrayref.
68  
69 =cut
70  
71 4 ▶sub on {
Subroutine on: called CC=1 SCAR=0.0
Pod documented
72 4 my ($self, $attribute) = @_;
73 4 return [ grep { $_->attribute eq $attribute } @{$self->{_errors}} ]
74 }
75  
76 22 __PACKAGE__->meta->make_immutable;
77  
78 22 1;
79 __END__
« lib/WebService/Braintree/WebhookNotificationGateway.pm ↑ Summary lib/WebService/Braintree/CreditCardVerification.pm »