| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Braintree::ValidationErrorCollection; | 
| 2 |  |  |  |  |  |  | $WebService::Braintree::ValidationErrorCollection::VERSION = '0.92'; | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | WebService::Braintree::ValidationError | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 PURPOSE | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | This class represents a collection of validation errors. | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =cut | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 1 |  |  | 1 |  | 5 | use Moose; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 14 | 1 |  |  | 1 |  | 5148 | use WebService::Braintree::Util; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 64 |  | 
| 15 | 1 |  |  | 1 |  | 262 | use WebService::Braintree::ValidationError; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 257 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 CLASS METHODS | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | This class is B<NOT> an interface, so it does B<NOT> have any class methods. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =cut | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 OBJECT METHODS | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub BUILD { | 
| 28 | 0 |  |  | 0 | 0 |  | my ($self, $args) = @_; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | $self->{_errors} = [ map { WebService::Braintree::ValidationError->new($_) } @{$args->{errors}} ]; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | $self->{_nested} = {}; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | while (my ($key, $value) = each %$args) { | 
| 34 | 0 | 0 |  |  |  |  | next if $key eq 'errors'; | 
| 35 | 0 |  |  |  |  |  | $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 |  |  |  |  |  |  | has 'deep_errors' => (is => 'ro', lazy => 1, builder => '_deep_errors'); | 
| 46 |  |  |  |  |  |  | sub _deep_errors { | 
| 47 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 48 | 0 |  |  |  |  |  | my @nested = map { @{$_->deep_errors} } values %{$self->{_nested}}; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 49 | 0 |  |  |  |  |  | return [ @{$self->{_errors}}, @nested ]; | 
|  | 0 |  |  |  |  |  |  | 
| 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 |  |  |  |  |  |  | sub for { | 
| 60 | 0 |  |  | 0 | 1 |  | my ($self, $target) = @_; | 
| 61 | 0 |  |  |  |  |  | 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 |  |  |  |  |  |  | sub on { | 
| 72 | 0 |  |  | 0 | 1 |  | my ($self, $attribute) = @_; | 
| 73 | 0 |  |  |  |  |  | return [ grep { $_->attribute eq $attribute } @{$self->{_errors}} ] | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  | __END__ | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 TODO | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =over 4 | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =item Need to document what the attributes actually mean. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =back | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =cut |