File Coverage

blib/lib/API/Shippo/Resource.pm
Criterion Covered Total %
statement 70 79 88.6
branch 13 20 65.0
condition 2 14 14.2
subroutine 22 23 95.6
pod 0 9 0.0
total 107 145 73.7


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         2  
  1         23  
3 1     1   19 use MRO::Compat 'c3';
  1         2  
  1         31  
4              
5             package # Hide from PAUSE
6             API::Shippo::Resource;
7 1     1   5 use Carp ( 'croak' );
  1         2  
  1         49  
8 1     1   5 use namespace::clean;
  1         1  
  1         6  
9 1     1   139 use constant DEFAULT_API_SCHEME => 'https';
  1         2  
  1         59  
10 1     1   4 use constant DEFAULT_API_HOST => 'api.goshippo.com';
  1         2  
  1         42  
11 1     1   5 use constant DEFAULT_API_PORT => '443';
  1         1  
  1         45  
12 1     1   4 use constant DEFAULT_API_BASE_PATH => 'v1';
  1         2  
  1         44  
13 1     1   4 use base ( 'API::Shippo::Object' );
  1         2  
  1         526  
14              
15             {
16             my $value = undef;
17              
18             sub api_private_token
19             {
20 2     2 0 520 my ( $class, $new_value ) = @_;
21 2 100       10 return $value unless @_ > 1;
22 1         2 $value = $new_value;
23 1         2 return $class;
24             }
25             }
26              
27             {
28             my $value = undef;
29              
30             sub api_public_token
31             {
32 2     2 0 5 my ( $class, $new_value ) = @_;
33 2 100       8 return $value unless @_ > 1;
34 1         2 $value = $new_value;
35 1         2 return $class;
36             }
37             }
38              
39             {
40             my $value = undef;
41              
42             sub api_token
43             {
44 2     2 0 5 my ( $class, $new_value ) = @_;
45 2 100       9 return $value unless @_ > 1;
46 1         2 $value = $new_value;
47 1         4 return $class;
48             }
49             }
50              
51             {
52             my $value = DEFAULT_API_SCHEME;
53              
54             sub api_scheme
55             {
56 10     10 0 20 my ( $class, $new_value ) = @_;
57 10 50       34 return $value unless @_ > 1;
58 0   0     0 $value = ( $new_value || DEFAULT_API_SCHEME );
59 0         0 return $class;
60             }
61              
62             BEGIN {
63 1     1   6 no warnings 'once';
  1         1  
  1         36  
64 1     1   398 *api_protocol = *api_scheme;
65             }
66             }
67              
68             {
69             my $value = DEFAULT_API_HOST;
70              
71             sub api_host
72             {
73 10     10 0 13 my ( $class, $new_value ) = @_;
74 10 50       40 return $value unless @_ > 1;
75 0   0     0 $value = ( $new_value || DEFAULT_API_HOST );
76 0         0 return $class;
77             }
78             }
79              
80             {
81             my $value = DEFAULT_API_PORT;
82              
83             sub api_port
84             {
85 10     10 0 16 my ( $class, $new_value ) = @_;
86 10 50       28 return $value unless @_ > 1;
87 0   0     0 $value = ( $new_value || DEFAULT_API_PORT );
88 0         0 return $class;
89             }
90             }
91              
92             {
93             my $value = DEFAULT_API_BASE_PATH;
94              
95             sub api_base_path
96             {
97 10     10 0 16 my ( $class, $new_value ) = @_;
98 10 50       27 return $value unless @_ > 1;
99 0   0     0 ( $value = $new_value || DEFAULT_API_BASE_PATH ) =~ s{(^\/*|\/*$)}{};
100 0         0 return $class;
101             }
102             }
103              
104             sub api_resource
105             {
106 0     0 0 0 croak 'Method not implemented in abstract base class';
107             }
108              
109             sub api_url
110             {
111 10     10 0 765 my ( $class ) = @_;
112 10         50 my $scheme = $class->api_scheme;
113 10         66 my $port = $class->api_port;
114 10         47 my $path = $class->api_base_path;
115 10         36 my $resource = $class->api_resource;
116 10         20 my $url = $scheme . '://';
117 10         73 $url .= $class->api_host;
118 10 50 33     70 $url .= ':' . $port
      33        
119             unless $port && $port eq '443' && $scheme eq 'https';
120 10 50       29 $url .= '/' . $path
121             if $path;
122 10 50       26 $url .= '/' . $resource
123             if $resource;
124 10         14 $url .= '/';
125 10         61 return $url;
126             }
127              
128             BEGIN {
129 1     1   5 no warnings 'once';
  1         3  
  1         36  
130 1     1   22 *class_url = *api_url;
131             }
132              
133             1;