Shutterstock/DeferredData.pm

filter: Statementstmt 80.0% 52 / 65 Branchbran 50.0% 7 / 14 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 1 totaltotal 70.8% 73 / 103 CC 13 SCAR 15.9
CC
13
Cov
72%
__ANON__
12.0
__ANON__
5.6
__ANON__
5.1
CRAP 4.9
« Shutterstock/Subscription.pm ↑ Summary Shutterstock/Video.pm »
1 package WebService::Shutterstock::DeferredData;
2 {
3 17 $WebService::Shutterstock::DeferredData::VERSION = '0.006';
4 }
5  
6 # ABSTRACT: Utility class for easy lazy-loading from the API
7  
8 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use Sub::Exporter -setup => { exports => ['deferred'] };
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 28 ▶sub deferred {
Subroutine deferred: called CC=4 SCAR=15.1
Pod undocumented
13 28 my $target = caller;
14 28 my $loader = pop;
15 28 my @fields = @_;
16 28 foreach my $f(@fields){
17 244 my($src,$dst,$is);
18 244 ▶ if(ref $f eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $f eq 'ARRAY') { } 24 220 244
19 24 ($src,$dst,$is) = @$f;
20 } else {
21 220 ($src,$dst,$is) = ($f, $f,'ro');
22 }
23 244 ▶ $is ||= 'ro';
Condition50%1/2
$is ||= "ro"
l!l
2440
MC/DC0%0/1
$is ||= "ro"
$is
Truth table50%1/2
A
A= $is
Aresult
11
00
24 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 244 my $sub = $target . '::' . $dst;
26 7 ▶ *$sub = sub {
Subroutine __ANON__: called CC=4 SCAR=17.2
27 7 my $self = shift;
28 7 ▶ unless ( exists $self->{$dst} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$dst}) 0 7 7
29 0 $self->load;
30 }
31 7 ▶ if($is eq 'rw' && @_){
Branch: 1 branch
BranchTrueFalseTotal
if ($is eq "rw" and @_) 0 7 7
Condition33%1/3
$is eq "rw" and @_
!ll&&!rl&&r
700
MC/DC0%0/2
$is eq "rw" and @_
$is eq "rw" @_
Truth table33%1/3
A and B
A= $is eq "rw"B= @_
ABresult
0X0
100
111
32 0 $self->{$dst} = shift;
33 }
34 7 return $self->{$dst};
35 244 };
36 }
37 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 28 my $loader_target = $target . '::load';
39 0 ▶ *$loader_target = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
40 0 my $self = shift;
41 0 my $data = $self->$loader;
42 0 ▶ my @src = map { ref $_ ? $_->[0] : $_ } @fields;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
43 0 ▶ my @dst = map { ref $_ ? $_->[1] : $_ } @fields;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
44 0 @{$self}{@dst} = @{$data}{@src};
45 0 return $self;
46 28 };
47 28 my $constructor_target = $target . '::new';
48 28 my $original = \&{ $constructor_target };
49 17 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 3 ▶ *$constructor_target = sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
51 3 my $class = shift;
52 3 my %args = @_;
53 3 my $self = $class->$original(@_);
54 3 foreach my $f(@fields){
55 40 my($src,$dst);
56 40 ▶ if(ref $f eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $f eq 'ARRAY') { } 0 40 40
57 0 ($src,$dst) = @$f;
58 } else {
59 40 ($src,$dst) = ($f, $f);
60 }
61 40 ▶ if(!exists $self->{$dst} && exists $args{$src}){
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{$dst} and exists $args{$src}) 3 37 40
Condition66%2/3
not exists $self->{$dst} and exists $args{$src}
!ll&&!rl&&r
0373
MC/DC50%1/2
not exists $self->{$dst} and exists $args{$src}
not exists $self->{$dst} exists $args{$src}
Truth table66%2/3
not(A) and B
A= not exists $self->{$dst}B= exists $args{$src}
ABresult
0X0
100
111
62 3 $self->{$dst} = $args{$src};
63 }
64 }
65 3 return $self;
66 28 };
67 }
68  
69 17 1;
70  
71 __END__
« Shutterstock/Subscription.pm ↑ Summary Shutterstock/Video.pm »