| 1 | package Thrift::Parser::Type::set; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =head1 NAME | ||||||||||||||
| 4 | |||||||||||||||
| 5 | Thrift::Parser::Type::set - set type | ||||||||||||||
| 6 | |||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||
| 8 | |||||||||||||||
| 9 | This class inherits from L<Thrift::Parser::Type::Container>. See the docs there for all the usage details. | ||||||||||||||
| 10 | |||||||||||||||
| 11 | =cut | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 6 | ▶ | use base qw(Thrift::Parser::Type::Container); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 USAGE | ||||||||||||||
| 19 | |||||||||||||||
| 20 | =cut | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 0 | ▶ | sub read { | ||||||||||||
|
Subroutine
read: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 23 | 0 | my ($self, $parser, $input, $meta) = @_; | |||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | $input->readSetBegin(\$meta->{val_type}, \$meta->{size}); | |||||||||||||
| 26 | 0 | my %val_meta = ( type => $meta->{val_type} ); | |||||||||||||
| 27 | 0 | ▶ | $val_meta{idl}{type} = $parser->resolve_idl_type( $meta->{idl}{type} )->val_type if $meta->{idl}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 0 | my @list; | |||||||||||||
| 29 | 0 | ▶ | for (my $i = 0; $i < $meta->{size}; $i++) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | 0 | my $val = $parser->parse_type($input, { %val_meta }); | |||||||||||||
| 31 | 0 | push @list, $val; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | 0 | $input->readSetEnd(); | |||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | $self->value(\@list); | |||||||||||||
| 36 | 0 | $self->val_type($meta->{val_type}); | |||||||||||||
| 37 | 0 | return $self; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | sub write { | ||||||||||||
|
Subroutine
write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 41 | 0 | my ($self, $output) = @_; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | my @list = @{ $self->value }; | |||||||||||||
| 44 | 0 | $output->writeSetBegin($self->val_type, int @list); | |||||||||||||
| 45 | 0 | $_->write($output) foreach @list; | |||||||||||||
| 46 | 0 | $output->writeSetEnd(); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head2 is_set | ||||||||||||||
| 50 | |||||||||||||||
| 51 | if ($string_set->is_set($string)) { .. } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | Pass a blessed object that matches the $val_type of this object, or at least a perl scalar that can be C<compose()>'ed into the class. Returns boolean value if the value is present in this set. Throws L<Thrift::Parser::InvalidArgument>. | ||||||||||||||
| 54 | |||||||||||||||
| 55 | =cut | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | sub is_set { | ||||||||||||
|
Subroutine
is_set: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 58 | 0 | my ($self, $test) = @_; | |||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | ▶ | if (! blessed $test) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 61 | 0 | $test = $self->{val_type_class}->compose($test); | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | elsif (! $test->isa( $self->{val_type_class} )) { | ||||||||||||||
| 64 | 0 | Thrift::Parser::InvalidArgument->throw("is_set() must be called with a $$self{val_type_class} object"); | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | foreach my $value (@{ $self->value }) { | |||||||||||||
| 68 | 0 | ▶ | if ($value->equal_to($test)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | 0 | return 1; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | 0 | return 0; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | =head1 COPYRIGHT | ||||||||||||||
| 76 | |||||||||||||||
| 77 | Copyright (c) 2009 Eric Waters and XMission LLC (http://www.xmission.com/). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||
| 78 | |||||||||||||||
| 79 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 AUTHOR | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Eric Waters <ewaters@gmail.com> | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =cut | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 6 | 1; | |||||||||||||