| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 72 | } | ||||||||||
| 73 | 0 | return; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 4 | 1; | |||||||||