File Coverage

blib/lib/API/Shippo/Object.pm
Criterion Covered Total %
statement 20 37 54.0
branch 2 10 20.0
condition 2 6 33.3
subroutine 6 9 66.6
pod 0 4 0.0
total 30 66 45.4


line stmt bran cond sub pod time code
1 1     1   5 use strict;
  1         2  
  1         23  
2 1     1   4 use warnings;
  1         1  
  1         30  
3 1     1   4 use MRO::Compat 'c3';
  1         2  
  1         31  
4              
5             package # Hide from PAUSE
6             API::Shippo::Object;
7 1     1   5 use Scalar::Util ( 'blessed', 'reftype' );
  1         1  
  1         54  
8 1     1   5 use namespace::clean;
  1         1  
  1         6  
9              
10             sub new
11             {
12 1     1 0 2 my ( $class, $id ) = @_;
13 1   33     8 my $self = bless( {}, ref( $class ) || $class );
14             $id = $id->{id}
15 1 50 33     4 if ref( $id ) && reftype( $id ) eq 'HASH';
16 1 50       9 $self->{id} = $id
17             if $id;
18 1         12 return $self;
19             }
20              
21             sub construct_from
22             {
23 0     0 0   my ( $invocant, $ref ) = @_;
24 0           my $ref_type = ref( $ref );
25 0 0         return $ref_type
26             unless defined $ref_type;
27 0 0         if ( $ref_type eq 'ARRAY' ) {
    0          
28 0           return [ map { $invocant->construct_from( $_ ) } @$ref ];
  0            
29             }
30             elsif ( $ref_type eq 'HASH' ) {
31 0           my $self = $invocant->new( $ref->{id} );
32 0           return $self->refresh_from( $ref );
33             }
34             else {
35 0           return $ref;
36             }
37             }
38              
39             sub refresh_from
40             {
41 0     0 0   my ( $self, $hash ) = @_;
42 0           @{$self}{ keys( %$hash ) } = values( %$hash );
  0            
43 0           return $self;
44             }
45              
46             sub request
47             {
48 0     0 0   my ( $self, $method, $url, %params ) = @_;
49 0           my $requestor = API::Shippo::Requestor->new( $self->api_key );
50 0           my ( $response, $api_key ) = $requestor->request( $method, $url, %params );
51 0           return $self->_convert_to_shippo_object( $response, $api_key );
52             }
53              
54             1;