| 1 | package Net::Easypost; | ||||||||||||||||||||||||||||
| 2 | 6 | $Net::Easypost::VERSION = '0.23'; | |||||||||||||||||||||||||||
| 3 | 6 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Net::Easypost::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Net::Easypost::Label; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Net::Easypost::Parcel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Net::Easypost::Rate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Net::Easypost::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Net::Easypost::Shipment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Perl client for the Easypost web service | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has 'requester' => ( | ||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | lazy => 1, | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | default => sub { return Net::Easypost::Request->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 6 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | ▶ | sub verify_address { | ||||||||||||||||||||||||||
|
Subroutine
verify_address: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 8 | my ($self, $params) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 8 | ▶ | if ( ref($params) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 30 | 5 | return Net::Easypost::Address->new( $params )->verify; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | elsif ( ref($params) eq 'Net::Easypost::Address' ) { | ||||||||||||||||||||||||||||
| 33 | 2 | return $params->verify; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||
| 36 | 1 | croak "verify_address expects either a hashref or an instance of Net::Easypost::Address\n"; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub get_rates { | ||||||||||||||||||||||||||
|
Subroutine
get_rates: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 4 | my $self = shift; # shift is important here | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | my $params; | |||||||||||||||||||||||||||
| 45 | 4 | ▶ | if ( scalar @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | if ( ref( $_[0] ) ne 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | croak 'get_rates expects a hashref not a '. ref($params) .'\n'; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 3 | $params = shift; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 1 | $params = { @_ }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | return Net::Easypost::Shipment->new( | ||||||||||||||||||||||||||||
| 58 | to_address => $params->{to}, | ||||||||||||||||||||||||||||
| 59 | from_address => $params->{from}, | ||||||||||||||||||||||||||||
| 60 | parcel => $params->{parcel}, | ||||||||||||||||||||||||||||
| 61 | 4 | )->rates; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub buy_label { | ||||||||||||||||||||||||||
|
Subroutine
buy_label: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 2 | my ($self, $shipment, %options) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | ▶ | croak 'Buy label expects a parameter of type Net::Easypost::Shipment' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$shipment or ref $shipment ne "Net::Easypost::Shipment"
MC/DC0%0/2
$shipment or ref $shipment ne "Net::Easypost::Shipment"
$shipment
ref $shipment ne "Net::Easypost::Shipment"
Truth table33%1/3
A or B
A= $shipmentB= ref $shipment ne "Net::Easypost::Shipment"
| |||||||||||||||||||||||||||||
| 69 | unless $shipment || ref($shipment) ne 'Net::Easypost::Shipment'; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | return $shipment->buy(%options); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub get_label { | ||||||||||||||||||||||||||
|
Subroutine
get_label: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($self, $label_filename) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $resp = $self->requester->post( | |||||||||||||||||||||||||||
| 79 | '/postage/get', | ||||||||||||||||||||||||||||
| 80 | { label_file_name => $label_filename } | ||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | return Net::Easypost::Label->new( | ||||||||||||||||||||||||||||
| 84 | rate => Net::Easypost::Rate->new( $resp->{rate} ), | ||||||||||||||||||||||||||||
| 85 | tracking_code => $resp->{tracking_code}, | ||||||||||||||||||||||||||||
| 86 | filename => $resp->{label_file_name}, | ||||||||||||||||||||||||||||
| 87 | filetype => $resp->{label_file_type}, | ||||||||||||||||||||||||||||
| 88 | url => $resp->{label_url} | ||||||||||||||||||||||||||||
| 89 | 0 | ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub list_labels { | ||||||||||||||||||||||||||
|
Subroutine
list_labels: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my $resp = $self->requester->get( | |||||||||||||||||||||||||||
| 97 | $self->requester->_build_url('/postage/list') | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | return $resp->{postages}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 6 | 1; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||