line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moxie::Enum; |
2
|
|
|
|
|
|
|
# ABSTRACT: Yet Another Enum Generator |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
54255
|
use v5.22; |
|
1
|
|
|
|
|
11
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
|
|
5
|
use experimental qw[ |
7
|
|
|
|
|
|
|
signatures |
8
|
|
|
|
|
|
|
postderef |
9
|
1
|
|
|
1
|
|
237
|
]; |
|
1
|
|
|
|
|
2323
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
141
|
use Scalar::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
12
|
1
|
|
|
1
|
|
242
|
use BEGIN::Lift (); |
|
1
|
|
|
|
|
3862
|
|
|
1
|
|
|
|
|
226
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
15
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ... |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %PACKAGE_TO_ENUM; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
77
|
sub import ($class) { |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2
|
|
22
|
|
|
|
|
|
|
# get the caller ... |
23
|
2
|
|
|
|
|
4
|
my $caller = caller; |
24
|
|
|
|
|
|
|
# and call import_into ... |
25
|
2
|
|
|
|
|
5
|
$class->import_into( $caller ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
0
|
3
|
sub import_into ($class, $caller) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
2
|
|
29
|
2
|
|
|
|
|
2
|
BEGIN::Lift::install( |
30
|
2
|
|
|
2
|
|
2
|
($caller, 'enum') => sub ($type, @args) { |
|
2
|
|
|
|
|
244
|
|
|
2
|
|
|
|
|
4
|
|
31
|
2
|
|
|
|
|
3
|
my %enum; |
32
|
2
|
100
|
66
|
|
|
9
|
if ( scalar @args == 1 && ref $args[0] eq 'HASH' ) { |
33
|
1
|
|
|
|
|
4
|
%enum = $args[0]->%*; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
|
|
2
|
my $idx = 0; |
37
|
1
|
|
|
|
|
2
|
%enum = map { $_ => ++$idx } @args; |
|
2
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
5
|
foreach my $key ( keys %enum ) { |
41
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
385
|
|
42
|
4
|
|
|
|
|
10
|
$enum{ $key } = Scalar::Util::dualvar( $enum{ $key }, $key ); |
43
|
4
|
|
|
4
|
|
11
|
*{$caller.'::'.$key} = sub (@) { $enum{ $key } }; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
5622
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
50
|
|
|
10
|
$PACKAGE_TO_ENUM{ $caller } //= {}; |
47
|
2
|
|
|
|
|
5
|
$PACKAGE_TO_ENUM{ $caller }->{ $type } = \%enum; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
924
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
10
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
## ... |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
8
|
0
|
2293
|
sub get_enum_for ($pkg, $type) { |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
10
|
|
57
|
|
|
|
|
|
|
return unless exists $PACKAGE_TO_ENUM{ $pkg } |
58
|
8
|
50
|
33
|
|
|
39
|
&& exists $PACKAGE_TO_ENUM{ $pkg }->{ $type }; |
59
|
8
|
|
|
|
|
33
|
return $PACKAGE_TO_ENUM{ $pkg }->{ $type }->%*; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
0
|
5
|
sub get_value_for ($pkg, $type, $name) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
3
|
|
63
|
2
|
|
|
|
|
5
|
my %enum = get_enum_for( $pkg, $type ); |
64
|
2
|
|
|
|
|
10
|
return $enum{ $name }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
3
|
0
|
1662
|
sub has_value_for ($pkg, $type, $name) { |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
3
|
|
68
|
3
|
|
|
|
|
5
|
my %enum = get_enum_for( $pkg, $type ); |
69
|
3
|
|
|
|
|
16
|
return exists $enum{ $name }; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
0
|
2
|
sub get_keys_for ($pkg, $type) { my %enum = get_enum_for( $pkg, $type ); keys %enum } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
73
|
1
|
|
|
1
|
0
|
644
|
sub get_values_for ($pkg, $type) { my %enum = get_enum_for( $pkg, $type ); values %enum } |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |