Easypost/Label.pm

filter: Statementstmt 87.8% 36 / 41 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 85.0% 51 / 60 CC 4 SCAR 5.4
CC
4
Cov
83%
save
3.1
__ANON__
2.0
serialize
2.0
CRAP 1.7
« Easypost/CustomsInfo.pm ↑ Summary Easypost/PostOnBuild.pm »
1 package Net::Easypost::Label;
2 6 $Net::Easypost::Label::VERSION = '0.23';
3 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 with qw(Net::Easypost::Resource);
5  
6 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Net::Easypost::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 has 'tracking_code' => (
10 is => 'ro',
11 required => 1
12 );
13  
14 6 has 'filename' => (
15 is => 'ro',
16 required => 1,
17 );
18  
19 6 has 'filetype' => (
20 is => 'ro',
21 lazy => 1,
22 default => 'image/png',
23 );
24  
25 6 has 'url' => (
26 is => 'ro',
27 predicate => 1,
28 required => 1,
29 );
30  
31 6 has 'rate' => (
32 is => 'ro',
33 );
34  
35 has 'image' => (
36 is => 'ro',
37 lazy => 1,
38 predicate => 1,
39 2 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
40 2 my ($self) = @_;
41  
42 2 ▶ croak "Cannot retrieve image for " . $self->filename . " without URL"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_url 0 2 2
43 unless $self->has_url;
44  
45 2 return $self->requester->get($self->url);
46 }
47 6 );
48  
49 5 ▶sub _build_operation { '' }
Subroutine _build_operation: called CC=1 SCAR=0.0
50 5 ▶sub _build_role { 'label' }
Subroutine _build_role: called CC=1 SCAR=0.0
51 5 ▶sub _build_fieldnames {
Subroutine _build_fieldnames: called CC=1 SCAR=0.0
52 5 return [qw/tracking_code url filetype filename/];
53 }
54  
55 2 ▶sub save {
Subroutine save: called CC=3 SCAR=11.2
Pod documented
56 2 my ($self) = @_;
57  
58 2 ▶ $self->image
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_image 2 0 2
59 unless $self->has_image;
60  
61 2 ▶ open my $fh, ">:raw", $self->filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:raw", $self->filename or croak(q[Couldn't save ] . $self->filename . ": $!") 2 0 2
62 or croak "Couldn't save " . $self->filename . ": $!";
63  
64 2 print {$fh} $self->image;
65 2 close($fh);
66  
67 2 return 1;
68 }
69  
70 1 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
71 1 my $self = shift;
72  
73 return Net::Easypost::Label->new(
74 5 map { $_ => $self->$_ }
75 5 grep { defined $self->$_ }
76 1 'id', @{ $self->fieldnames }
77 );
78 }
79  
80 0 ▶sub serialize {
Subroutine serialize: not called CC=1 SCAR=6.9
Pod documented
81 0 my ($self) = @_;
82  
83 return {
84 0 map { $self->role . "[$_]" => $self->$_ }
85 0 grep { defined $self->$_ }
86 0 @{ $self->fieldnames }
87 };
88 }
89  
90 6 1;
91  
92 __END__
« Easypost/CustomsInfo.pm ↑ Summary Easypost/PostOnBuild.pm »