| 1 | package Thrift::Parser::Type::map; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Thrift::Parser::Type::map - map 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 base qw(Thrift::Parser::Type::Container); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 6 | __PACKAGE__->mk_accessors(qw(key_type)); | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub read { | ||||||||
|
Subroutine
read: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 19 | 0 | my ($self, $parser, $input, $meta) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 0 | my @map; | |||||||||
| 22 | 0 | $input->readMapBegin(\$meta->{key_type}, \$meta->{val_type}, \$meta->{size}); | |||||||||
| 23 | 0 | my %val_meta = ( type => $meta->{val_type} ); | |||||||||
| 24 | 0 | my %key_meta = ( type => $meta->{key_type} ); | |||||||||
| 25 | 0 | ▶ | $val_meta{idl}{type} = $parser->resolve_idl_type( $meta->{idl}{type} )->val_type if $meta->{idl}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | ▶ | $key_meta{idl}{type} = $parser->resolve_idl_type( $meta->{idl}{type} )->key_type if $meta->{idl}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | for (my $i = 0; $i < $meta->{size}; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | my $key = $parser->parse_type($input, { %key_meta }); | |||||||||
| 29 | 0 | my $val = $parser->parse_type($input, { %val_meta }); | |||||||||
| 30 | 0 | push @map, [ $key => $val ]; | |||||||||
| 31 | } | ||||||||||
| 32 | 0 | $input->readMapEnd(); | |||||||||
| 33 | |||||||||||
| 34 | 0 | $self->value(\@map); | |||||||||
| 35 | 0 | $self->val_type($meta->{val_type}); | |||||||||
| 36 | 0 | $self->key_type($meta->{key_type}); | |||||||||
| 37 | 0 | return $self; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub write { | ||||||||
|
Subroutine
write: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 41 | 0 | my ($self, $output) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 0 | my @map = @{ $self->value }; | |||||||||
| 44 | 0 | $output->writeMapBegin($self->key_type, $self->val_type, int @map); | |||||||||
| 45 | 0 | foreach my $pair (@map) { | |||||||||
| 46 | 0 | $_->write($output) foreach @$pair; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | $output->writeMapEnd(); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | =head1 COPYRIGHT | ||||||||||
| 52 | |||||||||||
| 53 | 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. | ||||||||||
| 54 | |||||||||||
| 55 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||
| 56 | |||||||||||
| 57 | =head1 AUTHOR | ||||||||||
| 58 | |||||||||||
| 59 | Eric Waters <ewaters@gmail.com> | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 6 | 1; | |||||||||