line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
11
|
|
|
11
|
|
8305
|
use 5.008001; |
|
11
|
|
|
|
|
33
|
|
2
|
11
|
|
|
11
|
|
49
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
202
|
|
3
|
11
|
|
|
11
|
|
46
|
use warnings; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
714
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package MooseX::Enumeration::Meta::Attribute::Native::Trait::Enumeration; |
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
7
|
|
|
|
|
|
|
our $VERSION = '0.010'; |
8
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
3999
|
use Moose::Role; |
|
11
|
|
|
|
|
43372
|
|
|
11
|
|
|
|
|
40
|
|
10
|
|
|
|
|
|
|
with 'Moose::Meta::Attribute::Native::Trait'; |
11
|
|
|
|
|
|
|
|
12
|
11
|
|
|
11
|
|
52466
|
use Module::Runtime qw( use_package_optimistically ); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
66
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
before _process_isa_option => sub |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my $class = shift; |
17
|
|
|
|
|
|
|
my ($name, $options) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ($options->{enum}) |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
confess "Cannot supply both the 'isa' and 'enum' options" |
22
|
|
|
|
|
|
|
if $options->{isa}; |
23
|
|
|
|
|
|
|
require MooseX::Enumeration; |
24
|
|
|
|
|
|
|
$options->{isa} = 'MooseX::Enumeration' |
25
|
|
|
|
|
|
|
-> _enum_type_implementation |
26
|
|
|
|
|
|
|
-> new( values => $options->{enum} ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
36
|
|
|
36
|
|
6595
|
sub _helper_type { 'Str' } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
around _check_helper_type => sub { 1 }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has enum => (is => 'ro', lazy => 1, builder => '_build_enum'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _build_enum |
37
|
|
|
|
|
|
|
{ |
38
|
3
|
|
|
3
|
|
6
|
my $meta = shift; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
6
|
my $enum; |
41
|
3
|
|
|
|
|
111
|
my $type = $meta->type_constraint; |
42
|
3
|
|
|
|
|
25
|
while (defined $type) |
43
|
|
|
|
|
|
|
{ |
44
|
3
|
50
|
66
|
|
|
38
|
if ($type->isa('Type::Tiny::Enum') |
45
|
|
|
|
|
|
|
or $type->isa('Moose::Meta::TypeConstraint::Enum')) |
46
|
|
|
|
|
|
|
{ |
47
|
3
|
|
|
|
|
88
|
return $type->values; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
$type = $type->parent; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
confess "could not find values for enumeration"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
around _canonicalize_handles => sub |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
my $next = shift; |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
my $handles = $self->handles; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return unless $handles; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if (!ref $handles and $handles eq 1) |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
return map +("is_$_" => ["is", $_]), @{ $self->enum }; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif (!ref $handles and $handles eq 2) |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
my $attr = $self->name; |
70
|
|
|
|
|
|
|
return map +("$attr\_is_$_" => ["is", $_]), @{ $self->enum }; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if (ref $handles eq 'ARRAY') |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
return map +($_ => [split /_/, $_, 2]), @$handles; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my %handles = $self->$next(@_); |
79
|
|
|
|
|
|
|
for my $h (values %handles) |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
next unless $h->[0] =~ /^(is|assign)_(\w+)$/; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @s = split /_/, shift(@$h), 2; |
84
|
|
|
|
|
|
|
unshift @$h, @s; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
return %handles; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
around _native_accessor_class_for => sub |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
my $next = shift; |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
my ($suffix) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $role |
96
|
|
|
|
|
|
|
= 'MooseX::Enumeration::Meta::Method::Accessor::Native::' |
97
|
|
|
|
|
|
|
. $self->_native_type . '::' |
98
|
|
|
|
|
|
|
. $suffix; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return Moose::Meta::Class->create_anon_class( |
101
|
|
|
|
|
|
|
superclasses => [ $self->accessor_metaclass, $self->delegation_metaclass ], |
102
|
|
|
|
|
|
|
roles => [ use_package_optimistically($role) ], |
103
|
|
|
|
|
|
|
cache => 1, |
104
|
|
|
|
|
|
|
)->name; |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |