File Coverage

lib/WebService/Shippo/Address.pm
Criterion Covered Total %
statement 25 33 75.7
branch 0 8 0.0
condition 0 6 0.0
subroutine 9 10 90.0
pod 0 1 0.0
total 34 58 58.6


line stmt bran cond sub pod time code
1 7     7   33 use strict;
  7         13  
  7         177  
2 7     7   36 use warnings;
  7         13  
  7         184  
3 7     7   33 use MRO::Compat 'c3';
  7         13  
  7         252  
4              
5             package WebService::Shippo::Address;
6             require WebService::Shippo::Request;
7 7     7   35 use Carp ( 'confess' );
  7         11  
  7         334  
8 7     7   42 use Params::Callbacks ( 'callbacks' );
  7         14  
  7         276  
9 7     7   36 use Scalar::Util ( 'blessed' );
  7         15  
  7         353  
10 7         3358 use base qw(
11             WebService::Shippo::Item
12             WebService::Shippo::Create
13             WebService::Shippo::Fetch
14 7     7   36 );
  7         17  
15              
16             sub api_resource () { 'addresses' }
17              
18             sub collection_class () { 'WebService::Shippo::Addresses' }
19              
20             sub item_class () { __PACKAGE__ }
21              
22             sub validate
23             {
24 0     0 0   my ( $callbacks, $invocant, $object_id, @params ) = &callbacks;
25 0 0         if ( blessed( $invocant ) ) {
26 0 0         $object_id = $invocant->id
27             unless $object_id;
28             # Don't make unnecessary call to API if address was already validated
29 0 0 0       return $invocant
      0        
30             if $invocant->id eq $object_id
31             && $invocant->source eq 'VALIDATOR'
32             && $invocant->state eq 'VALID';
33             }
34 0 0         confess 'Expected an object id'
35             unless $object_id;
36 0           my $url = $invocant->url( "$object_id/validate" );
37 0           my $response = WebService::Shippo::Request->get( $url, @params );
38 0           return $invocant->construct_from( $response, $callbacks );
39             }
40              
41             BEGIN {
42 7     7   36 no warnings 'once';
  7         13  
  7         221  
43 7     7   117 *Shippo::Address:: = *WebService::Shippo::Address::;
44             }
45              
46             1;
47             __END__