line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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. See the docs there for all the usage details. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
192
|
|
14
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
154
|
|
15
|
6
|
|
|
6
|
|
32
|
use Scalar::Util qw(blessed); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
369
|
|
16
|
6
|
|
|
6
|
|
33
|
use base qw(Thrift::Parser::Type::Container); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2899
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 USAGE |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub read { |
23
|
0
|
|
|
0
|
1
|
0
|
my ($self, $parser, $input, $meta) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
$input->readSetBegin(\$meta->{val_type}, \$meta->{size}); |
26
|
0
|
|
|
|
|
0
|
my %val_meta = ( type => $meta->{val_type} ); |
27
|
0
|
0
|
|
|
|
0
|
$val_meta{idl}{type} = $parser->resolve_idl_type( $meta->{idl}{type} )->val_type if $meta->{idl}; |
28
|
0
|
|
|
|
|
0
|
my @list; |
29
|
0
|
|
|
|
|
0
|
for (my $i = 0; $i < $meta->{size}; $i++) { |
30
|
0
|
|
|
|
|
0
|
my $val = $parser->parse_type($input, { %val_meta }); |
31
|
0
|
|
|
|
|
0
|
push @list, $val; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
0
|
$input->readSetEnd(); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
$self->value(\@list); |
36
|
0
|
|
|
|
|
0
|
$self->val_type($meta->{val_type}); |
37
|
0
|
|
|
|
|
0
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub write { |
41
|
0
|
|
|
0
|
1
|
0
|
my ($self, $output) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
my @list = @{ $self->value }; |
|
0
|
|
|
|
|
0
|
|
44
|
0
|
|
|
|
|
0
|
$output->writeSetBegin($self->val_type, int @list); |
45
|
0
|
|
|
|
|
0
|
$_->write($output) foreach @list; |
46
|
0
|
|
|
|
|
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'ed into the class. Returns boolean value if the value is present in this set. Throws L. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub is_set { |
58
|
4
|
|
|
4
|
1
|
60
|
my ($self, $test) = @_; |
59
|
|
|
|
|
|
|
|
60
|
4
|
50
|
|
|
|
15
|
if (! blessed $test) { |
|
|
0
|
|
|
|
|
|
61
|
4
|
|
|
|
|
19
|
$test = $self->{val_type_class}->compose($test); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif (! $test->isa( $self->{val_type_class} )) { |
64
|
0
|
|
|
|
|
0
|
Thrift::Parser::InvalidArgument->throw("is_set() must be called with a $$self{val_type_class} object"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
31
|
foreach my $value (@{ $self->value }) { |
|
3
|
|
|
|
|
9
|
|
68
|
10
|
100
|
|
|
|
64
|
if ($value->equal_to($test)) { |
69
|
2
|
|
|
|
|
31
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
1
|
|
|
|
|
5
|
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 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |