| 1 | package Net::Easypost::CustomsInfo; | ||||||||||
| 2 | 1 | $Net::Easypost::CustomsInfo::VERSION = '0.23'; | |||||||||
| 3 | 1 | ▶ | use JSON::MaybeXS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Types::Standard qw(ArrayRef Bool Enum InstanceOf Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | with qw/Net::Easypost::Resource/; | |||||||||
| 8 | 1 | with qw/Net::Easypost::PostOnBuild/; | |||||||||
| 9 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | has 'eel_ppc' => ( | |||||||||
| 12 | is => 'rw', | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 1 | has 'contents_type' => ( | |||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => Enum[qw/documents gift merchandise returned_goods sample other/] | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | has 'customs_certify' => ( | ||||||||||
| 21 | is => 'rw', | ||||||||||
| 22 | isa => Bool|InstanceOf['JSON::PP::Boolean'], | ||||||||||
| 23 | 1 | ▶ | coerce => sub { $_[0] ? JSON->true : JSON->false } | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 24 | 1 | ); | |||||||||
| 25 | |||||||||||
| 26 | 1 | has 'non_delivery_option' => ( | |||||||||
| 27 | is => 'rw', | ||||||||||
| 28 | isa => Enum[qw/abandon return/], | ||||||||||
| 29 | default => 'return' | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 1 | has [qw/contents_explanation customs_signer/] => ( | |||||||||
| 33 | is => 'rw', | ||||||||||
| 34 | isa => Str | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 1 | has 'restriction_type' => ( | |||||||||
| 38 | is => 'rw', | ||||||||||
| 39 | isa => Enum[qw/none quarantine sanitary_phytosanitary_inspection/] | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | 1 | has 'restriction_comments' => ( | |||||||||
| 43 | is => 'rw', | ||||||||||
| 44 | isa => Str | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | 1 | has 'customs_items' => ( | |||||||||
| 48 | is => 'rw', | ||||||||||
| 49 | isa => ArrayRef[InstanceOf['Net::Easypost::CustomsItem']] | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub _build_fieldnames { | ||||||||
|
Subroutine
_build_fieldnames: called CC=1 SCAR=0.0
| |||||||||||
| 53 | return [ | ||||||||||
| 54 | 1 | qw/ | |||||||||
| 55 | contents_explanation | ||||||||||
| 56 | contents_type | ||||||||||
| 57 | customs_certify | ||||||||||
| 58 | customs_signer | ||||||||||
| 59 | eel_ppc | ||||||||||
| 60 | non_delivery_option | ||||||||||
| 61 | restriction_comments | ||||||||||
| 62 | restriction_type | ||||||||||
| 63 | / | ||||||||||
| 64 | ]; | ||||||||||
| 65 | } | ||||||||||
| 66 | 1 | ▶ | sub _build_role { 'customs_info' } | ||||||||
|
Subroutine
_build_role: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 1 | ▶ | sub _build_operation { '/customs_infos' } | ||||||||
|
Subroutine
_build_operation: called CC=1 SCAR=0.0
| |||||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | sub serialize { | ||||||||
|
Subroutine
serialize: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 70 | 1 | my ($self) = @_; | |||||||||
| 71 | |||||||||||
| 72 | my $obj = { | ||||||||||
| 73 | 6 | map { $self->role . "[$_]" => $self->$_ } | |||||||||
| 74 | 1 | grep { defined $self->$_ } @{ $self->fieldnames } | |||||||||
| 75 | }; | ||||||||||
| 76 | |||||||||||
| 77 | # if customs_items exist, they were already created in Net::Easypost::CustomsItem | ||||||||||
| 78 | # so we can simply pass the id | ||||||||||
| 79 | 1 | ▶ | if ($self->customs_items) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 1 | foreach my $i (0 .. $#{ $self->customs_items }) { | |||||||||
| 81 | 1 | my $item = $self->customs_items->[$i]; | |||||||||
| 82 | 1 | $obj->{$self->role . "[customs_items][$i][id]"} = $item->id; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 1 | return $obj; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 90 | 0 | my ($self) = @_; | |||||||||
| 91 | |||||||||||
| 92 | return Net::Easypost::CustomsInfo->new( | ||||||||||
| 93 | 0 | map { $_ => $self->$_ } | |||||||||
| 94 | 0 | grep { defined $self->$_ } @{ $self->fieldnames }, | |||||||||
| 95 | 'customs_items' => [ | ||||||||||
| 96 | 0 | map { $_->clone } $self->customs_items | |||||||||
| 97 | ] | ||||||||||
| 98 | ); | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 1 | 1; | |||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||