File Coverage

blib/lib/WebService/Braintree/ResultObject.pm
Criterion Covered Total %
statement 6 35 17.1
branch 0 10 0.0
condition n/a
subroutine 2 10 20.0
pod 0 8 0.0
total 8 63 12.7


line stmt bran cond sub pod time code
1             package WebService::Braintree::ResultObject;
2             $WebService::Braintree::ResultObject::VERSION = '0.92';
3 1     1   797 use WebService::Braintree::Util qw(is_arrayref is_hashref);
  1         2  
  1         48  
4 1     1   6 use Moose;
  1         6  
  1         6  
5              
6             sub set_attributes_from_hash {
7 0     0 0   my ($self, $target, $attributes) = @_;
8 0           while (my($attribute, $value) = each(%$attributes)) {
9 0           __PACKAGE__->meta->add_attribute($attribute, is => 'rw');
10 0           $target->$attribute($self->set_attr_value($value));
11             }
12             }
13              
14             sub set_attr_value {
15 0     0 0   my ($self, $value) = @_;
16              
17 0 0         if (is_hashref($value)) {
    0          
18 0           return Hash::Inflator->new($value);
19             } elsif (is_arrayref($value)) {
20 0           my $new_array = [];
21 0           foreach (@$value) {
22 0           push(@$new_array, $self->set_attr_value($_));
23             }
24 0           return $new_array;
25             } else {
26 0           return $value;
27             }
28             }
29              
30             sub setup_sub_objects {
31 0     0 0   my($self, $target, $params, $sub_objects) = @_;
32 0           while (my($attribute, $class) = each(%$sub_objects)) {
33 0           __PACKAGE__->meta->add_attribute($attribute, is => 'rw');
34 0 0         if (is_arrayref($params->{$attribute})) {
35 0           my $new_array = [];
36 0           foreach my $element (@{$params->{$attribute}}) {
  0            
37 0 0         push(@$new_array, $class->new($element)) if is_hashref($element);
38             }
39 0           $target->$attribute($new_array);
40             } else {
41 0 0         push(@{$target->$attribute}, $class->new($params->{$attribute})) if is_hashref($params->{$attribute});
  0            
42             }
43 0           delete($params->{$attribute});
44             }
45             }
46              
47              
48 0     0 0   sub credit_card_details { shift->credit_card; }
49 0     0 0   sub customer_details { shift->customer; }
50 0     0 0   sub billing_details { shift->billing; }
51 0     0 0   sub shipping_details { shift->shipping; }
52 0     0 0   sub subscription_details { shift->subscription; }
53              
54             1;