line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moxie::Enum; |
2
|
|
|
|
|
|
|
# ABSTRACT: Yet Another Enum Generator |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
47822
|
use v5.22; |
|
1
|
|
|
|
|
11
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
|
|
4
|
use experimental qw[ |
7
|
|
|
|
|
|
|
signatures |
8
|
|
|
|
|
|
|
postderef |
9
|
1
|
|
|
1
|
|
367
|
]; |
|
1
|
|
|
|
|
2812
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
164
|
use Scalar::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
12
|
1
|
|
|
1
|
|
270
|
use BEGIN::Lift (); |
|
1
|
|
|
|
|
4390
|
|
|
1
|
|
|
|
|
259
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
15
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ... |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %PACKAGE_TO_ENUM; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
96
|
sub import ($class) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
3
|
|
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
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
3
|
|
29
|
2
|
|
|
|
|
4
|
BEGIN::Lift::install( |
30
|
2
|
|
|
2
|
|
2
|
($caller, 'enum') => sub ($type, @args) { |
|
2
|
|
|
|
|
271
|
|
|
2
|
|
|
|
|
4
|
|
31
|
2
|
|
|
|
|
3
|
my %enum; |
32
|
2
|
100
|
66
|
|
|
10
|
if ( scalar @args == 1 && ref $args[0] eq 'HASH' ) { |
33
|
1
|
|
|
|
|
3
|
%enum = $args[0]->%*; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
1
|
|
|
|
|
15
|
my $idx = 0; |
37
|
1
|
|
|
|
|
5
|
%enum = map { $_ => ++$idx } @args; |
|
2
|
|
|
|
|
9
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
7
|
foreach my $key ( keys %enum ) { |
41
|
1
|
|
|
1
|
|
9
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
441
|
|
42
|
4
|
|
|
|
|
16
|
$enum{ $key } = Scalar::Util::dualvar( $enum{ $key }, $key ); |
43
|
4
|
|
|
4
|
|
14
|
*{$caller.'::'.$key} = sub (@) { $enum{ $key } }; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
5270
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
50
|
|
|
22
|
$PACKAGE_TO_ENUM{ $caller } //= {}; |
47
|
2
|
|
|
|
|
5
|
$PACKAGE_TO_ENUM{ $caller }->{ $type } = \%enum; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
1044
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
11
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
## ... |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
8
|
0
|
2061
|
sub get_enum_for ($pkg, $type) { |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
8
|
|
57
|
|
|
|
|
|
|
return unless exists $PACKAGE_TO_ENUM{ $pkg } |
58
|
8
|
50
|
33
|
|
|
38
|
&& exists $PACKAGE_TO_ENUM{ $pkg }->{ $type }; |
59
|
8
|
|
|
|
|
31
|
return $PACKAGE_TO_ENUM{ $pkg }->{ $type }->%*; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
0
|
4
|
sub get_value_for ($pkg, $type, $name) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3
|
|
63
|
2
|
|
|
|
|
5
|
my %enum = get_enum_for( $pkg, $type ); |
64
|
2
|
|
|
|
|
9
|
return $enum{ $name }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
3
|
0
|
1457
|
sub has_value_for ($pkg, $type, $name) { |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3
|
|
68
|
3
|
|
|
|
|
5
|
my %enum = get_enum_for( $pkg, $type ); |
69
|
3
|
|
|
|
|
299
|
return exists $enum{ $name }; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
0
|
3
|
sub get_keys_for ($pkg, $type) { my %enum = get_enum_for( $pkg, $type ); keys %enum } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
73
|
1
|
|
|
1
|
0
|
509
|
sub get_values_for ($pkg, $type) { my %enum = get_enum_for( $pkg, $type ); values %enum } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |