line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::VariantAttribute; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
360664
|
use strict; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
115
|
|
4
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
110
|
|
5
|
4
|
|
|
4
|
|
18
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
165
|
|
6
|
4
|
|
|
4
|
|
1860
|
use MooX::ReturnModifiers; |
|
4
|
|
|
|
|
2009
|
|
|
4
|
|
|
|
|
1118
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
12
|
|
|
12
|
|
8319
|
my ( $package, @import ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
12
|
|
|
|
|
30
|
my $target = caller; |
13
|
12
|
|
|
|
|
47
|
my %modifiers = return_modifiers( $target, [qw/has around with/] ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $variant = sub { |
16
|
17
|
|
|
17
|
|
172605
|
my ( $name, %spec ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
17
|
100
|
|
|
|
78
|
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
|
|
6622
|
my ($orig, $self) = (shift, shift); |
22
|
3
|
|
|
|
|
14
|
return $self->_given_when($self->$orig(@_), $spec{given}, $spec{when}, $name); |
23
|
3
|
|
|
|
|
25
|
}); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
17
|
|
|
|
|
3587
|
$modifiers{has}->( $name => _construct_attribute( $name, %spec ) ); |
27
|
|
|
|
|
|
|
|
28
|
12
|
|
|
|
|
398
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$target->can('_given_when') |
31
|
12
|
50
|
|
|
|
127
|
or $modifiers{with}->('MooX::VariantAttribute::Role'); |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
4
|
|
33
|
{ no strict 'refs'; *{"${target}::variant"} = $variant; } |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1229
|
|
|
12
|
|
|
|
|
39195
|
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
62
|
|
34
|
|
|
|
|
|
|
|
35
|
12
|
|
|
|
|
428
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _construct_attribute { |
39
|
17
|
|
|
17
|
|
57
|
my ( $name, %spec ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $trigger = sub { |
42
|
69
|
|
|
69
|
|
36205
|
return $_[0]->_given_when( $_[1], $spec{given}, $spec{when}, $name ); |
43
|
17
|
|
|
|
|
73
|
}; |
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
|
|
6693
|
$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
|
17
|
100
|
|
|
|
100
|
(map {( |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
77
|
102
|
100
|
|
|
|
262
|
$spec{$_} ? ( $_ => $spec{$_} ) : () |
78
|
|
|
|
|
|
|
)} qw/lazy predicate clearer required reader writer/), |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |