line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::VariantAttribute; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
76031
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
66
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
63
|
|
5
|
3
|
|
|
3
|
|
9
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
750
|
|
|
3
|
|
|
|
|
137
|
|
6
|
3
|
|
|
3
|
|
1064
|
use MooX::ReturnModifiers; |
|
3
|
|
|
|
|
1906
|
|
|
3
|
|
|
|
|
872
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
11
|
|
|
11
|
|
5166
|
my ( $package, @import ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
11
|
|
|
|
|
16
|
my $target = caller; |
13
|
11
|
|
|
|
|
35
|
my %modifiers = return_modifiers( $target, [qw/has around with/] ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $variant = sub { |
16
|
14
|
|
|
14
|
|
81626
|
my ( $name, %spec ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
14
|
100
|
|
|
|
44
|
if ( my $builder = $spec{builder} ) { |
19
|
3
|
50
|
|
|
|
30
|
my $build_name = $builder =~ m/^1$/ ? sprintf "_build_%s", $name : $builder; |
20
|
|
|
|
|
|
|
$modifiers{around}->($build_name, sub { |
21
|
3
|
|
|
3
|
|
5924
|
my ($orig, $self) = (shift, shift); |
22
|
3
|
|
|
|
|
10
|
return $self->_given_when($self->$orig(@_), $spec{given}, $spec{when}, $name); |
23
|
3
|
|
|
|
|
24
|
}); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
14
|
|
|
|
|
3354
|
$modifiers{has}->( $name => _construct_attribute( $name, %spec ) ); |
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
|
|
245
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$target->can('_given_when') |
31
|
11
|
50
|
|
|
|
69
|
or $modifiers{with}->('MooX::VariantAttribute::Role'); |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
3
|
|
13
|
{ no strict 'refs'; *{"${target}::variant"} = $variant; } |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
596
|
|
|
11
|
|
|
|
|
20936
|
|
|
11
|
|
|
|
|
15
|
|
|
11
|
|
|
|
|
43
|
|
34
|
|
|
|
|
|
|
|
35
|
11
|
|
|
|
|
308
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _construct_attribute { |
39
|
14
|
|
|
14
|
|
35
|
my ( $name, %spec ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $trigger = sub { |
42
|
48
|
|
|
48
|
|
13127
|
return $_[0]->_given_when( $_[1], $spec{given}, $spec{when}, $name ); |
43
|
14
|
|
|
|
|
69
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
return ( |
46
|
|
|
|
|
|
|
is => 'rw', |
47
|
|
|
|
|
|
|
trigger => $trigger, |
48
|
|
|
|
|
|
|
( |
49
|
|
|
|
|
|
|
$spec{default} ? ( |
50
|
|
|
|
|
|
|
default => sub { |
51
|
|
|
|
|
|
|
return $_[0]->_given_when( |
52
|
|
|
|
|
|
|
( |
53
|
|
|
|
|
|
|
ref $spec{default} eq 'CODE' |
54
|
|
|
|
|
|
|
? $spec{default}->() |
55
|
|
|
|
|
|
|
: $spec{default} |
56
|
|
|
|
|
|
|
), |
57
|
|
|
|
|
|
|
$spec{given}, |
58
|
|
|
|
|
|
|
$spec{when}, |
59
|
3
|
100
|
|
3
|
|
6109
|
$name |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
) : () |
63
|
|
|
|
|
|
|
), |
64
|
|
|
|
|
|
|
( |
65
|
|
|
|
|
|
|
$spec{builder} ? ( |
66
|
|
|
|
|
|
|
builder => ref $spec{builder} eq 'CODE' ? sub { |
67
|
|
|
|
|
|
|
return $_[0]->_given_when( |
68
|
|
|
|
|
|
|
$spec{builder}->(), |
69
|
|
|
|
|
|
|
$spec{given}, |
70
|
|
|
|
|
|
|
$spec{when}, |
71
|
0
|
|
|
0
|
|
0
|
$name |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
} : $spec{builder} |
74
|
|
|
|
|
|
|
) : () |
75
|
|
|
|
|
|
|
), |
76
|
14
|
100
|
|
|
|
70
|
(map {( |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
77
|
84
|
100
|
|
|
|
166
|
$spec{$_} ? ( $_ => $spec{$_} ) : () |
78
|
|
|
|
|
|
|
)} qw/lazy predicate clearer required reader writer/), |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |