IDL/Enum.pm

filter: Statementstmt 37.9% 11 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 38.6% 17 / 44 CC 7 SCAR 22.2
CC
7
Cov
31%
numbered_values
12.0
value_named
12.0
value_id_name
12.0
CRAP 9.2
« Parser/Type/bool.pm ↑ Summary Parser/Type/list.pm »
1 package Thrift::IDL::Enum;
2  
3 =head1 NAME
4  
5 Thrift::IDL::Enum
6  
7 =head1 DESCRIPTION
8  
9 Inherits from L<Thrift::IDL::Definition>
10  
11 =cut
12  
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use base qw(Thrift::IDL::Definition);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 __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 0 ▶sub numbered_values {
Subroutine numbered_values: not called CC=3 SCAR=24.8
Pod documented
33 0 my $self = shift;
34  
35 0 my $last_value = -1;
36 0 foreach my $value_pair (@{ $self->values }) {
37 0 ▶ if (! defined $value_pair->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value_pair->[1]) { } 0 0 0
38 0 $value_pair->[1] = ++$last_value;
39 }
40 else {
41 0 $last_value = $value_pair->[1];
42 }
43 }
44  
45 0 return $self->values;
46 }
47  
48 =head2 value_named
49  
50 Return the value (number) with the given name
51  
52 =cut
53  
54 0 ▶sub value_named {
Subroutine value_named: not called CC=3 SCAR=24.8
Pod documented
55 0 my ($self, $name) = @_;
56 0 foreach my $value_pair (@{ $self->numbered_values }) {
57 0 ▶ return $value_pair->[1] if $value_pair->[0] eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $value_pair->[0] eq $name 0 0 0
58 }
59 0 return;
60 }
61  
62 =head2 value_id_name
63  
64 Return the name for a given value (number)
65  
66 =cut
67  
68 0 ▶sub value_id_name {
Subroutine value_id_name: not called CC=3 SCAR=24.8
Pod documented
69 0 my ($self, $id) = @_;
70 0 foreach my $value_pair (@{ $self->numbered_values }) {
71 0 ▶ return $value_pair->[0] if $value_pair->[1] == $id;
Branch: 1 branch
BranchTrueFalseTotal
if $value_pair->[1] == $id 0 0 0
72 }
73 0 return;
74 }
75  
76 4 1;
« Parser/Type/bool.pm ↑ Summary Parser/Type/list.pm »