line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Shutterstock::DeferredData; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$WebService::Shutterstock::DeferredData::VERSION = '0.006'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Utility class for easy lazy-loading from the API |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
70
|
use strict; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
593
|
|
9
|
12
|
|
|
12
|
|
73
|
use warnings; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
629
|
|
10
|
12
|
|
|
12
|
|
43639
|
use Sub::Exporter -setup => { exports => ['deferred'] }; |
|
12
|
|
|
|
|
196753
|
|
|
12
|
|
|
|
|
120
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub deferred { |
13
|
31
|
|
|
31
|
0
|
345
|
my $target = caller; |
14
|
31
|
|
|
|
|
79
|
my $loader = pop; |
15
|
31
|
|
|
|
|
127
|
my @fields = @_; |
16
|
31
|
|
|
|
|
83
|
foreach my $f(@fields){ |
17
|
294
|
|
|
|
|
373
|
my($src,$dst,$is); |
18
|
294
|
100
|
|
|
|
578
|
if(ref $f eq 'ARRAY'){ |
19
|
20
|
|
|
|
|
51
|
($src,$dst,$is) = @$f; |
20
|
|
|
|
|
|
|
} else { |
21
|
274
|
|
|
|
|
642
|
($src,$dst,$is) = ($f, $f,'ro'); |
22
|
|
|
|
|
|
|
} |
23
|
294
|
|
50
|
|
|
837
|
$is ||= 'ro'; |
24
|
12
|
|
|
12
|
|
5347
|
no strict 'refs'; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
1519
|
|
25
|
294
|
|
|
|
|
779
|
my $sub = $target . '::' . $dst; |
26
|
|
|
|
|
|
|
*$sub = sub { |
27
|
13
|
|
|
13
|
|
3068
|
my $self = shift; |
28
|
13
|
100
|
|
|
|
59
|
unless ( exists $self->{$dst} ) { |
29
|
2
|
|
|
|
|
11
|
$self->load; |
30
|
|
|
|
|
|
|
} |
31
|
13
|
50
|
66
|
|
|
61
|
if($is eq 'rw' && @_){ |
32
|
0
|
|
|
|
|
0
|
$self->{$dst} = shift; |
33
|
|
|
|
|
|
|
} |
34
|
13
|
|
|
|
|
161
|
return $self->{$dst}; |
35
|
294
|
|
|
|
|
2861
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
12
|
|
|
12
|
|
72
|
no strict 'refs'; |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
2374
|
|
38
|
31
|
|
|
|
|
109
|
my $loader_target = $target . '::load'; |
39
|
|
|
|
|
|
|
*$loader_target = sub { |
40
|
4
|
|
|
4
|
|
9
|
my $self = shift; |
41
|
4
|
|
|
|
|
17
|
my $data = $self->$loader; |
42
|
3
|
50
|
|
|
|
153
|
my @src = map { ref $_ ? $_->[0] : $_ } @fields; |
|
6
|
|
|
|
|
112
|
|
43
|
3
|
50
|
|
|
|
8
|
my @dst = map { ref $_ ? $_->[1] : $_ } @fields; |
|
6
|
|
|
|
|
26
|
|
44
|
3
|
|
|
|
|
9
|
@{$self}{@dst} = @{$data}{@src}; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
9
|
|
45
|
3
|
|
|
|
|
18
|
return $self; |
46
|
31
|
|
|
|
|
324
|
}; |
47
|
31
|
|
|
|
|
93
|
my $constructor_target = $target . '::new'; |
48
|
31
|
|
|
|
|
52
|
my $original = \&{ $constructor_target }; |
|
31
|
|
|
|
|
135
|
|
49
|
12
|
|
|
12
|
|
102
|
no warnings 'redefine'; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
2679
|
|
50
|
|
|
|
|
|
|
*$constructor_target = sub { |
51
|
12
|
|
|
12
|
|
1184
|
my $class = shift; |
52
|
12
|
|
|
|
|
69
|
my %args = @_; |
53
|
12
|
|
|
|
|
133
|
my $self = $class->$original(@_); |
54
|
12
|
|
|
|
|
11865
|
foreach my $f(@fields){ |
55
|
80
|
|
|
|
|
167
|
my($src,$dst); |
56
|
80
|
100
|
|
|
|
164
|
if(ref $f eq 'ARRAY'){ |
57
|
14
|
|
|
|
|
41
|
($src,$dst) = @$f; |
58
|
|
|
|
|
|
|
} else { |
59
|
66
|
|
|
|
|
920
|
($src,$dst) = ($f, $f); |
60
|
|
|
|
|
|
|
} |
61
|
80
|
100
|
66
|
|
|
14283
|
if(!exists $self->{$dst} && exists $args{$src}){ |
62
|
14
|
|
|
|
|
57
|
$self->{$dst} = $args{$src}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
12
|
|
|
|
|
100
|
return $self; |
66
|
31
|
|
|
|
|
339
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |