| 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
| |||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$is ||= "ro"
$is
Truth table50%1/2
A
A= $is
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 0 | $self->load; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 7 | ▶ | if($is eq 'rw' && @_){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$is eq "rw" and @_
MC/DC0%0/2
$is eq "rw" and @_
$is eq "rw"
@_
Truth table33%1/3
A and B
A= $is eq "rw"B= @_
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my @dst = map { ref $_ ? $_->[1] : $_ } @fields; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
not exists $self->{$dst} and exists $args{$src}
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}
| |||||||||||||||||||||||||||||
| 62 | 3 | $self->{$dst} = $args{$src}; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 3 | return $self; | |||||||||||||||||||||||||||
| 66 | 28 | }; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 17 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||