line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Thrift::IDL::Base; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Thrift::IDL::Base |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Base class for most L subclasses. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
40
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
216
|
|
14
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
206
|
|
15
|
6
|
|
|
6
|
|
35
|
use base qw(Class::Accessor); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
4965
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(parent comments)); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 parent |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 comments |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Accessors |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use overload |
29
|
6
|
|
|
|
|
78
|
'""' => \&_overload_string, |
30
|
6
|
|
|
6
|
|
17139
|
'eq' => \&_overload_string; |
|
6
|
|
|
|
|
20
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _overload_string { |
33
|
217
|
|
|
217
|
|
65341
|
my $self = shift; |
34
|
217
|
100
|
|
|
|
4673
|
return $self->can('to_str') ? $self->to_str : ref($self); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 children_of_type ($type) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $comments = $obj->children_of_type('Thrift::IDL::Comment'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Returns an array ref of all child objects of the given class |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub children_of_type { |
46
|
55
|
|
|
55
|
1
|
9603
|
my ($self, $type) = @_; |
47
|
|
|
|
|
|
|
|
48
|
55
|
|
|
|
|
120
|
my $cache_key = 'children.' . $type; |
49
|
55
|
100
|
|
|
|
253
|
return $self->{$cache_key} if $self->{$cache_key}; |
50
|
|
|
|
|
|
|
|
51
|
30
|
|
|
|
|
94
|
$self->{$cache_key} = []; |
52
|
30
|
|
|
|
|
710
|
foreach my $child (@{ $self->{children} }) { |
|
30
|
|
|
|
|
100
|
|
53
|
145
|
100
|
|
|
|
1689
|
push @{ $self->{$cache_key} }, $child if $child->isa($type); |
|
47
|
|
|
|
|
154
|
|
54
|
|
|
|
|
|
|
} |
55
|
30
|
|
|
|
|
185
|
return $self->{$cache_key}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 array_search ($value, $array_method, $method) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $Calculator_service = $document->array_search('Calculator', 'services', 'name'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Given a method $array_method which returns an array of objects on $self, return the object which has $value = $object->$method |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub array_search { |
67
|
39
|
|
|
39
|
1
|
1632
|
my ($self, $value, $array_method, $method) = @_; |
68
|
|
|
|
|
|
|
|
69
|
39
|
|
|
|
|
2922
|
my $cache_key = join '.', 'array_idx', $array_method, $method; |
70
|
39
|
100
|
|
|
|
163
|
if (! $self->{$cache_key}) { |
71
|
61
|
|
|
|
|
744
|
$self->{$cache_key} = { |
72
|
21
|
|
|
|
|
93
|
map { $_->$method => $_ } |
73
|
21
|
|
|
|
|
39
|
@{ $self->$array_method } |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
39
|
|
|
|
|
901
|
return $self->{$cache_key}{$value}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 setup |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
A struct has children of type L and L. Walk through all these children and associate the comments with the fields that preceeded them (if perl style) or with the field following. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _setup { |
86
|
31
|
|
|
31
|
|
134
|
my ($self, $key) = @_; |
87
|
31
|
100
|
|
|
|
3138
|
return if $self->{"_setup_called_$key"}++; |
88
|
|
|
|
|
|
|
|
89
|
30
|
|
|
|
|
60
|
my (@fields, @comments, $last_field); |
90
|
30
|
|
|
|
|
57
|
foreach my $child (@{ $self->$key }) { |
|
30
|
|
|
|
|
257
|
|
91
|
51
|
100
|
|
|
|
701
|
if ($child->isa('Thrift::IDL::Field')) { |
|
|
50
|
|
|
|
|
|
92
|
47
|
|
|
|
|
136
|
$child->{comments} = [ @comments ]; |
93
|
47
|
|
|
|
|
125
|
push @fields, $child; |
94
|
47
|
|
|
|
|
70
|
$last_field = $child; |
95
|
47
|
|
|
|
|
115
|
@comments = (); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ($child->isa('Thrift::IDL::Comment')) { |
98
|
|
|
|
|
|
|
# Perl-style comments are postfix to the previous element |
99
|
4
|
100
|
|
|
|
15
|
if ($child->style eq 'perl_single') { |
100
|
1
|
|
|
|
|
2
|
push @{ $last_field->{comments} }, $child; |
|
1
|
|
|
|
|
6
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
3
|
|
|
|
|
7
|
push @comments, $child; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
0
|
die "Unrecognized child of ".ref($self)." (".ref($child)."\n"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
30
|
|
|
|
|
335
|
$self->$key(\@fields); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |