line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Thrift::IDL::Enum; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Thrift::IDL::Enum |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Inherits from L |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
221
|
|
14
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
10163
|
|
15
|
6
|
|
|
6
|
|
45
|
use base qw(Thrift::IDL::Definition); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2187
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(name values)); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 name |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 values |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Scalar accessors |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 numbered_values |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Numbering the Enum is optional in the Thrift spec. Calling this method will assign incremented numbers to each value (if they have no number) |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub numbered_values { |
33
|
15
|
|
|
15
|
1
|
28892
|
my $self = shift; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
31
|
my $last_value = -1; |
36
|
15
|
|
|
|
|
23
|
foreach my $value_pair (@{ $self->values }) { |
|
15
|
|
|
|
|
56
|
|
37
|
60
|
100
|
|
|
|
289
|
if (! defined $value_pair->[1]) { |
38
|
8
|
|
|
|
|
20
|
$value_pair->[1] = ++$last_value; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
52
|
|
|
|
|
83
|
$last_value = $value_pair->[1]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
15
|
|
|
|
|
49
|
return $self->values; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 value_named |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Return the value (number) with the given name |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub value_named { |
55
|
6
|
|
|
6
|
1
|
8003
|
my ($self, $name) = @_; |
56
|
6
|
|
|
|
|
13
|
foreach my $value_pair (@{ $self->numbered_values }) { |
|
6
|
|
|
|
|
22
|
|
57
|
13
|
100
|
|
|
|
98
|
return $value_pair->[1] if $value_pair->[0] eq $name; |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
14
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 value_id_name |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Return the name for a given value (number) |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub value_id_name { |
69
|
8
|
|
|
8
|
1
|
124
|
my ($self, $id) = @_; |
70
|
8
|
|
|
|
|
13
|
foreach my $value_pair (@{ $self->numbered_values }) { |
|
8
|
|
|
|
|
22
|
|
71
|
26
|
100
|
|
|
|
144
|
return $value_pair->[0] if $value_pair->[1] == $id; |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
10
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |