Shutterstock/LicensedMedia.pm

filter: Statementstmt 51.1% 22 / 43 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 38.6% 29 / 75 CC 10 SCAR 42.4
CC
10
Cov
35%
download
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 69.1
↑ Summary Shutterstock/Customer.pm »
1 package WebService::Shutterstock::LicensedMedia;
2 {
3 5 $WebService::Shutterstock::LicensedMedia::VERSION = '0.006';
4 }
5  
6 # ABSTRACT: Role for providing common functionality for licensed media
7  
8 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use WebService::Shutterstock::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 5 has download_url => ( is => 'ro' );
17  
18  
19 0 ▶sub download {
Subroutine download: not called CC=10 SCAR=47.0
Pod documented
20 0 my $self = shift;
21 0 my %args = @_;
22 0 my @unknown_args = grep { !/^(file|directory)$/ } keys %args;
23  
24 0 ▶ croak "Invalid args: @unknown_args (expected either 'file' or 'download')" if @unknown_args;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown_args 0 0 0
25  
26 0 my $url = $self->download_url;
27 0 my $destination;
28 0 ▶ if($args{directory}){
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'directory'}) { } 0 0 0
elsif ($args{'file'}) { } 0 0 0
29 0 $destination = $args{directory};
30 0 $destination =~ s{/$}{};
31 0 my($basename) = $url =~ m{.+/(.+)};
32 0 $destination .= "/$basename";
33 } elsif($args{file}){
34 0 $destination = $args{file};
35 }
36 0 ▶ if(!defined $destination && !defined wantarray){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $destination or defined wantarray) 0 0 0
Condition0%0/3
defined $destination or defined wantarray
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $destination or defined wantarray
defined $destination defined wantarray
Truth table0%0/3
A or B
A= defined $destinationB= defined wantarray
ABresult
1X1
011
000
37 0 croak "Refusing to download media in void context without specifying a destination file or directory (specify ->download(file => \$some_file) or ->download(directory => \$some_dir)";
38 }
39 0 my $ua = LWP::UserAgent->new;
40 0 ▶ my $response = $ua->get( $url, ( $destination ? ( ':content_file' => $destination ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$destination ? : 0 0 0
41 0 ▶ if(my $died = $response->header('X-Died') ){
Branch: 2 branches
BranchTrueFalseTotal
if (my $died = $response->header('X-Died')) { } 0 0 0
elsif ($response->code == 200) { } 0 0 0
42 0 die WebService::Shutterstock::Exception->new(
43 response => $response,
44 error => "Unable to save media to $destination: $died"
45 );
46 } elsif($response->code == 200){
47 0 ▶ return $destination || $response->content;
Condition0%0/3
$destination || $response->content
l!l&&r!l&&!r
000
MC/DC0%0/2
$destination || $response->content
$destination $response->content
Truth table0%0/3
A || B
A= $destinationB= $response->content
ABresult
1X1
011
000
48 } else {
49 0 die WebService::Shutterstock::Exception->new(
50 response => $response,
51 error => $response->status_line . ": unable to retrieve media",
52 );
53 }
54 }
55  
56 5 1;
57  
58 __END__
↑ Summary Shutterstock/Customer.pm »