PML/Schema/Decl.pm

filter: Statementstmt 52.5% 104 / 198 Branchbran 43.4% 46 / 106 Conditioncond 31.0% 9 / 29 MC/DCmcdc 18.7% 3 / 16 Subroutinesub 54.5% 18 / 33 Podpod 91.6% 22 / 24 totaltotal 49.7% 202 / 406 CC 67 SCAR 41.7
CC
67
Cov
48%
get_normal_fields
182.0
convert_from_hash
123.8
get_childnodes_decls
56.0
CRAP 65.0
« PML/Schema/Import.pm ↑ Summary PML/Schema/CDATA.pm »
1 package Treex::PML::Schema::Decl;
2  
3 ########################################################################
4 # PML Schema type declaration
5 ########################################################################
6  
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 $VERSION='2.29'; # version template
13 }
14 9 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use Treex::PML::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use base qw(Treex::PML::Schema::XMLNode);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 =head1 NAME
21  
22 Treex::PML::Schema::Decl - implements PML schema type declaration
23  
24 =head1 DESCRIPTION
25  
26 This is an abstract class from which all specific type declaration
27 classes inherit.
28  
29 =head1 INHERITANCE
30  
31 This class inherits from L<Treex::PML::Schema::XMLNode>.
32  
33 =head1 METHODS
34  
35 =over 3
36  
37 =cut
38  
39 0 ▶sub new { croak("Can't create ".__PACKAGE__) }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 # compatibility with old Treex::PML::Type
42  
43 0 ▶sub type_decl { return $_[0] };
Subroutine type_decl: not called CC=1 SCAR=6.9
Pod undocumented
44  
45 =item $decl->get_schema ()
46  
47 =item $decl->schema ()
48  
49 Return C<Treex::PML::Schema> the declaration belongs to.
50  
51 =cut
52  
53 0 ▶sub schema { return $_[0]->{-schema} }
Subroutine schema: not called CC=1 SCAR=6.9
Pod documented
54  
55 =item $decl->get_schema ()
56  
57 Same as C<< $decl->schema() >>.
58  
59 =cut
60  
61 0 ▶sub get_schema { return $_[0]->schema }
Subroutine get_schema: not called CC=1 SCAR=6.9
Pod documented
62  
63 =item $decl->get_decl_type ()
64  
65 Return the type of declaration as an integer constant (see
66 L<Treex::PML::Schema/"CONSTANTS">).
67  
68 =item $decl->get_decl_type_str ()
69  
70 Return the type of declaration as string; one of: type, root,
71 structure, container, sequence, list, alt, cdata, choice, constant,
72 attribute, member, element.
73  
74 =cut
75  
76 0 ▶sub get_decl_type { return(undef); } # VIRTUAL
Subroutine get_decl_type: not called CC=1 SCAR=6.9
Pod documented
77 0 ▶sub get_decl_type_str { return(undef); } # VIRTUAL
Subroutine get_decl_type_str: not called CC=1 SCAR=6.9
Pod documented
78  
79 =item $decl->is_atomic ()
80  
81 Return 1 if the declaration is of atomic type (cdata, choice,
82 constant), 0 if it is a structured type (structure, container,
83 sequence, list, alt), or undef, if it is an auxiliary declaration
84 (root, type, attribute, member, element).
85  
86 =cut
87  
88 0 ▶sub is_atomic { croak "is_atomic(): UNKNOWN TYPE"; } # VIRTUAL
Subroutine is_atomic: not called CC=1 SCAR=6.9
Pod documented
89  
90 =item $decl->get_content_decl ()
91  
92 For declarations with content (type, root, container, list, alt,
93 attribute, member, element), return the content declaration; return
94 undef for other declarations. This method transparently resolves
95 references to named types.
96  
97 =cut
98  
99 3077 ▶sub get_content_decl {
Subroutine get_content_decl: called CC=7 SCAR=21.1
Pod documented
100 3077 my $self = shift;
101 3077 my $no_resolve = shift;
102 3077 ▶ if ($self->{-decl}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'-decl'}) { } 1907 1170 3077
elsif (my $resolved = $self->{'-resolved'}) { } 872 298 1170
elsif (my $type_ref = $self->{'type'}) { } 298 0 298
103 1907 return $self->{ $self->{-decl} };
104 } elsif (my $resolved = $self->{-resolved}) {
105 872 return $resolved;
106 } elsif (my $type_ref = $self->{type}) {
107 298 my $schema = $self->{-schema};
108 298 ▶ if ($schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema) { } 298 0 298
109 298 my $type = $schema->{type}{ $type_ref };
110 298 ▶ if ($no_resolve) {
Branch: 2 branches
BranchTrueFalseTotal
if ($no_resolve) { } 0 298 298
elsif ($type) { } 298 0 298
111 0 return $type;
112 } elsif ($type) {
113 298 weaken($self->{-resolved} = $type->get_content_decl);
114 298 return $self->{-resolved};
115 } else {
116 0 return undef;
117 }
118 } else {
119 0 croak "Declaration not associated with a schema";
120 }
121 }
122 0 return(undef);
123 }
124  
125 =item $decl->get_knit_content_decl ()
126  
127 If the data type has a role '#KNIT', return a type declaration for the
128 knitted content (Note: PML 1.1.2 allows role '#KNIT' role on list,
129 element, and member declarations, but element knitting is not
130 currenlty implemented). Otherwise return the same as get_content_decl.
131  
132 =cut
133  
134  
135 276 ▶sub get_knit_content_decl {
Subroutine get_knit_content_decl: called CC=3 SCAR=11.0
Pod documented
136 276 my $self = shift;
137 276 ▶ return (defined($self->{role}) and $self->{role} eq '#KNIT') ?
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'role'} && $self->{'role'} eq '#KNIT' ? : 17 259 276
Condition100%3/3
defined $self->{"role"} and $self->{"role"} eq "#KNIT"
!ll&&!rl&&r
13312617
MC/DC100%2/2
defined $self->{"role"} and $self->{"role"} eq "#KNIT"
defined $self->{"role"} $self->{"role"} eq "#KNIT"
Truth table100%3/3
A and B
A= defined $self->{"role"}B= $self->{"role"} eq "#KNIT"
ABresult
0X0
100
111
138 $self->get_type_ref_decl
139 : $self->get_content_decl;
140 }
141  
142 =item $decl->get_type_ref ()
143  
144 If the declaration has content and the content is specified via a
145 reference to a named type, return the name of the referred type.
146 Otherwise return undef.
147  
148 =cut
149  
150 1826 ▶sub get_type_ref {
Subroutine get_type_ref: called CC=1 SCAR=0.0
Pod documented
151 1826 return $_[0]->{type};
152 }
153  
154 =item $decl->get_type_ref_decl ()
155  
156 Retrun content declaration object (if any), but only if it is
157 specified via a reference to a named type. In all other cases, return
158 undef.
159  
160 =cut
161  
162 17 ▶sub get_type_ref_decl {
Subroutine get_type_ref_decl: called CC=6 SCAR=19.0
Pod documented
163 17 my $self = shift;
164 17 my $no_resolve = shift;
165 17 ▶ if (my $resolved = $self->{-resolved}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $resolved = $self->{'-resolved'}) { } 7 10 17
elsif (my $type_ref = $self->{'type'}) { } 10 0 10
166 7 return $resolved;
167 } elsif (my $type_ref = $self->{type}) {
168 10 my $schema = $self->{-schema};
169 10 ▶ if ($schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema) 10 0 10
170 10 my $type = $schema->{type}{ $type_ref };
171 return $no_resolve ? $type
172 : $type ?
173 10 ▶ ($self->{-resolved} = $type->get_content_decl)
Branch: 2 branches
BranchTrueFalseTotal
$no_resolve ? : 0 10 10
$type ? : 10 0 10
174 : undef ;
175 }
176 }
177 0 return(undef);
178 }
179  
180 =item $decl->get_base_type_name ()
181  
182 If the declaration is a nested (even deeply) part of a named type
183 declaration, return the name of that named type.
184  
185 =cut
186  
187 0 ▶sub get_base_type_name {
Subroutine get_base_type_name: not called CC=2 SCAR=17.9
Pod documented
188 0 my $path = $_[0]->{-path};
189 0 ▶ if ($path=~m{^!([^/]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^!([^/]+)]) { } 0 0 0
190 0 return $1;
191 } else {
192 0 return(undef);
193 }
194 }
195  
196 =item $decl->get_parent_decl ()
197  
198 If this declaration is nested, return its parent declaration.
199  
200 =cut
201  
202 667 ▶sub get_parent_decl { return $_[0]->{-parent} }
Subroutine get_parent_decl: called CC=1 SCAR=0.0
Pod documented
203  
204 =item $decl->get_decl_path ()
205  
206 Return a cannonical attribute path leading to the declaration
207 (starting either at a named type or the root type declaration).
208  
209 =cut
210  
211 2961 ▶sub get_decl_path { return $_[0]->{-path}; }
Subroutine get_decl_path: called CC=1 SCAR=0.0
Pod documented
212  
213 =item $decl->get_role
214  
215 If the declaration is associated with a role, return it.
216  
217 =cut
218  
219 1389 ▶sub get_role { return $_[0]->{role}||'' }
Subroutine get_role: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]{'role'} || ''
l!l
2341155
MC/DC100%1/1
$_[0]{'role'} || ''
$_[0]{'role'}
Truth table100%2/2
A
A= $_[0]{'role'}
Aresult
11
00
220  
221  
222 =item $decl->find (attribute-path,noresolve)
223  
224 Locate a nested declaration specified by C<attribute-path> starting
225 from the current type. See C<$schema-E<gt>find_type_by_path> for details
226 about locating declarations.
227  
228 =cut
229  
230 0 ▶sub find {
Subroutine find: not called CC=1 SCAR=6.9
Pod documented
231 0 my ($self, $path,$noresolve) = @_;
232 # find node type
233 0 my $type = $self->type_decl;
234 0 return $self->schema->find_type_by_path($path,$noresolve,$type);
235 }
236  
237 =item $decl->find_role (role, opts)
238  
239 Search declarations with a given role nested within this declaration.
240 In scalar context, return the first declaration that matches, in array
241 context return all such declarations.
242  
243 The last argument C<opts> can be used to pass some flags to the
244 algorithm. Currently only the flag C<no_children> is available. If
245 true, then the function never recurses into content declaration of
246 declarations with the role #CHILDNODES.
247  
248 =cut
249  
250 0 ▶sub find_role {
Subroutine find_role: not called CC=1 SCAR=6.9
Pod documented
251 0 my ($self, $role, $opts) = @_;
252 0 return $self->schema->find_role($role,$self->type_decl,$opts);
253 }
254  
255 =item $decl->convert_from_hash (class, hash, schema, path)
256  
257 Compatibility method building the schema object from a nested hash
258 structure created by XML::Simple which was used in older
259 implementations. This is useful for upgrading objects stored in old
260 binary dumps. Not to be used directly.
261  
262 =cut
263  
264 212 ▶sub convert_from_hash {
Subroutine convert_from_hash: called CC=28 SCAR=48.2
Pod documented
265 212 my ($class, $decl, $schema, $path) = @_;
266 212 my $sub;
267 my $decl_type;
268 212 ▶ if ($sub = $decl->{structure}) {
Branch: 8 branches
BranchTrueFalseTotal
if ($sub = $decl->{'structure'}) { } 4 208 212
elsif ($sub = $decl->{'container'}) { } 0 208 208
elsif ($sub = $decl->{'sequence'}) { } 0 208 208
elsif ($sub = $decl->{'list'}) { } 4 204 208
elsif ($sub = $decl->{'alt'}) { } 100 104 204
elsif ($sub = $decl->{'choice'}) { } 2 102 104
elsif ($sub = $decl->{'cdata'}) { } 98 4 102
elsif (exists $decl->{'constant'}) { } 0 4 4
269 4 $decl_type = 'structure';
270 4 bless $sub, 'Treex::PML::Schema::Struct';
271 4 $sub->{'-attributes'}=[qw(role name type)];
272 4 ▶ if (my $members = $sub->{member}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $members = $sub->{"member"}) 4 0 4
273 4 my ($name, $mdecl);
274 4 ▶ while (($name, $mdecl) = each %$members) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$members) 104 4 108
275 104 bless $mdecl, 'Treex::PML::Schema::Member';
276 104 $mdecl->{'-xml_name'}='member';
277 104 $mdecl->{'-attributes'}=[qw(name required as_attribute type role)];
278 104 weaken($mdecl->{-parent}=$sub);
279 104 weaken($mdecl->{-schema}=$schema);
280 104 $class->convert_from_hash($mdecl,
281 $schema,
282 $path.'/'.$name
283 );
284 104 ▶ if (!$mdecl->{-decl} and $mdecl->{role} eq '#KNIT') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $mdecl->{"-decl"} and $mdecl->{"role"} eq "#KNIT") 0 104 104
Condition33%1/3
not $mdecl->{"-decl"} and $mdecl->{"role"} eq "#KNIT"
!ll&&!rl&&r
10400
MC/DC0%0/2
not $mdecl->{"-decl"} and $mdecl->{"role"} eq "#KNIT"
not $mdecl->{"-decl"} $mdecl->{"role"} eq "#KNIT"
Truth table33%1/3
not(A) and B
A= not $mdecl->{"-decl"}B= $mdecl->{"role"} eq "#KNIT"
ABresult
0X0
100
111
285 # warn("Member $decl->{-parent}{-path}/$decl->{-name} with role=\"#KNIT\" must have a content type declaration: assuming <cdata format=\"PMLREF\">!\n");
286 0 Treex::PML::Schema::__fix_knit_type($schema,$mdecl);
287 }
288 }
289 }
290 } elsif ($sub = $decl->{container}) {
291 0 $decl_type = 'container';
292 0 bless $sub, 'Treex::PML::Schema::Container';
293 0 $sub->{'-attributes'}=[qw(role name type)];
294 0 ▶ if (my $members = $sub->{attribute}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $members = $sub->{"attribute"}) 0 0 0
295 0 my ($name, $mdecl);
296 0 ▶ while (($name, $mdecl) = each %$members) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$members) 0 0 0
297 0 bless $mdecl, 'Treex::PML::Schema::Attribute';
298 0 $mdecl->{'-xml_name'}='attribute';
299 0 $mdecl->{'-attributes'}=[qw(name required type role)];
300 0 weaken($mdecl->{-schema}=$schema);
301 0 weaken($mdecl->{-parent}=$sub);
302 0 $class->convert_from_hash($mdecl,
303 $schema,
304 $path.'/'.$name
305 );
306 }
307 }
308 0 $class->convert_from_hash($sub, $schema, $path.'/#content');
309 } elsif ($sub = $decl->{sequence}) {
310 0 $decl_type = 'sequence';
311 0 bless $sub, 'Treex::PML::Schema::Seq';
312 0 $sub->{'-attributes'}=[qw(role content_pattern type)];
313 0 ▶ if (my $members = $sub->{element}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $members = $sub->{"element"}) 0 0 0
314 0 my ($name, $mdecl);
315 0 ▶ while (($name, $mdecl) = each %$members) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$members) 0 0 0
316 0 bless $mdecl, 'Treex::PML::Schema::Element';
317 0 $mdecl->{'-xml_name'}='element';
318 0 $mdecl->{'-attributes'}=[qw(name type role)];
319 0 weaken($mdecl->{-schema}=$schema);
320 0 weaken($mdecl->{-parent}=$sub);
321 0 $class->convert_from_hash($mdecl,
322 $schema,
323 $path.'/'.$name
324 );
325 }
326 }
327 } elsif ($sub = $decl->{list}) {
328 4 $decl_type = 'list';
329 4 bless $sub, 'Treex::PML::Schema::List';
330 4 $sub->{'-attributes'}=[qw(role ordered type)];
331 4 $class->convert_from_hash($sub, $schema, $path.'/LM');
332 4 ▶ if (!$sub->{-decl} and $sub->{role} eq '#KNIT') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sub->{"-decl"} and $sub->{"role"} eq "#KNIT") 0 4 4
Condition33%1/3
not $sub->{"-decl"} and $sub->{"role"} eq "#KNIT"
!ll&&!rl&&r
040
MC/DC0%0/2
not $sub->{"-decl"} and $sub->{"role"} eq "#KNIT"
not $sub->{"-decl"} $sub->{"role"} eq "#KNIT"
Truth table33%1/3
not(A) and B
A= not $sub->{"-decl"}B= $sub->{"role"} eq "#KNIT"
ABresult
0X0
100
111
333 # warn("List $sub->{-name} with role=\"#KNIT\" must have a content type declaration: assuming <cdata format=\"PMLREF\">!\n");
334 0 Treex::PML::Schema::__fix_knit_type($schema,$sub,$path.'/LM');
335 }
336 } elsif ($sub = $decl->{alt}) {
337 100 $decl_type = 'alt';
338 100 bless $sub, 'Treex::PML::Schema::Alt';
339 100 $sub->{'-attributes'}=[qw(role type)];
340 100 $class->convert_from_hash($sub, $schema, $path.'/AM');
341 } elsif ($sub = $decl->{choice}) {
342 2 $decl_type = 'choice';
343 # convert from an ARRAY to a hash
344 2 ▶ if (ref($sub) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub eq 'ARRAY') { } 2 0 2
elsif (ref $sub) { } 0 0 0
345 $sub = $decl->{choice} = bless { values => [
346 map {
347 2 ▶ ref($_) eq 'HASH' ? $_->{content} : $_
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'HASH' ? : 0 226 226
348 } @$sub
349 ],
350 }, 'Treex::PML::Schema::Choice';
351 } elsif (ref($sub)) {
352 0 bless $sub, 'Treex::PML::Schema::Choice';
353 0 ▶ if (ref($sub->{value}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sub->{"value"} eq "ARRAY") 0 0 0
354 $sub->{values} = [
355 0 map { $_->{content} } @{$sub->{value}}
356 ];
357 0 delete $sub->{value};
358 }
359 } else {
360 0 croak __PACKAGE__.": Invalid <choice> element in type '$path'?\n";
361 }
362 } elsif ($sub = $decl->{cdata}) {
363 98 $decl_type = 'cdata';
364 98 bless $sub, 'Treex::PML::Schema::CDATA';
365 98 $sub->{'-attributes'}=['format'];
366 } elsif (exists $decl->{constant}) { # can be 0
367 0 $sub = $decl->{constant};
368 0 $decl_type = 'constant';
369 0 ▶ unless (ref($sub)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sub) 0 0 0
370 0 $sub = $decl->{constant} = bless { value => $sub }, 'Treex::PML::Schema::Constant';
371 }
372 ## this is just a scalar value
373 # bless $sub, 'Treex::PML::Schema::Constant';
374 }
375 212 $sub->{'-xml_name'}=$decl_type;
376 212 weaken( $decl->{-schema} = $schema );
377 212 $decl->{-decl} = $decl_type;
378 212 ▶ unless (exists($sub->{-schema}) and exists($sub->{-parent})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sub->{"-schema"} and exists $sub->{"-parent"}) 212 0 212
Condition66%2/3
exists $sub->{"-schema"} and exists $sub->{"-parent"}
!ll&&!rl&&r
1081040
MC/DC0%0/2
exists $sub->{"-schema"} and exists $sub->{"-parent"}
exists $sub->{"-schema"} exists $sub->{"-parent"}
Truth table66%2/3
A and B
A= exists $sub->{"-schema"}B= exists $sub->{"-parent"}
ABresult
0X0
100
111
379 212 ▶ weaken( $sub->{-schema} = $schema ) unless $sub->{-schema};
Branch: 1 branch
BranchTrueFalseTotal
unless $sub->{"-schema"} 108 104 212
380 212 ▶ weaken( $sub->{-parent} = $decl ) unless $sub->{-parent};
Branch: 1 branch
BranchTrueFalseTotal
unless $sub->{"-parent"} 212 0 212
381 212 $sub->{-path} = $path;
382 }
383 212 return $decl;
384 }
385  
386  
387 =item $decl->get_normal_fields ()
388  
389 This method is provided for convenience.
390  
391 For a structure type, return names of its members, for a container
392 return names of its attributes plus the name '#content' referring to
393 the container's content value. In both cases, eliminate fields of
394 values with role C<#CHILDNODES> and strip a possible C<.rf> suffix of
395 fields with role C<#KNIT>.
396  
397 =cut
398  
399 0 ▶sub get_normal_fields {
Subroutine get_normal_fields: not called CC=13 SCAR=52.0
Pod documented
400 0 my ($self,$path)=@_;
401 0 ▶ my $type = defined($path) ? $self->find($path) : $self;
Branch: 1 branch
BranchTrueFalseTotal
defined $path ? : 0 0 0
402 0 my $struct;
403 my $members;
404 0 ▶ return unless ref $type;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 0 0 0
405 0 my $decl_is = $type->get_decl_type;
406 0 ▶ if ($decl_is == PML_TYPE_DECL ||
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13) 0 0 0
Condition0%0/12
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13
l!l&&r!l&&!r
000
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12
l!l&&r!l&&!r
000
$decl_is == 1 or $decl_is == 2 or $decl_is == 11
l!l&&r!l&&!r
000
$decl_is == 1 or $decl_is == 2
l!l&&r!l&&!r
000
MC/DC0%0/5
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13
$decl_is == 1 $decl_is == 2 $decl_is == 11 $decl_is == 12 $decl_is == 13
Truth table0%0/6
A or B or C or D or E
A= $decl_is == 1B= $decl_is == 2C= $decl_is == 11D= $decl_is == 12E= $decl_is == 13
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
407 $decl_is == PML_ROOT_DECL ||
408 $decl_is == PML_ATTRIBUTE_DECL ||
409 $decl_is == PML_MEMBER_DECL ||
410 $decl_is == PML_ELEMENT_DECL ) {
411 0 ▶ if ($type = $type->get_content_decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type = $type->get_content_decl) { } 0 0 0
412 0 $decl_is = $type->get_decl_type;
413 } else {
414 0 return ();
415 }
416 }
417 0 my @members = ();
418 0 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 0 0 0
elsif ($decl_is == 4) { } 0 0 0
419 @members =
420 0 map { $_->get_knit_name }
421 0 grep { $_->get_role ne '#CHILDNODES' }
422 $type->get_members;
423 } elsif ($decl_is == PML_CONTAINER_DECL) {
424 0 my $cdecl = $type->get_content_decl;
425 0 ▶ @members = ($type->get_attribute_names,
Branch: 1 branch
BranchTrueFalseTotal
$cdecl && $type->get_role ne '#CHILDNODES' ? : 0 0 0
Condition0%0/3
$cdecl and $type->get_role ne "#CHILDNODES"
!ll&&!rl&&r
000
MC/DC0%0/2
$cdecl and $type->get_role ne "#CHILDNODES"
$cdecl $type->get_role ne "#CHILDNODES"
Truth table0%0/3
A and B
A= $cdeclB= $type->get_role ne "#CHILDNODES"
ABresult
0X0
100
111
426 ($cdecl && $type->get_role ne '#CHILDNODES') ? '#content' : ());
427 }
428 }
429  
430 =item $decl->get_childnodes_decls ()
431  
432 If the $decl has the role #NODE, this method locates a sub-declaration
433 with role #CHILDNODES and returns a list of declarations of the child
434 nodes.
435  
436 =cut
437  
438 0 ▶sub get_childnodes_decls {
Subroutine get_childnodes_decls: not called CC=7 SCAR=40.3
Pod documented
439 0 my ($self) = @_;
440 0 ▶ if ($self->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_decl_type == 13) 0 0 0
441 0 $self = $self->get_content_decl;
442 }
443 0 ▶ return unless $self->get_role eq '#NODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_role eq "#NODE" 0 0 0
444 0 my ($ch) = $self->find_members_by_role('#CHILDNODES');
445 0 ▶ if ($ch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch) 0 0 0
446 0 my $ch_is = $ch->get_decl_type;
447 0 ▶ if ($ch_is == PML_MEMBER_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch_is == 12) 0 0 0
448 0 $ch = $ch->get_content_decl;
449 0 $ch_is = $ch->get_decl_type;
450 }
451 0 ▶ if ($ch_is == PML_SEQUENCE_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ch_is == 5) { } 0 0 0
elsif ($ch_is == 6) { } 0 0 0
452 0 return $ch->get_elements;
453 } elsif ($ch_is == PML_LIST_DECL) {
454 0 return $ch->get_content_decl;
455 }
456 }
457 0 return;
458 }
459  
460  
461 =item $decl->get_attribute_paths (\%opts)
462  
463 Return attribute paths leading from this declaration to all (possibly
464 deeply) nested declarations of atomic type. This method is an alias for
465  
466 $decl->schema->get_paths_to_atoms([$decl],\%opts)
467  
468 See L<Treex::PML::Schema> for details.
469  
470 =cut
471  
472 0 ▶sub get_attribute_paths { # OLD NAME
Subroutine get_attribute_paths: not called CC=1 SCAR=6.9
Pod documented
473 0 my ($self,$opts)=@_;
474 0 return $self->get_paths_to_atoms($opts);
475 }
476  
477 =item $decl->get_paths_to_atoms (\%opts)
478  
479 Same as
480  
481 $decl->schema->get_paths_to_atoms([$decl],\%opts)
482  
483 See L<Treex::PML::Schema> for details.
484  
485 =cut
486  
487 0 ▶sub get_paths_to_atoms {
Subroutine get_paths_to_atoms: not called CC=1 SCAR=6.9
Pod documented
488 0 my ($self,$opts)=@_;
489 0 return $self->schema->get_paths_to_atoms([$self],$opts);
490 }
491  
492 =item $decl->validate_object($object);
493  
494 See C<validate_object()> method of L<Treex::PML::Schema>.
495  
496 =cut
497  
498 0 ▶sub validate_object {
Subroutine validate_object: not called CC=1 SCAR=6.9
Pod documented
499 0 croak "Not implemented for the class ".__PACKAGE__;
500 }
501  
502 =item $decl->for_each_decl (sub{ ... })
503  
504 This method traverses all nested sub-declarations and calls a given
505 subroutine passing the sub-declaration object as a parameter.
506  
507 =cut
508  
509 6013 ▶sub for_each_decl {
Subroutine for_each_decl: called CC=7 SCAR=19.5
Pod documented
510 6013 my ($self,$sub)=@_;
511 6013 $sub->($self);
512 # (a container or #KNIT member can have both type and children)
513 # traverse descendant type declarations
514 6013 for my $d (qw(member attribute element)) {
515 16894 ▶ if (ref $self->{$d}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$d}) 872 16022 16894
516 872 foreach (values %{$self->{$d}}) {
517 2225 $_->for_each_decl($sub);
518 }
519 872 ▶ last if $d eq 'attribute'; # there may be content
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "attribute" 181 691 872
520 691 return; # otherwise
521 }
522 }
523 5322 for my $d (qw(list alt structure container sequence),
524 qw(cdata choice constant)) {
525 34038 ▶ if (exists $self->{$d}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$d}) 2642 31396 34038
526 2642 $self->{$d}->for_each_decl($sub);
527 2642 return;
528 }
529 }
530 }
531  
532 =item $decl->write ({option => value})
533  
534 This method serializes a declaration to XML. See Treex::PML::Schema->write for
535 details and Treex::PML::Schema::XMLNode->write for implementation.
536  
537 =cut
538  
539  
540 =back
541  
542 =cut
543  
544  
545 9 1;
546 __END__
« PML/Schema/Import.pm ↑ Summary PML/Schema/CDATA.pm »