line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::SetOnce; |
2
|
2
|
|
|
2
|
|
83592
|
use strictures 1; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
65
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.001002'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
238
|
use Carp; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
173
|
|
8
|
2
|
|
|
2
|
|
2051
|
use Class::Method::Modifiers qw(install_modifier); |
|
2
|
|
|
|
|
3623
|
|
|
2
|
|
|
|
|
1228
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
2
|
|
|
2
|
|
14023
|
my ($class) = @_; |
12
|
2
|
|
|
|
|
7
|
my $target = caller; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
install_modifier $target, 'around', 'has', sub { |
15
|
14
|
|
|
14
|
|
23453
|
my $orig = shift; |
16
|
14
|
|
|
|
|
49
|
my ($attr, %opts) = @_; |
17
|
14
|
100
|
|
|
|
55
|
return $orig->($attr, %opts) |
18
|
|
|
|
|
|
|
unless delete $opts{once}; |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
17
|
my $is = $opts{is}; |
21
|
12
|
|
|
|
|
13
|
my $writer = $opts{writer}; |
22
|
12
|
100
|
|
|
|
29
|
if ($is eq 'rw') { |
|
|
50
|
|
|
|
|
|
23
|
10
|
|
66
|
|
|
38
|
$writer ||= $attr; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($is eq 'rwp') { |
26
|
2
|
|
33
|
|
|
10
|
$writer ||= "_set_$attr"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
0
|
|
|
|
|
0
|
croak "SetOnce can't be used on read-only accessors"; |
30
|
|
|
|
|
|
|
} |
31
|
12
|
|
66
|
|
|
50
|
my $predicate = $opts{predicate} ||= '_has_' . $attr; |
32
|
|
|
|
|
|
|
|
33
|
12
|
|
50
|
|
|
44
|
$opts{moosify} ||= []; |
34
|
12
|
|
|
|
|
46
|
push @{$opts{moosify}}, sub { |
35
|
0
|
|
|
|
|
0
|
my ($spec) = @_; |
36
|
|
|
|
|
|
|
require # hide from CPANTS |
37
|
0
|
|
|
|
|
0
|
MooseX::SetOnce; |
38
|
0
|
|
0
|
|
|
0
|
$spec->{traits} ||= []; |
39
|
0
|
|
|
|
|
0
|
push @{$spec->{traits}}, 'SetOnce'; |
|
0
|
|
|
|
|
0
|
|
40
|
12
|
|
|
|
|
14
|
}; |
41
|
|
|
|
|
|
|
|
42
|
12
|
|
|
|
|
44
|
$orig->($attr, %opts); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$target->can('before')->($writer, sub { |
45
|
24
|
|
|
|
|
19803
|
my ($self) = @_; |
46
|
24
|
100
|
100
|
|
|
490
|
if (@_ > 1 && $self->$predicate) { |
47
|
10
|
|
|
|
|
1396
|
croak "cannot change value of SetOnce attribute $attr"; |
48
|
|
|
|
|
|
|
} |
49
|
12
|
|
|
|
|
4810
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
19
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |