| 1 | package Thrift::Parser::Type::Struct; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Thrift::Parser::Type::Struct - Struct type | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =cut | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use base qw(Thrift::Parser::Type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 6 | __PACKAGE__->mk_value_passthrough_methods(qw(named field_named id ids field_values keyed_field_values keyed_field_values_plain)); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | This class inherits from L<Thrift::Parser::Type>; see docs there for inherited methods. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head2 value | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Returns the L<Thrift::Parser::FieldSet> object which represents the data in this type. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | The following methods are available on this class that are passthrough methods to the C<value> object: | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $field = $object->named('id'); | ||||||||||||||||||||||||||||
| 29 | is equivalent to: | ||||||||||||||||||||||||||||
| 30 | my $field = $object->value->named('id'); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =over | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =item I<named> | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =item I<id> | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item I<ids> | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item I<field_values> | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item I<keyed_field_values> | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =back | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 compose | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | my $object = $class->compose({ ... }); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Call with a hashref of key/value pairs to create a new object. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub compose { | ||||||||||||||||||||||||||
|
Subroutine
compose: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($class, $value) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (blessed $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (! $value->isa($class)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | Thrift::Parser::InvalidArgument->throw("$class compose() can't take a value of ".ref($value)); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 0 | return $value; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my $fieldset = Thrift::Parser::FieldSet->compose($class, %$value); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | return $class->new({ value => $fieldset }); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $parser, $input, $meta) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Try and find the list of fields that comprise the structure | ||||||||||||||||||||||||||||
| 73 | 0 | my @sub_idl_fields; | |||||||||||||||||||||||||||
| 74 | 0 | for (1) { | |||||||||||||||||||||||||||
| 75 | last unless $meta->{idl} | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | && $meta->{idl}{type}->isa('Thrift::IDL::Type::Custom'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$meta->{"idl"} and $meta->{"idl"}{"type"}->isa("Thrift::IDL::Type::Custom")
MC/DC0%0/2
$meta->{"idl"} and $meta->{"idl"}{"type"}->isa("Thrift::IDL::Type::Custom")
$meta->{"idl"}
$meta->{"idl"}{"type"}->isa("Thrift::IDL::Type::Custom")
Truth table0%0/3
A and B
A= $meta->{"idl"}B= $meta->{"idl"}{"type"}->isa("Thrift::IDL::Type::Custom")
| |||||||||||||||||||||||||||||
| 77 | my $struct = $parser->idl->struct_named( | ||||||||||||||||||||||||||||
| 78 | $meta->{idl}{type}->name | ||||||||||||||||||||||||||||
| 79 | 0 | ); | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | last unless $struct; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | @sub_idl_fields = @{ $struct->fields }; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $self->value( | ||||||||||||||||||||||||||||
| 85 | 0 | $parser->parse_structure($input, \@sub_idl_fields) | |||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | 0 | return $self; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub write { | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my ($self, $output) = @_; | |||||||||||||||||||||||||||
| 92 | # FieldSet->write() encompasses all needed behavior | ||||||||||||||||||||||||||||
| 93 | 0 | $self->value->write($output); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub value_plain { | ||||||||||||||||||||||||||
|
Subroutine
value_plain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 0 | return $self->keyed_field_values_plain; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 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. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Eric Waters <ewaters@gmail.com> | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 6 | 1; | |||||||||||||||||||||||||||