File Coverage

blib/lib/Thrift/Parser/Type/Struct.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 8 0.0
condition 0 3 0.0
subroutine 4 8 50.0
pod 4 4 100.0
total 20 56 35.7


line stmt bran cond sub pod time code
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     6   32 use strict;
  6         11  
  6         190  
12 6     6   32 use warnings;
  6         12  
  6         212  
13 6     6   31 use base qw(Thrift::Parser::Type);
  6         12  
  6         618  
14 6     6   33 use Scalar::Util qw(blessed);
  6         9  
  6         2511  
15              
16             __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; see docs there for inherited methods.
21              
22             =head2 value
23              
24             Returns the L 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 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
35              
36             =item I
37              
38             =item I
39              
40             =item I
41              
42             =item I
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             sub compose {
55 0     0 1   my ($class, $value) = @_;
56              
57 0 0         if (blessed $value) {
58 0 0         if (! $value->isa($class)) {
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             sub read {
70 0     0 1   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 0 0 0       last unless $meta->{idl}
76             && $meta->{idl}{type}->isa('Thrift::IDL::Type::Custom');
77 0           my $struct = $parser->idl->struct_named(
78             $meta->{idl}{type}->name
79             );
80 0 0         last unless $struct;
81 0           @sub_idl_fields = @{ $struct->fields };
  0            
82             }
83              
84             $self->value(
85 0           $parser->parse_structure($input, \@sub_idl_fields)
86             );
87 0           return $self;
88             }
89              
90             sub write {
91 0     0 1   my ($self, $output) = @_;
92             # FieldSet->write() encompasses all needed behavior
93 0           $self->value->write($output);
94             }
95              
96             sub value_plain {
97 0     0 1   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
110              
111             =cut
112              
113             1;