line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::LazyRequire; |
2
|
1
|
|
|
1
|
|
60344
|
use strictures 1; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
30
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.001001'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
97
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
159
|
|
8
|
1
|
|
|
1
|
|
1085
|
use Sub::Quote; |
|
1
|
|
|
|
|
5408
|
|
|
1
|
|
|
|
|
84
|
|
9
|
1
|
|
|
1
|
|
1233
|
use Class::Method::Modifiers qw(install_modifier); |
|
1
|
|
|
|
|
15309
|
|
|
1
|
|
|
|
|
627
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
2
|
|
|
2
|
|
13940
|
my ($class) = @_; |
13
|
2
|
|
|
|
|
9
|
my $target = caller; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
install_modifier $target, 'around', 'has', sub { |
16
|
6
|
|
|
6
|
|
35313
|
my $orig = shift; |
17
|
6
|
|
|
|
|
27
|
my ($attrs, %opts) = @_; |
18
|
6
|
100
|
|
|
|
24
|
my @attrs = ref $attrs ? @$attrs : $attrs; |
19
|
6
|
100
|
|
|
|
18
|
if ($opts{lazy_required}) { |
20
|
4
|
50
|
33
|
|
|
125
|
if (exists $opts{lazy} && !$opts{lazy}) { |
|
|
50
|
33
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
croak "LazyRequire can't be used with lazy => 0"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
elsif (exists $opts{default} || exists $opts{builder}) { |
24
|
0
|
|
|
|
|
0
|
croak "You may not use both a builder or a default and lazy_required for one attribute (" |
25
|
|
|
|
|
|
|
. (join ', ', @attrs) . ")"; |
26
|
|
|
|
|
|
|
} |
27
|
4
|
|
|
|
|
11
|
$opts{lazy} = 1; |
28
|
4
|
|
|
|
|
7
|
for my $attr (@attrs) { |
29
|
6
|
|
|
|
|
1080
|
my $opts = { |
30
|
|
|
|
|
|
|
default => quote_sub(qq{ |
31
|
|
|
|
|
|
|
Carp::croak("Attribute '\Q$attr\E' must be provided before calling reader"); |
32
|
|
|
|
|
|
|
}), |
33
|
|
|
|
|
|
|
%opts, |
34
|
|
|
|
|
|
|
}; |
35
|
6
|
|
|
|
|
561
|
$orig->($attr, %$opts); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
2
|
|
|
|
|
17
|
$orig->($attrs, %opts); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
2
|
|
|
|
|
19
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |