line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moxie::Enum; |
2
|
|
|
|
|
|
|
# ABSTRACT: Yet Another Enum Generator |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
44765
|
use v5.22; |
|
1
|
|
|
|
|
10
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
|
|
4
|
use experimental qw[ |
7
|
|
|
|
|
|
|
signatures |
8
|
|
|
|
|
|
|
postderef |
9
|
1
|
|
|
1
|
|
228
|
]; |
|
1
|
|
|
|
|
2450
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
141
|
use Scalar::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
12
|
1
|
|
|
1
|
|
238
|
use BEGIN::Lift (); |
|
1
|
|
|
|
|
4006
|
|
|
1
|
|
|
|
|
218
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
15
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ... |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %PACKAGE_TO_ENUM; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
79
|
sub import ($class) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2
|
|
22
|
|
|
|
|
|
|
# get the caller ... |
23
|
2
|
|
|
|
|
5
|
my $caller = caller; |
24
|
|
|
|
|
|
|
# and call import_into ... |
25
|
2
|
|
|
|
|
4
|
$class->import_into( $caller ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
0
|
2
|
sub import_into ($class, $caller) { |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2
|
|
29
|
2
|
|
|
|
|
2
|
BEGIN::Lift::install( |
30
|
2
|
|
|
2
|
|
3
|
($caller, 'enum') => sub ($type, @args) { |
|
2
|
|
|
|
|
215
|
|
|
2
|
|
|
|
|
4
|
|
31
|
2
|
|
|
|
|
2
|
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
|
|
|
|
|
5
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
7
|
foreach my $key ( keys %enum ) { |
41
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
387
|
|
42
|
4
|
|
|
|
|
12
|
$enum{ $key } = Scalar::Util::dualvar( $enum{ $key }, $key ); |
43
|
4
|
|
|
4
|
|
7
|
*{$caller.'::'.$key} = sub (@) { $enum{ $key } }; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
6077
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
50
|
|
|
11
|
$PACKAGE_TO_ENUM{ $caller } //= {}; |
47
|
2
|
|
|
|
|
7
|
$PACKAGE_TO_ENUM{ $caller }->{ $type } = \%enum; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
943
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
2
|
|
|
|
|
10
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
## ... |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
8
|
0
|
2460
|
sub get_enum_for ($pkg, $type) { |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
10
|
|
57
|
|
|
|
|
|
|
return unless exists $PACKAGE_TO_ENUM{ $pkg } |
58
|
8
|
50
|
33
|
|
|
36
|
&& exists $PACKAGE_TO_ENUM{ $pkg }->{ $type }; |
59
|
8
|
|
|
|
|
29
|
return $PACKAGE_TO_ENUM{ $pkg }->{ $type }->%*; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
0
|
3
|
sub get_value_for ($pkg, $type, $name) { |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2
|
|
63
|
2
|
|
|
|
|
4
|
my %enum = get_enum_for( $pkg, $type ); |
64
|
2
|
|
|
|
|
9
|
return $enum{ $name }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
3
|
0
|
1441
|
sub has_value_for ($pkg, $type, $name) { |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
4
|
|
68
|
3
|
|
|
|
|
6
|
my %enum = get_enum_for( $pkg, $type ); |
69
|
3
|
|
|
|
|
15
|
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
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
73
|
1
|
|
|
1
|
0
|
504
|
sub get_values_for ($pkg, $type) { my %enum = get_enum_for( $pkg, $type ); values %enum } |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |