line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::SetOnce; |
2
|
1
|
|
|
1
|
|
34299
|
use strictures 1; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
28
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.001003'; |
5
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
84
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
1574
|
use Class::Method::Modifiers qw(install_modifier); |
|
1
|
|
|
|
|
1470
|
|
|
1
|
|
|
|
|
370
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
2
|
|
|
2
|
|
8406
|
my ($class) = @_; |
12
|
2
|
|
|
|
|
6
|
my $target = caller; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
install_modifier $target, 'around', 'has', sub { |
15
|
14
|
|
|
14
|
|
16171
|
my $orig = shift; |
16
|
14
|
|
|
|
|
40
|
my ($attr, %opts) = @_; |
17
|
14
|
100
|
|
|
|
44
|
return $orig->($attr, %opts) |
18
|
|
|
|
|
|
|
unless delete $opts{once}; |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
15
|
my $is = $opts{is}; |
21
|
12
|
|
|
|
|
11
|
my $writer = $opts{writer}; |
22
|
12
|
100
|
|
|
|
27
|
if ($is eq 'rw') { |
|
|
50
|
|
|
|
|
|
23
|
10
|
|
66
|
|
|
32
|
$writer ||= $attr; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ($is eq 'rwp') { |
26
|
2
|
|
33
|
|
|
11
|
$writer ||= "_set_$attr"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
0
|
|
|
|
|
0
|
croak "SetOnce can't be used on read-only accessors"; |
30
|
|
|
|
|
|
|
} |
31
|
12
|
|
66
|
|
|
36
|
my $predicate = $opts{predicate} ||= '_has_' . $attr; |
32
|
|
|
|
|
|
|
|
33
|
12
|
|
50
|
|
|
37
|
$opts{moosify} ||= []; |
34
|
12
|
|
|
|
|
40
|
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
|
|
|
|
|
12
|
}; |
41
|
|
|
|
|
|
|
|
42
|
12
|
|
|
|
|
37
|
$orig->($attr, %opts); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$target->can('before')->($writer, sub { |
45
|
24
|
|
|
|
|
13414
|
my ($self) = @_; |
46
|
24
|
100
|
100
|
|
|
371
|
if (@_ > 1 && $self->$predicate) { |
47
|
10
|
|
|
|
|
961
|
croak "cannot change value of SetOnce attribute $attr"; |
48
|
|
|
|
|
|
|
} |
49
|
12
|
|
|
|
|
3757
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
15
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |