PML/Schema.pm

filter: Statementstmt 66.2% 348 / 525 Branchbran 47.8% 133 / 278 Conditioncond 46.3% 128 / 276 MC/DCmcdc 23.6% 36 / 152 Subroutinesub 74.7% 62 / 83 Podpod 91.1% 31 / 34 totaltotal 54.7% 738 / 1348 CC 248 SCAR 50.5
CC
248
Cov
56%
_get_paths_to_atoms
870.0
find_type_by_path
253.0
_find
204.1
CRAP 155.4
« PML/Backend/Storable.pm ↑ Summary PML/Backend/PML.pm »
1 # -*- cperl -*-
2 package Treex::PML::Schema;
3  
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Treex::PML::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Treex::PML::Resource::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 our $VERSION = '2.29'; # version template
17 9 require Exporter;
18 9 import Exporter qw(import);
19 9 our @EXPORT = (
20 @Treex::PML::Schema::Constants::EXPORT,
21 qw(PML_VERSION_SUPPORTED),
22 );
23 9 our %EXPORT_TAGS = (
24 'constants' => [ @EXPORT ],
25 );
26 } # BEGIN
27  
28 9 ▶use constant PML_VERSION_SUPPORTED => "1.2";
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 9 ▶use Treex::PML::Schema::XMLNode;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 9 ▶use Treex::PML::Schema::Decl;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use Treex::PML::Schema::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use Treex::PML::Schema::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use Treex::PML::Schema::Derive;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 9 ▶use Treex::PML::Schema::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 9 ▶use Treex::PML::Schema::Import;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 ▶use Treex::PML::Schema::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 9 ▶use Treex::PML::Schema::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use Treex::PML::Schema::Container;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use Treex::PML::Schema::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶use Treex::PML::Schema::List;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 ▶use Treex::PML::Schema::Alt;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 9 ▶use Treex::PML::Schema::Choice;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 9 ▶use Treex::PML::Schema::CDATA;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 9 ▶use Treex::PML::Schema::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 9 ▶use Treex::PML::Schema::Member;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 9 ▶use Treex::PML::Schema::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 9 ▶use Treex::PML::Schema::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 9 ▶use Treex::PML::Schema::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 9 ▶use Treex::PML::IO;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 9 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 9 ▶use base qw(Treex::PML::Schema::Template);
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 9 ▶use Scalar::Util qw(weaken isweak);
Subroutine BEGIN: called CC=1 SCAR=0.0
56 9 require Treex::PML;
57  
58 =head1 NAME
59  
60 Treex::PML::Schema - Perl implements a PML schema.
61  
62 =head2 DESCRIPTION
63  
64 This class implements PML schemas. PML schema consists of a set of
65 type declarations of several kinds, represented by objects inheriting
66 from a common base class C<Treex::PML::Schema::Decl>.
67  
68 =head2 INHERITANCE
69  
70 This class inherits from L<Treex::PML::Schema::Template>.
71  
72 =head3 Attribute Paths
73  
74 Some methods use so called 'attribute paths' to navigate through
75 nested and referenced type declarations. An attribute path is a
76 '/'-separated sequence of steps, where step can be one of the
77 following:
78  
79 =over 3
80  
81 =item C<!>I<type-name>
82  
83 '!' followed by name of a named type (this step can only occur
84 as the very first step
85  
86 =item I<name>
87  
88 name (of a member of a structure, element of a sequence or attribute
89 of a container), specifying the type declaration of the specified
90 named component
91  
92 =item C<#content>
93  
94 the string '#content', specifying the content type declaration
95 of a container
96  
97 =item C<LM>
98  
99 specifying the type declaration of a list
100  
101 =item C<AM>
102  
103 specifying the type declaration of an alt
104  
105 =item C<[>I<NNN>C<]>
106  
107 where I<NNN> is a decimal number (ignored) are an equivalent of LM or AM
108  
109 =back
110  
111 Steps of the form LM, AM, and [NNN] (except when occuring at the end
112 of an attribute path) may be omitted.
113  
114 =head2 EXPORT
115  
116 This module exports constants for declaration types.
117  
118 =head2 EXPORT TAGS
119  
120 =over 3
121  
122 =item :constants
123  
124 Export constant symbols (exported by default, too).
125  
126 =back
127  
128 =head2 CONSTANTS
129  
130 See Treex::PML::Schema::Constants.
131  
132 =cut
133  
134 =head1 METHODS
135  
136 =over 3
137  
138 =item Treex::PML::Schema->new ({ option => value, ... })
139  
140 NOTE: Don't call this constructor directly, use Treex::PML::Factory->createPMLSchema() instead!
141  
142 Parses an XML representation of a PML Schema
143 from a string, filehandle, local file, or URL,
144 processing the modular instructions as described in
145  
146 L<http://ufal.mff.cuni.cz/jazz/PML/doc/pml_doc.html#processing>
147  
148 and returns the corresponding C<Treex::PML::Schema> object.
149  
150 One of the following options must be given:
151  
152 =over 5
153  
154 =item C<string>
155  
156 a XML string to parse
157  
158 =item C<filename>
159  
160 a file name or URL
161  
162 =item C<fh>
163  
164 a file-handle (IO::File, IO::Pipe, etc.) open for reading
165  
166 =back
167  
168 The following options are optional:
169  
170 =over 5
171  
172 =item C<base_url>
173  
174 base URL for referred schemas (usefull when parsing from a file-handle or a string)
175  
176 =item C<use_resources>
177  
178 if this option is used with a true value, the parser will attempt to
179 locate referred schemas also in L<Treex::PML> resource paths.
180  
181 =item C<revision>, C<minimal_revision>, C<maximal_revision>
182  
183 constraints to the revision number of the schema.
184  
185 =item C<validate>
186  
187 if this option is used with a true value, the parser will validate the
188 schema on the fly using a RelaxNG grammar given using the
189 C<relaxng_schema> parameter; if C<relaxng_schema> is not given, the
190 file 'pml_schema_inline.rng' searched for in L<Treex::PML> resource paths
191 is assumed.
192  
193 =item C<relaxng_schema>
194  
195 a particular RelaxNG grammar to validate against. The value may be an
196 URL or filename for the grammar in the RelaxNG XML format, or a
197 XML::LibXML::RelaxNG object representation. The compact format is not
198 supported.
199  
200 =back
201  
202 =cut
203  
204 9 ▶BEGIN{
Subroutine BEGIN: called CC=1 SCAR=0.0
205 my %parse_opts = (
206 KeyAttr => {
207 "member" => "name",
208 "attribute" => "name",
209 "element" => "name",
210 "type" => "name",
211 "template" => "name",
212 "derive" => "name",
213 "let" => "param",
214 "param" => "name",
215 },
216 TextOnly => {
217 description => 'content',
218 revision => 'content',
219 value => 'content',
220 delete => 'content',
221 constant => 'value',
222 },
223 Stringify => {
224 description => 'content',
225 revision => 'content',
226 value => 'content',
227 delete => 'content',
228 },
229 Solitary => {
230 9 map { $_ => 1 }
231 qw(description revision root cdata structure container sequence constant list alt choice)
232 },
233 Bless => {
234 member => 'Treex::PML::Schema::Member',
235 attribute => 'Treex::PML::Schema::Attribute',
236 element => 'Treex::PML::Schema::Element',
237 type => 'Treex::PML::Schema::Type',
238 root => 'Treex::PML::Schema::Root',
239 structure => 'Treex::PML::Schema::Struct',
240 container => 'Treex::PML::Schema::Container',
241 sequence => 'Treex::PML::Schema::Seq',
242 list => 'Treex::PML::Schema::List',
243 alt => 'Treex::PML::Schema::Alt',
244 cdata => 'Treex::PML::Schema::CDATA',
245 constant => 'Treex::PML::Schema::Constant',
246 choice => 'Treex::PML::Schema::Choice',
247 template => 'Treex::PML::Schema::Template',
248 copy => 'Treex::PML::Schema::Copy',
249 import => 'Treex::PML::Schema::Import',
250 derive => 'Treex::PML::Schema::Derive',
251 '*' => 'Treex::PML::Schema::XMLNode',
252 },
253 DefaultNs => PML_SCHEMA_NS,
254 );
255  
256 67 ▶sub new {
Subroutine new: called CC=16 SCAR=32.9
Pod documented
257 67 my ($class,$opts, $more_opts)=@_;
258 67 ▶ if (!ref $opts) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opts) 0 67 67
259 # compatibility with older API
260 0 ▶ $more_opts ||= {};
Condition0%0/2
$more_opts ||= {}
l!l
00
MC/DC0%0/1
$more_opts ||= {}
$more_opts
Truth table0%0/2
A
A= $more_opts
Aresult
11
00
261 0 $opts = { %$more_opts, string => $opts };
262 }
263  
264 67 my $file = $opts->{filename};
265  
266 67 my $base = $opts->{base_url};
267 67 ▶ if (defined $base and length $base) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $base and length $base) { } 16 51 67
elsif ($opts->{'use_resources'}) { } 28 23 51
Condition66%2/3
defined $base and length $base
!ll&&!rl&&r
51016
MC/DC50%1/2
defined $base and length $base
defined $base length $base
Truth table66%2/3
A and B
A= defined $baseB= length $base
ABresult
0X0
100
111
268 16 $file = Treex::PML::ResolvePath($base,$file,$opts->{use_resources});
269 } elsif ($opts->{use_resources}) {
270 28 $file = Treex::PML::FindInResources($file);
271 }
272 67 my $schema;
273 my $revision_opts = {
274 67 map { $_ => delete($opts->{$_}) }
275 qw(revision_error revision minimal_revision maximal_revision)
276 };
277 67 ▶ if (defined($file) and ref($schema = $opts->{schemas}{$file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and ref($schema = $opts->{"schemas"}{$file})) 0 67 67
Condition33%1/3
defined $file and ref($schema = $opts->{"schemas"}{$file})
!ll&&!rl&&r
0670
MC/DC0%0/2
defined $file and ref($schema = $opts->{"schemas"}{$file})
defined $file ref($schema = $opts->{"schemas"}{$file})
Truth table33%1/3
A and B
A= defined $fileB= ref($schema = $opts->{"schemas"}{$file})
ABresult
0X0
100
111
278 0 ▶ print STDERR "schema $file already hashed\n" if $Treex::PML::Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $Treex::PML::Debug 0 0 0
279 0 $schema->check_revision($revision_opts);
280 0 return $schema;
281 }
282 67 my $parse_opts = {%parse_opts,%$opts};
283 67 $parse_opts->{Bless}{pml_schema}=$class;
284 67 ▶ $parse_opts->{URL} = (ref $file && $file->isa('Treex::PML::Resource::URI')) ? $file->file : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file && $file->isa('Treex::PML::Resource::URI') ? : 10 57 67
Condition100%3/3
ref $file and $file->isa("Treex::PML::Resource::URI")
!ll&&!rl&&r
282910
MC/DC100%2/2
ref $file and $file->isa("Treex::PML::Resource::URI")
ref $file $file->isa("Treex::PML::Resource::URI")
Truth table100%3/3
A and B
A= ref $fileB= $file->isa("Treex::PML::Resource::URI")
ABresult
0X0
100
111
285  
286 67 my $pml_reader = Treex::PML::Schema::Reader->new($parse_opts);
287 67 my $reader = $pml_reader->reader;
288 67 my $version;
289 67 eval {
290 67 ▶ unless ( $reader->nextElement('pml_schema', PML_SCHEMA_NS)==1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($reader->nextElement("pml_schema", "http://ufal.mff.cuni.cz/pdt/pml/schema/") == 1) 0 67 67
291 0 die "Not a PML schema: $file!\n";
292 }
293 67 $version = $reader->getAttribute('version');
294 67 $reader->moveToElement;
295 67 $schema = $pml_reader->parse_element();
296 };
297 67 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 67 67
298 0 die "Treex::PML::Schema::Reader error while parsing: $file near line ".$reader->lineNumber."\n$@\n";
299 0 return;
300 }
301 67 ▶ if (defined $version and length $version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version and length $version) { } 67 0 67
Condition33%1/3
defined $version and length $version
!ll&&!rl&&r
0067
MC/DC0%0/2
defined $version and length $version
defined $version length $version
Truth table33%1/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
302 67 ▶ unless (cmp_revisions($version,PML_VERSION_SUPPORTED)<=0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (cmp_revisions($version, "1.2") <= 0) 0 67 67
303 0 die "Unsupported version of PML schema '$file': this module supports versions up to ".PML_VERSION_SUPPORTED."\n";
304 }
305 } else {
306 0 warn "WARNING: PML schema '$file' does not specify version! Assuming ".PML_VERSION_SUPPORTED."\n";
307 }
308 67 $schema->check_revision($revision_opts);
309 67 $schema->{-VERSION}=$Treex::PML::Schema::VERSION;
310 67 return $schema;
311 }
312 } # BEGIN
313  
314  
315 =item Treex::PML::Schema->readFrom (filename,opts)
316  
317 An obsolete alias for Treex::PML::Schema->new({%$opts, filename=>$filename}).
318  
319 =cut
320  
321 0 ▶sub readFrom {
Subroutine readFrom: not called CC=1 SCAR=6.9
Pod documented
322 0 my ($self,$file,$opts)=@_;
323 0 return $self->new({%$opts, filename=>$file});
324 }
325  
326 =item $schema->write ({option => value})
327  
328 This method serializes the Treex::PML::Schema object to XML. See Treex::PML::Schema::XMLNode->write for implementation.
329  
330 IMPORTANT: The resulting schema is simplified, that is all modular instructions
331 are processed and removed from it, see L<http://ufal.mff.cuni.cz/jazz/PML/doc/pml_doc.html#processing>
332  
333 One of the following options must be given:
334  
335 =over 5
336  
337 =item C<string>
338  
339 a scalar reference to which the XML is to be stored as a string
340  
341 =item C<filename>
342  
343 a file name
344  
345 =item C<fh>
346  
347 a file-handle (IO::File, IO::Pipe, etc.) open for writing
348  
349 =back
350  
351 One of the following options are optional:
352  
353 =over 5
354  
355 =item C<no_backups>
356  
357 if this option is used with a true value, the writer will not attempt
358 to create backup (tilda) files when overwriting an existing file.
359  
360 =item C<no_indent>
361  
362 if this option is used with a true value, the writer will not add
363 additional newlines and indentatin white-space to the result XML.
364  
365 =back
366  
367 =cut
368  
369 # for implementation see XMLNode.pm
370  
371  
372 =item $schema->get_url ()
373  
374 Return location of the PML schema file.
375  
376 =cut
377  
378 1 ▶sub get_url { return $_[0]->{URL}; }
Subroutine get_url: called CC=1 SCAR=0.0
Pod documented
379  
380 =item $schema->set_url ($URI)
381  
382 Set location of the PML schema file.
383  
384 =cut
385  
386 22 ▶sub set_url { return $_[0]->{URL} = Treex::PML::IO::make_URI($_[1]) }
Subroutine set_url: called CC=1 SCAR=0.0
Pod documented
387  
388  
389 =item $schema->get_pml_version ()
390  
391 Return PML version the schema conforms to.
392  
393 =cut
394  
395 0 ▶sub get_pml_version { return $_[0]->{version}; }
Subroutine get_pml_version: not called CC=1 SCAR=6.9
Pod documented
396  
397  
398 =item $schema->get_revision ()
399  
400 Return PML schema revision.
401  
402 =cut
403  
404 0 ▶sub get_revision { return $_[0]->{revision}; }
Subroutine get_revision: not called CC=1 SCAR=6.9
Pod documented
405  
406 =item $schema->get_description ()
407  
408 Return PML schema description.
409  
410 =cut
411  
412 0 ▶sub get_description { return $_[0]->{description}; }
Subroutine get_description: not called CC=1 SCAR=6.9
Pod documented
413  
414 =item $schema->get_root_decl ()
415  
416 Return the root type declaration (see C<Treex::PML::Schema::Root>).
417  
418 =cut
419  
420 151 ▶sub get_root_decl { return $_[0]->{root}; }
Subroutine get_root_decl: called CC=1 SCAR=0.0
Pod documented
421  
422 =item $schema->get_root_type ()
423  
424 Like $schema->get_root_decl->get_content_decl.
425  
426 =cut
427  
428 0 ▶sub get_root_type {
Subroutine get_root_type: not called CC=1 SCAR=6.9
Pod documented
429 0 my ($self,$name) = @_;
430 0 return $self->{root}->get_content_decl;
431 }
432 9 *get_root_type_obj = \&get_root_type;
433  
434  
435 0 ▶sub _internal_api_version { return $_[0]->{'-api_version'} }
Subroutine _internal_api_version: not called CC=1 SCAR=6.9
436  
437 =item $decl->get_decl_type ()
438  
439 Return the constant PML_SCHEMA_DECL (for compatibility with the Treex::PML::Schema::Decl interface).
440  
441 =item $decl->get_decl_type_str ()
442  
443 Return the string 'schema' (for compatibility with the Treex::PML::Schema::Decl interface).
444  
445 =cut
446  
447 198 ▶sub get_decl_type { return(PML_SCHEMA_DECL); }
Subroutine get_decl_type: called CC=1 SCAR=0.0
Pod documented
448 0 ▶sub get_decl_type_str { return('schema'); }
Subroutine get_decl_type_str: not called CC=1 SCAR=6.9
Pod documented
449  
450 =item $schema->get_root_name ()
451  
452 Return name of the root element for PML instance.
453  
454 =cut
455  
456 1 ▶sub get_root_name {
Subroutine get_root_name: called CC=2 SCAR=7.2
Pod documented
457 1 my $root = $_[0]->{root};
458 1 ▶ return $root ? $root->{name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$root ? : 1 0 1
459 }
460  
461 =item $schema->get_type_names ()
462  
463 Return names of all named type declarations.
464  
465 =cut
466  
467 0 ▶sub get_type_names {
Subroutine get_type_names: not called CC=2 SCAR=17.9
Pod documented
468 0 my $types = $_[0]->{type};
469 0 ▶ return $types ? keys(%$types) : ();
Branch: 1 branch
BranchTrueFalseTotal
$types ? : 0 0 0
470 }
471  
472 =item $schema->get_named_references ()
473  
474 This method returns a list of HASHrefs containing
475 information about a named references to PML instances
476 (each hash will currently have the keys 'name' and 'readas').
477  
478 =cut
479  
480 107 ▶sub get_named_references {
Subroutine get_named_references: called CC=2 SCAR=6.9
Pod documented
481 107 my ($self, $name) = @_;
482 107 ▶ if ($self->{reference}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"reference"}) 52 55 107
483 56 return map { my $r=$_; my $h = { map { ($_=>$r->{$_}) } @{$r->{'-attributes'}} }; $h }
484 52 @{$self->{reference}} ;
485 }
486 55 return;
487 }
488  
489 =item $schema->get_named_reference_info (name)
490  
491 This method retrieves information about a specific named instance
492 reference as a hash (currently with keys 'name' and 'readas').
493  
494 =cut
495  
496 0 ▶sub get_named_reference_info {
Subroutine get_named_reference_info: not called CC=3 SCAR=24.8
Pod documented
497 0 my ($self, $name) = @_;
498 0 ▶ if ($self->{reference}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"reference"}) 0 0 0
499 0 return { map { my $r=$_; map { $_=>$r->{$_} } @{$r->{'-attributes'}} }
500 0 ▶ grep { defined($_->{name}) and $_->{name} eq $name } @{$self->{reference}} };
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq $name
defined $_->{'name'} $_->{'name'} eq $name
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq $name
ABresult
0X0
100
111
501 }
502 0 return;
503 }
504  
505 =item Treex::PML::Schema::cmp_revisions($A, $B)
506  
507 This function compares two schema revision strings according to the
508 ruls described in the PML specification. Returns -1 if revision $A
509 precedes revision $B, 0 if the revisions are equal (equivalent), and 1
510 if revision $A follows revision $B.
511  
512 =cut
513  
514 # compare two revision numbers
515 78 ▶sub cmp_revisions {
Subroutine cmp_revisions: called CC=4 SCAR=13.9
Pod documented
516 78 my ($my_revision,$revision)=@_;
517 78 my @my_revision = split(/\./,$my_revision);
518 78 my @revision = split(/\./,$revision);
519 78 my $cmp=0;
520 78 ▶ while ($cmp==0 and (@my_revision or @revision)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp == 0 and @my_revision || @revision) 158 78 236
Condition83%5/6
$cmp == 0 and @my_revision || @revision
!ll&&!rl&&r
708158
@my_revision or @revision
l!l&&r!l&&!r
15808
MC/DC66%2/3
$cmp == 0 and @my_revision || @revision
$cmp == 0 @my_revision @revision
Truth table75%3/4
A and B or C
A= $cmp == 0B= @my_revisionC= @revision
ABCresult
0XX0
1000
11X1
1011
521 158 $cmp = (shift(@my_revision) <=> shift(@revision));
522 }
523 78 return $cmp;
524 }
525  
526 # compare schema revision number with a given revision number
527 11 ▶sub _match_revision {
Subroutine _match_revision: called CC=3 SCAR=11.7
528 11 my ($self,$revision)=@_;
529 11 ▶ my $my_revision=$self->{revision} || 0;
Condition50%1/2
$self->{'revision'} || 0
l!l
110
MC/DC0%0/1
$self->{'revision'} || 0
$self->{'revision'}
Truth table50%1/2
A
A= $self->{'revision'}
Aresult
11
00
530 11 ▶ return cmp_revisions($self->{revision} || 0, $revision);
Condition50%1/2
$self->{'revision'} || 0
l!l
110
MC/DC0%0/1
$self->{'revision'} || 0
$self->{'revision'}
Truth table50%1/2
A
A= $self->{'revision'}
Aresult
11
00
531 }
532  
533 # for internal use only
534 9 ▶sub _resolve_type {
Subroutine _resolve_type: called CC=4 SCAR=15.8
535 9 my ($self,$type)=@_;
536 9 ▶ return $type unless ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 0 9 9
537 9 my $ref = $type->{type};
538 9 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 9 0 9
539 9 my $rtype = $self->{type}{$ref};
540 9 ▶ if (ref($rtype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rtype) { } 9 0 9
541 9 return $rtype;
542 } else {
543 # couldn't resolve
544 0 warn "No declaration for type '$ref' in schema '".$self->get_url."'\n";
545 0 return $type->{type};
546 }
547 } else {
548 0 return $type;
549 }
550 }
551  
552 =item $schema->for_each_decl (sub{...})
553  
554 This method traverses all nested declarations and sub-declarations and
555 calls a given subroutine passing the sub-declaration object as a
556 parameter.
557  
558 =cut
559  
560 153 ▶sub for_each_decl {
Subroutine for_each_decl: called CC=5 SCAR=16.1
Pod documented
561 153 my ($self,$sub) = @_;
562 153 ▶ if (ref $self->{root}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"root"}) 152 1 153
563 152 $self->{root}->for_each_decl($sub);
564 }
565 153 for my $d (qw(template type)) {
566 306 ▶ if (ref $self->{$d}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$d}) 139 167 306
567 139 foreach (values %{$self->{$d}}) {
568 972 $_->for_each_decl($sub);
569 }
570 }
571 }
572 }
573  
574 # traverse type data structure and collect types referred via
575 # type="type-name" declarations in the refferred hash
576 22 ▶sub _get_referred_types {
Subroutine _get_referred_types: called CC=1 SCAR=0.1
577 22 my ($self,$type,$referred) = @_;
578 $type->for_each_decl(
579 93 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=18.6
580 93 my ($type)=@_;
581 93 ▶ return unless ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 0 93 93
582 93 ▶ if (defined($type->{type}) and length($type->{type}) and !exists($referred->{$type->{type}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type->{"type"} and length $type->{"type"} and not exists $$referred{$type->{"type"}}) 9 84 93
Condition66%4/6
defined $type->{"type"} and length $type->{"type"} and not exists $$referred{$type->{"type"}}
!ll&&!rl&&r
8409
defined $type->{"type"} and length $type->{"type"}
!ll&&!rl&&r
8409
MC/DC33%1/3
defined $type->{"type"} and length $type->{"type"} and not exists $$referred{$type->{"type"}}
defined $type->{"type"} length $type->{"type"} not exists $$referred{$type->{"type"}}
Truth table50%2/4
A and B and not(C)
A= defined $type->{"type"}B= length $type->{"type"}C= not exists $$referred{$type->{"type"}}
ABCresult
0XX0
10X0
1100
1111
583 # this type declaration reffers to another type - get it
584 9 my $resolved = $self->_resolve_type($type);
585 9 $referred->{$type->{type}} = $resolved;
586 9 ▶ $self->_get_referred_types($resolved,$referred) if ref $resolved;
Branch: 1 branch
BranchTrueFalseTotal
if ref $resolved 9 0 9
587 }
588 22 });
589 }
590  
591 # import given named type and all named types it requires
592 # from src_schema into the current schema (self)
593 0 ▶sub _import_type {
Subroutine _import_type: not called CC=5 SCAR=34.0
594 0 my ($self,$src_schema, $name) = @_;
595 0 ▶ unless (exists $src_schema->{type}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $src_schema->{"type"}{$name}) 0 0 0
596 0 croak "Cannot import type '$name' from '$src_schema->{URL}' to '$self->{URL}': type not declared in the source schema\n";
597 }
598 0 my $type = $src_schema->{type}{$name};
599 0 my %referred = ($name => $type);
600 0 $src_schema->_get_referred_types($type,\%referred);
601 0 foreach my $n (keys %referred) {
602 0 ▶ unless (exists $self->{type}{$n}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'type'}{$n}) { } 0 0 0
603 0 my $parent = $referred{$n}->{-parent};
604 0 ▶ if (defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) { } 0 0 0
605 0 $self->{type}{$n}=Treex::PML::CloneValue($referred{$n},[$parent], [$self]);
606 } else {
607 0 $self->{type}{$n}=Treex::PML::CloneValue($referred{$n});
608 }
609 } else {
610
611 }
612 }
613 }
614  
615 0 ▶sub __fmt {
Subroutine __fmt: not called CC=3 SCAR=24.8
616 0 my ($string,$fmt) =@_;
617 0 $string =~ s{%(.)}{ $1 eq "%" ? "%" :
618 0 ▶ exists($fmt->{$1}) ? $fmt->{$1} : "%$1" }eg;
Branch: 2 branches
BranchTrueFalseTotal
$1 eq '%' ? : 0 0 0
exists $fmt->{$1} ? : 0 0 0
619 0 return $string;
620 }
621  
622 =item $schema->check_revision({ option=>value })
623  
624 Check that schema revision satisfies given constraints. The following options are suported:
625  
626 C<revision>: exact revision number to match
627  
628 C<minimal_revision>: minimal revision number to match
629  
630 C<maximal_revision>: maximal revision number to match
631  
632 C<revision error>: an optional error message format string with %f
633 mark for the schema filename or URL and %e for the error
634 string. Defaults to 'Error: wrong schema revision of %f: %e';
635  
636 =cut
637  
638 67 ▶sub check_revision {
Subroutine check_revision: called CC=8 SCAR=24.0
Pod documented
639 67 my ($self,$opts)=@_;
640  
641 67 ▶ my $error = $opts->{revision_error} || 'Error: wrong schema revision of %f: %e';
Condition100%2/2
$opts->{'revision_error'} || 'Error: wrong schema revision of %f: %e'
l!l
4423
MC/DC100%1/1
$opts->{'revision_error'} || 'Error: wrong schema revision of %f: %e'
$opts->{'revision_error'}
Truth table100%2/2
A
A= $opts->{'revision_error'}
Aresult
11
00
642 67 ▶ if ($opts->{revision} and
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'revision'} and $self->_match_revision($opts->{'revision'}) != 0) { } 0 67 67
Condition66%2/3
$opts->{"revision"} and $self->_match_revision($opts->{"revision"}) != 0
!ll&&!rl&&r
6430
MC/DC0%0/2
$opts->{"revision"} and $self->_match_revision($opts->{"revision"}) != 0
$opts->{"revision"} $self->_match_revision($opts->{"revision"}) != 0
Truth table66%2/3
A and B
A= $opts->{"revision"}B= $self->_match_revision($opts->{"revision"}) != 0
ABresult
0X0
100
111
643 $self->_match_revision($opts->{revision})!=0) {
644 croak(__fmt($error, { 'e' => "required $opts->{revision}, got $self->{revision}",
645 0 'f' => $self->{URL}}));
646 } else {
647 67 ▶ if ($opts->{minimal_revision} and
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"minimal_revision"} and $self->_match_revision($opts->{"minimal_revision"}) < 0) 0 67 67
Condition66%2/3
$opts->{"minimal_revision"} and $self->_match_revision($opts->{"minimal_revision"}) < 0
!ll&&!rl&&r
6160
MC/DC0%0/2
$opts->{"minimal_revision"} and $self->_match_revision($opts->{"minimal_revision"}) < 0
$opts->{"minimal_revision"} $self->_match_revision($opts->{"minimal_revision"}) < 0
Truth table66%2/3
A and B
A= $opts->{"minimal_revision"}B= $self->_match_revision($opts->{"minimal_revision"}) < 0
ABresult
0X0
100
111
648 $self->_match_revision($opts->{minimal_revision})<0) {
649 croak(__fmt($error, { 'e' => "required at least $opts->{minimal_revision}, got $self->{revision}",
650 0 'f' => $self->{URL}}));
651 }
652 67 ▶ if ($opts->{maximal_revision} and
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"maximal_revision"} and $self->_match_revision($opts->{"maximal_revision"}) > 0) 0 67 67
Condition66%2/3
$opts->{"maximal_revision"} and $self->_match_revision($opts->{"maximal_revision"}) > 0
!ll&&!rl&&r
6520
MC/DC0%0/2
$opts->{"maximal_revision"} and $self->_match_revision($opts->{"maximal_revision"}) > 0
$opts->{"maximal_revision"} $self->_match_revision($opts->{"maximal_revision"}) > 0
Truth table66%2/3
A and B
A= $opts->{"maximal_revision"}B= $self->_match_revision($opts->{"maximal_revision"}) > 0
ABresult
0X0
100
111
653 $self->_match_revision($opts->{maximal_revision})>0) {
654 croak(__fmt($error, { 'e' => "required at most $opts->{maximal_revision}, got $self->{revision}",
655 0 'f' => $self->{URL}}));
656 }
657 }
658 }
659  
660 =item $schema->convert_from_hash
661  
662 Compatibility method building the schema object from a nested hash
663 structure created by XML::Simple which was used in older
664 implementations. This is useful for upgrading objects stored in old
665 binary dumps.
666  
667 =cut
668  
669 2 ▶sub convert_from_hash {
Subroutine convert_from_hash: called CC=8 SCAR=22.6
Pod documented
670 2 my $class = shift;
671 2 my $schema_hash;
672 2 ▶ if (ref($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 0 2 2
673 0 $schema_hash = $class;
674 0 $class = ref( $schema_hash );
675 } else {
676 2 $schema_hash = shift;
677 2 bless $schema_hash,$class;
678 }
679 2 ▶ $schema_hash->{-api_version} ||= '2.0';
Condition50%1/2
$schema_hash->{"-api_version"} ||= "2.0"
l!l
02
MC/DC0%0/1
$schema_hash->{"-api_version"} ||= "2.0"
$schema_hash->{"-api_version"}
Truth table50%1/2
A
A= $schema_hash->{"-api_version"}
Aresult
11
00
680 2 $schema_hash->{'-xml_name'}='pml_schema';
681 2 $schema_hash->{-attributes}=[qw(xmlns version)];
682 2 ▶ if (ref $schema_hash->{reference}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema_hash->{"reference"}) 0 2 2
683 0 for my $ref (@{$schema_hash->{reference}}) {
684 0 $ref->{'-xml_name'}='reference';
685 0 $ref->{'-attributes'}=[qw(name readas)];
686 0 bless $ref,'Treex::PML::Schema::XMLNode';
687 0 weaken($ref->{-parent}=$schema_hash);
688 }
689 }
690 2 my $root = $schema_hash->{root};
691 2 ▶ if (defined($root)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $root) 2 0 2
692 2 bless $root, 'Treex::PML::Schema::Root';
693 2 weaken($root->{-parent}=$schema_hash);
694 2 $root->{'-xml_name'}='root';
695 2 $root->{'-attributes'}=['name','type'];
696 2 Treex::PML::Schema::Decl->convert_from_hash($root,
697 $schema_hash,
698 undef # path = '' for root
699 );
700 }
701 2 my $types = $schema_hash->{type};
702 2 ▶ if ($types) {
Branch: 1 branch
BranchTrueFalseTotal
if ($types) 2 0 2
703 2 my ($name, $decl);
704 2 ▶ while (($name, $decl) = each %$types) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$types) 2 2 4
705 2 bless $decl, 'Treex::PML::Schema::Type';
706 2 $decl->{'-xml_name'}='type';
707 2 $decl->{'-attributes'}=['name'];
708 2 Treex::PML::Schema::Decl->convert_from_hash($decl,
709 $schema_hash,
710 '!'.$name
711 );
712 }
713 }
714 2 return $schema_hash;
715 }
716  
717  
718 =item $schema->find_type_by_path (attribute-path,noresolve,decl)
719  
720 Locate a declaration specified by C<attribute-path> starting from
721 declaration C<decl>. If C<decl> is undefined the root type declaration
722 is used. (Note that attribute paths starting with '/' are always
723 evaluated startng from the root declaration and paths starting with
724 '!' followed by a name of a named type are evaluated starting from
725 that type.) All references to named types are transparently resolved
726 in each step.
727  
728 The caller should pass a true value in C<noresolve> to enforce Member,
729 Attribute, Element, Type, or Root declaration objects to be returned
730 rather than declarations of their content.
731  
732 Attribute path is a '/'-separated sequence of steps (member,
733 attribute, element names or strings matching [\d*]) which identifying
734 a certain nested type declaration. A step of the aforementioned form
735 [\d*] is match the content declaration of a List or Alt. Note however, that
736 named stepsdive into List or Alt declarations automatically, too.
737  
738 =cut
739  
740 99 ▶sub find_type_by_path {
Subroutine find_type_by_path: called CC=44 SCAR=55.3
Pod documented
741 99 my ($schema, $path, $noresolve, $decl) = @_;
742 99 ▶ if (defined($path) and length($path)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $path and length $path) { } 99 0 99
elsif (not $decl) { } 0 0 0
Condition33%1/3
defined $path and length $path
!ll&&!rl&&r
0099
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
743 99 ▶ if ($path=~s{^!([^/]+)/?}{}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path =~ s[^!([^/]+)/?][]) { } 2 97 99
elsif ($path =~ s[^/][] or not $decl) { } 97 0 97
744 2 $decl = $schema->get_type_by_name($1);
745 2 ▶ if (defined $decl) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $decl) { } 2 0 2
746 2 $decl = $decl->get_content_decl;
747 } else {
748 0 return;
749 }
750 ▶ } elsif ($path=~s{^/}{} or !$decl) {
Condition33%1/3
$path =~ s[^/][] or not $decl
l!l&&r!l&&!r
0970
MC/DC0%0/2
$path =~ s[^/][] or not $decl
$path =~ s[^/][] not $decl
Truth table33%1/3
A or not(B)
A= $path =~ s[^/][]B= not $decl
ABresult
1X1
011
000
751 97 $decl = $schema->get_root_decl->get_content_decl;
752 }
753 99 for my $step (split /\//, $path,-1) {
754 495 ▶ next if $step eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $step eq "." 0 495 495
755 495 ▶ if (ref($decl)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decl) { } 495 0 495
756 495 my $decl_is = $decl->get_decl_type;
757 495 ▶ if ($decl_is == PML_ATTRIBUTE_DECL ||
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 11 or $decl_is == 12 or $decl_is == 13 or $decl_is == 1) 139 356 495
Condition77%7/9
$decl_is == 11 or $decl_is == 12 or $decl_is == 13 or $decl_is == 1
l!l&&r!l&&!r
1390356
$decl_is == 11 or $decl_is == 12 or $decl_is == 13
l!l&&r!l&&!r
4297356
$decl_is == 11 or $decl_is == 12
l!l&&r!l&&!r
042453
MC/DC50%2/4
$decl_is == 11 or $decl_is == 12 or $decl_is == 13 or $decl_is == 1
$decl_is == 11 $decl_is == 12 $decl_is == 13 $decl_is == 1
Truth table60%3/5
A or B or C or D
A= $decl_is == 11B= $decl_is == 12C= $decl_is == 13D= $decl_is == 1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
758 $decl_is == PML_MEMBER_DECL ||
759 $decl_is == PML_ELEMENT_DECL ||
760 $decl_is == PML_TYPE_DECL ) {
761 139 $decl = $decl->get_knit_content_decl;
762 139 ▶ next unless defined($step) and length($step);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $step and length $step 0 139 139
Condition33%1/3
defined $step and length $step
!ll&&!rl&&r
00139
MC/DC0%0/2
defined $step and length $step
defined $step length $step
Truth table33%1/3
A and B
A= defined $stepB= length $step
ABresult
0X0
100
111
763 139 redo;
764 }
765 356 ▶ if ($decl_is == PML_LIST_DECL ||
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 6 or $decl_is == 7) 54 302 356
Condition66%2/3
$decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
540302
MC/DC50%1/2
$decl_is == 6 or $decl_is == 7
$decl_is == 6 $decl_is == 7
Truth table66%2/3
A or B
A= $decl_is == 6B= $decl_is == 7
ABresult
1X1
011
000
766 $decl_is == PML_ALT_DECL ) {
767 54 $decl = $decl->get_knit_content_decl;
768 54 ▶ next if ($step =~ /^\[[-+]?\d+\]$/ or
Branch: 2 branches
BranchTrueFalseTotal
if $step =~ /^\[[-+]?\d+\]$/ or $decl_is == 6 ? $step eq "LM" || $step eq "[LIST]" : $step eq "AM" || $step eq "[ALT]" 54 0 54
$decl_is == 6 ? : 54 0 54
Condition22%2/9
$step =~ /^\[[-+]?\d+\]$/ or $decl_is == 6 ? $step eq "LM" || $step eq "[LIST]" : $step eq "AM" || $step eq "[ALT]"
l!l&&r!l&&!r
0540
$step eq "LM" or $step eq "[LIST]"
l!l&&r!l&&!r
5400
$step eq "AM" or $step eq "[ALT]"
l!l&&r!l&&!r
000
MC/DC0%0/2
$step =~ /^\[[-+]?\d+\]$/ or $decl_is == 6 ? $step eq "LM" || $step eq "[LIST]" : $step eq "AM" || $step eq "[ALT]"
$step =~ /^\[[-+]?\d+\]$/ $decl_is == 6 ? $step eq "LM" || $step eq "[LIST]" : $step eq "AM" || $step eq "[ALT]"
MC/DC0%0/2
$step eq "LM" or $step eq "[LIST]"
$step eq "LM" $step eq "[LIST]"
MC/DC0%0/2
$step eq "AM" or $step eq "[ALT]"
$step eq "AM" $step eq "[ALT]"
Truth table33%1/3
A or B
A= $step =~ /^\[[-+]?\d+\]$/B= $decl_is == 6 ? $step eq "LM" || $step eq "[LIST]" : $step eq "AM" || $step eq "[ALT]"
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $step eq "LM"B= $step eq "[LIST]"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $step eq "AM"B= $step eq "[ALT]"
ABresult
1X1
011
000
769 (($decl_is == PML_LIST_DECL) ?
770 ($step eq 'LM' or $step eq '[LIST]')
771 :($step eq 'AM' or $step eq '[ALT]')));
772 0 redo;
773 }
774 302 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 4 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 42 260 302
elsif ($decl_is == 4) { } 97 163 260
elsif ($decl_is == 5) { } 163 0 163
elsif ($decl_is == 2) { } 0 0 0
775 42 my $member = $decl->get_member_by_name($step);
776 42 ▶ if ($member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member) { } 42 0 42
777 42 $decl = $member;
778 } else {
779 0 $member = $decl->get_member_by_name($step.'.rf');
780 0 ▶ return unless $member;
Branch: 1 branch
BranchTrueFalseTotal
unless $member 0 0 0
781 0 ▶ if ($member->get_knit_name eq $step) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member->get_knit_name eq $step) { } 0 0 0
782 0 $decl = $member;
783 } else {
784 0 return;
785 }
786 }
787 } elsif ($decl_is == PML_CONTAINER_DECL) {
788 97 ▶ if ($step eq '#content') {
Branch: 1 branch
BranchTrueFalseTotal
if ($step eq "#content") 97 0 97
789 97 $decl = $decl->get_content_decl;
790 97 next;
791 }
792 0 my $attr = $decl->get_attribute_by_name($step);
793 0 $decl = $attr;
794 } elsif ($decl_is == PML_SEQUENCE_DECL) {
795 163 $step =~ s/^\[\d+\]//; # name must follow
796 163 $decl = $decl->get_element_by_name($step);
797 } elsif ($decl_is == PML_ROOT_DECL) {
798 0 ▶ if (!(defined($step) and length($step)) or ($step eq $decl->get_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $step && length $step or $step eq $decl->get_name) { } 0 0 0
Condition0%0/6
not defined $step && length $step or $step eq $decl->get_name
l!l&&r!l&&!r
000
defined $step && length $step
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $step && length $step or $step eq $decl->get_name
defined $step length $step $step eq $decl->get_name
Truth table0%0/4
not(A && B) or C
A= defined $stepB= length $stepC= $step eq $decl->get_name
ABCresult
0XX1
10X1
1111
1100
799 0 $decl = $decl->get_content_decl;
800 } else {
801 0 return;
802 }
803 } else {
804 0 return;
805 }
806 } else {
807 # warn "Can't follow type path '$path' (step '$step')\n";
808 0 return(undef); # ERROR
809 }
810 }
811 } elsif (!$decl) {
812 0 ▶ $decl ||= $schema->get_root_decl->get_content_decl;
Condition0%0/3
$decl ||= $schema->get_root_decl->get_content_decl
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl ||= $schema->get_root_decl->get_content_decl
$decl $schema->get_root_decl->get_content_decl
Truth table0%0/3
A ||= B
A= $declB= $schema->get_root_decl->get_content_decl
ABresult
1X1
011
000
813 }
814 99 ▶ my $decl_is = $decl && $decl->get_decl_type;
Condition33%1/3
$decl && $decl->get_decl_type
!ll&&!rl&&r
0099
MC/DC0%0/2
$decl && $decl->get_decl_type
$decl $decl->get_decl_type
Truth table33%1/3
A && B
A= $declB= $decl->get_decl_type
ABresult
0X0
100
111
815 99 ▶ return $noresolve ? $decl :
Branch: 2 branches
BranchTrueFalseTotal
$noresolve ? : 0 99 99
$decl && ($decl_is == 11 || $decl_is == 12 || $decl_is == 13 || $decl_is == 1 || $decl_is == 2) ? : 66 33 99
Condition60%9/15
$decl and $decl_is == 11 || $decl_is == 12 || $decl_is == 13 || $decl_is == 1 || $decl_is == 2
!ll&&!rl&&r
03366
$decl_is == 11 or $decl_is == 12 or $decl_is == 13 or $decl_is == 1 or $decl_is == 2
l!l&&r!l&&!r
66033
$decl_is == 11 or $decl_is == 12 or $decl_is == 13 or $decl_is == 1
l!l&&r!l&&!r
66033
$decl_is == 11 or $decl_is == 12 or $decl_is == 13
l!l&&r!l&&!r
06633
$decl_is == 11 or $decl_is == 12
l!l&&r!l&&!r
0099
MC/DC16%1/6
$decl and $decl_is == 11 || $decl_is == 12 || $decl_is == 13 || $decl_is == 1 || $decl_is == 2
$decl $decl_is == 11 $decl_is == 12 $decl_is == 13 $decl_is == 1 $decl_is == 2
Truth table28%2/7
A and B or C or D or E or F
A= $declB= $decl_is == 11C= $decl_is == 12D= $decl_is == 13E= $decl_is == 1F= $decl_is == 2
ABCDEFresult
0XXXXX0
1000000
11XXXX1
101XXX1
1001XX1
10001X1
1000011
816 $decl && (
817 $decl_is == PML_ATTRIBUTE_DECL ||
818 $decl_is == PML_MEMBER_DECL ||
819 $decl_is == PML_ELEMENT_DECL ||
820 $decl_is == PML_TYPE_DECL ||
821 $decl_is == PML_ROOT_DECL
822 )
823 ? ($decl->get_knit_content_decl) : $decl;
824 }
825  
826  
827 =item $schema->find_types_by_role (role,start_decls)
828  
829 Return a list of declarations (objects derived from Treex::PML::Schema::Decl)
830 that have role equal to C<role>.
831  
832 If C<start_decls> is specified, it must be an ARRAY reference of
833 declarations; in that case, only declarations nested below the listed
834 ones are considered.
835  
836 =cut
837  
838 0 ▶sub find_types_by_role {
Subroutine find_types_by_role: not called CC=3 SCAR=24.8
Pod documented
839 0 my ($self,$role,$start_decls)=@_;
840 0 my @decls;
841 0 ▶ my $sub = sub { push @decls, $_[0] if $_[0]->{role} eq $role };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"role"} eq $role 0 0 0
842 0 ▶ if (defined($start_decls)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_decls) { } 0 0 0
843 0 for (@$start_decls) {
844 0 $_->for_each_decl($sub);
845 }
846 } else {
847 0 $self->for_each_decl($sub);
848 }
849 0 return @decls;
850 }
851  
852 =item $schema->find_role (role,start_decl,opts)
853  
854 WARINING: this function can be very slow, esp. if the type
855 declarations are recursive.
856  
857 Return a list of attribute paths leading to nested type declarations
858 of C<decl> with role equal to C<role>.
859  
860 This is equivalent to
861  
862 $schema->find_decl($decl,sub{ $_[0]->{role} eq $role },$opts);
863  
864 Please, see the documentation for C<find_dec> for more information.
865  
866 =cut
867  
868 22 ▶sub find_role {
Subroutine find_role: called CC=4 SCAR=15.0
Pod documented
869 22 my ($self, $role, $decl, $opts)=@_;
870 22 ▶ if (!$decl and wantarray()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $decl and wantarray) 22 0 22
Condition33%1/3
not $decl and wantarray
!ll&&!rl&&r
0022
MC/DC0%0/2
not $decl and wantarray
not $decl wantarray
Truth table33%1/3
not(A) and B
A= not $declB= wantarray
ABresult
0X0
100
111
871 22 ▶ $self->{-ROLE_CACHE}{$role} ||= [ $self->_find_role($role,$decl,$opts) ];
Condition100%2/2
$self->{"-ROLE_CACHE"}{$role} ||= [$self->_find_role($role, $decl, $opts)]
l!l
1012
MC/DC100%1/1
$self->{"-ROLE_CACHE"}{$role} ||= [$self->_find_role($role, $decl, $opts)]
$self->{"-ROLE_CACHE"}{$role}
Truth table100%2/2
A
A= $self->{"-ROLE_CACHE"}{$role}
Aresult
11
00
872 22 return @{$self->{-ROLE_CACHE}{$role}};
873 }
874 0 return $self->_find_role($role,$decl,$opts);
875 }
876  
877 12 ▶sub _find_role {
Subroutine _find_role: called CC=1 SCAR=0.0
878 12 my ($self, $role, $decl, $opts)=@_;
879 12 ▶ return $self->find_decl(sub{ defined($_[0]->{role}) and $_[0]->{role} eq $role },$decl,$opts);
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"role"} and $_[0]{"role"} eq $role 280 1546 1826
880 }
881  
882 =item $schema->find_decl (callback,start_decl,opts)
883  
884 WARINING: this function can be very slow, esp. if the type
885 declarations are recursive.
886  
887 Return a list of attribute paths leading to nested type declarations
888 of C<decl> for which a given callback returns a true value. The tested
889 type declaration is passed to the callback as the first (and only)
890 argument.
891  
892 If C<start_decls> is specified, it must be an ARRAY reference of
893 declarations; in that case, only declarations nested or referred to
894 from the listed ones are considered.
895  
896 In array context return all matching nested declarations are
897 returned. In scalar context only the first one is returned (with early
898 stopping).
899  
900 The last argument C<opts> can be used to pass some flags to the
901 algorithm. Currently only the flag C<no_childnodes> is available. If
902 true, then the function never recurses into content declaration of
903 declarations with the role #CHILDNODES.
904  
905 =cut
906  
907 12 ▶sub find_decl {
Subroutine find_decl: called CC=3 SCAR=11.6
Pod documented
908 12 my ($self, $sub, $decl, $opts)=@_;
909 12 ▶ $decl ||= $self->{root};
Condition33%1/3
$decl ||= $self->{"root"}
l!l&&r!l&&!r
0120
MC/DC0%0/2
$decl ||= $self->{"root"}
$decl $self->{"root"}
Truth table33%1/3
A ||= B
A= $declB= $self->{"root"}
ABresult
1X1
011
000
910 12 my $first = not(wantarray);
911 12 my @res = grep { defined } $self->_find($decl,$sub,$first,{},$opts);
912 12 ▶ return $first ? $res[0] : @res;
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 12 12
913 }
914  
915  
916 1859 ▶sub _find {
Subroutine _find: called CC=60 SCAR=53.2
917 1859 my ($self, $decl, $test, $first, $cache, $opts)=@_;
918  
919 1859 my @result = ();
920  
921 1859 ▶ return () unless ref $decl;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $decl 0 1859 1859
922  
923  
924 1859 ▶ if ($cache->{'#RECURSE'}{ $decl }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache->{"#RECURSE"}{$decl}) 33 1826 1859
925 return ()
926 33 }
927 1826 local $cache->{'#RECURSE'}{ $decl } = 1;
928  
929 1826 ▶ if ( ref $opts and $opts->{no_childnodes} and defined($decl->{role}) and $decl->{role} eq '#CHILDNODES') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts and $opts->{"no_childnodes"} and defined $decl->{"role"} and $decl->{"role"} eq "#CHILDNODES") 0 1826 1826
Condition44%4/9
ref $opts and $opts->{"no_childnodes"} and defined $decl->{"role"} and $decl->{"role"} eq "#CHILDNODES"
!ll&&!rl&&r
182600
ref $opts and $opts->{"no_childnodes"} and defined $decl->{"role"}
!ll&&!rl&&r
182600
ref $opts and $opts->{"no_childnodes"}
!ll&&!rl&&r
1218140
MC/DC0%0/4
ref $opts and $opts->{"no_childnodes"} and defined $decl->{"role"} and $decl->{"role"} eq "#CHILDNODES"
ref $opts $opts->{"no_childnodes"} defined $decl->{"role"} $decl->{"role"} eq "#CHILDNODES"
Truth table40%2/5
A and B and C and D
A= ref $optsB= $opts->{"no_childnodes"}C= defined $decl->{"role"}D= $decl->{"role"} eq "#CHILDNODES"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
930 0 return ();
931 }
932  
933 1826 ▶ if ( $test->($decl) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$test($decl)) 76 1750 1826
934 76 ▶ if ($first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 0 76 76
935 0 return '';
936 } else {
937 76 push @result, '';
938 }
939 }
940 1826 my $type_ref = $decl->get_type_ref;
941 1826 my $decl_is = $decl->get_decl_type;
942 1826 ▶ my $seq_bracket = $opts->{with_Seq_brackets} ? '[0]' : '';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'with_Seq_brackets'} ? : 0 1826 1826
943  
944 1826 ▶ if ($type_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_ref) 367 1459 1826
945 367 my $cached = $cache->{ $type_ref };
946 367 ▶ unless ($cached) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cached) 109 258 367
947 109 $cached = $cache->{ $type_ref } = [ $self->_find( $self->get_type_by_name($type_ref),
948 $test, $first, $cache, $opts ) ];
949 }
950 367 ▶ if ($decl_is == PML_CONTAINER_DECL) {
Branch: 3 branches
BranchTrueFalseTotal
if ($decl_is == 4) { } 0 367 367
elsif ($decl_is == 6) { } 81 286 367
elsif ($decl_is == 7) { } 24 262 286
951 0 ▶ push @result, map { (defined($_) and length($_)) ? '#content/'.$_ : '#content' } @$cached;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
952 } elsif ($decl_is == PML_LIST_DECL) {
953 81 ▶ push @result, map { (defined($_) and length($_)) ? 'LM/'.$_ : 'LM' } @$cached;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 8 26 34
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
0268
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
954 } elsif ($decl_is == PML_ALT_DECL) {
955 0 ▶ push @result, map { (defined($_) and length($_)) ? 'AM/'.$_ : 'AM' } @$cached;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
956 } else {
957 262 push @result, @$cached;
958 }
959 367 ▶ return $result[0] if ($first and @result);
Branch: 1 branch
BranchTrueFalseTotal
if $first and @result 0 367 367
Condition33%1/3
$first and @result
!ll&&!rl&&r
36700
MC/DC0%0/2
$first and @result
$first @result
Truth table33%1/3
A and B
A= $firstB= @result
ABresult
0X0
100
111
960 }
961 1826 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 6 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 132 1694 1826
elsif ($decl_is == 4) { } 48 1646 1694
elsif ($decl_is == 5) { } 34 1612 1646
elsif ($decl_is == 6) { } 134 1478 1612
elsif ($decl_is == 7) { } 28 1450 1478
elsif ($decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13) { } 821 629 1450
962 132 foreach my $member ($decl->get_members) {
963 624 ▶ my @res = map { (defined($_) and length($_)) ? $member->get_name.'/'.$_ : $member->get_name }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 37 0 37
Condition33%1/3
defined $_ and length $_
!ll&&!rl&&r
0037
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table33%1/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
964 $self->_find($member, $test, $first, $cache, $opts);
965 624 ▶ return $res[0] if ($first and @res);
Branch: 1 branch
BranchTrueFalseTotal
if $first and @res 0 624 624
Condition33%1/3
$first and @res
!ll&&!rl&&r
62400
MC/DC0%0/2
$first and @res
$first @res
Truth table33%1/3
A and B
A= $firstB= @res
ABresult
0X0
100
111
966 624 push @result,@res;
967 }
968 } elsif ($decl_is == PML_CONTAINER_DECL) {
969 48 my $cdecl = $decl->get_content_decl;
970 48 foreach my $attr ($decl->get_attributes) {
971 0 ▶ my @res = map { (defined($_) and length($_)) ? $attr->get_name.'/'.$_ : $attr->get_name }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
972 $self->_find($attr, $test, $first, $cache, $opts);
973 28 ▶ return $res[0] if ($first and @res);
Branch: 1 branch
BranchTrueFalseTotal
if $first and @res 0 28 28
Condition33%1/3
$first and @res
!ll&&!rl&&r
2800
MC/DC0%0/2
$first and @res
$first @res
Truth table33%1/3
A and B
A= $firstB= @res
ABresult
0X0
100
111
974 28 push @result,@res;
975 }
976 48 ▶ if ($cdecl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cdecl) 48 0 48
977 48 ▶ push @result, map { (defined($_) and length($_)) ? '#content/'.$_ : '#content' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 51 0 51
Condition33%1/3
defined $_ and length $_
!ll&&!rl&&r
0051
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table33%1/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
978 $self->_find($cdecl, $test, $first, $cache, $opts);
979 48 ▶ return $result[0] if ($first and @result);
Branch: 1 branch
BranchTrueFalseTotal
if $first and @result 0 48 48
Condition33%1/3
$first and @result
!ll&&!rl&&r
4800
MC/DC0%0/2
$first and @result
$first @result
Truth table33%1/3
A and B
A= $firstB= @result
ABresult
0X0
100
111
980 }
981 } elsif ($decl_is == PML_SEQUENCE_DECL) {
982 34 foreach my $element ($decl->get_elements) {
983 55 ▶ my @res = map { (defined($_) and length($_)) ? $element->get_name.$seq_bracket.'/'.$_ : $element->get_name.$seq_bracket }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 56 41 97
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
04156
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
984 $self->_find($element, $test, $first, $cache, $opts);
985 55 ▶ return $res[0] if ($first and @res);
Branch: 1 branch
BranchTrueFalseTotal
if $first and @res 0 55 55
Condition33%1/3
$first and @res
!ll&&!rl&&r
5500
MC/DC0%0/2
$first and @res
$first @res
Truth table33%1/3
A and B
A= $firstB= @res
ABresult
0X0
100
111
986 55 push @result,@res;
987 }
988 } elsif ($decl_is == PML_LIST_DECL) {
989 134 ▶ push @result, map { (defined($_) and length($_)) ? 'LM/'.$_ : 'LM' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 19 15 34
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
01519
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
990 $self->_find($decl->get_content_decl, $test, $first, $cache, $opts);
991 } elsif ($decl_is == PML_ALT_DECL) {
992 0 ▶ push @result, map { (defined($_) and length($_)) ? 'AM/'.$_ : 'AM' }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
993 $self->_find($decl->get_content_decl, $test, $first, $cache, $opts);
994 ▶ } elsif ($decl_is == PML_TYPE_DECL ||
Condition100%12/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
76655629
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12
l!l&&r!l&&!r
142624684
$decl_is == 1 or $decl_is == 2 or $decl_is == 11
l!l&&r!l&&!r
114281308
$decl_is == 1 or $decl_is == 2
l!l&&r!l&&!r
102121336
MC/DC100%5/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 table100%6/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
995 $decl_is == PML_ROOT_DECL ||
996 $decl_is == PML_ATTRIBUTE_DECL ||
997 $decl_is == PML_MEMBER_DECL ||
998 $decl_is == PML_ELEMENT_DECL ) {
999 821 push @result, $self->_find($decl->get_content_decl, $test, $first, $cache, $opts);
1000 }
1001 1826 my %uniq;
1002 return $first ? (@result ? $result[0] : ())
1003 1826 ▶ : grep { !$uniq{$_} && ($uniq{$_}=1) } @result;
Branch: 2 branches
BranchTrueFalseTotal
$first ? : 0 1826 1826
@result ? : 0 0 0
Condition100%2/2
!$uniq{$_} && ($uniq{$_} = 1)
!ll
96537
MC/DC100%1/1
!$uniq{$_} && ($uniq{$_} = 1)
!$uniq{$_}
Truth table100%2/2
not(A)
A= !$uniq{$_}
Aresult
00
11
1004 }
1005  
1006 =item $schema->node_types ()
1007  
1008 Return a list of all type declarations with the role C<#NODE>.
1009  
1010 =cut
1011  
1012 0 ▶sub node_types {
Subroutine node_types: not called CC=1 SCAR=6.9
Pod documented
1013 0 my ($self) = @_;
1014 0 my @result;
1015 0 return $self->find_types_by_role('#NODE');
1016 }
1017  
1018  
1019  
1020 =item $schema->get_type_by_name (name)
1021  
1022 Return the declaration of the named type with a given name (see
1023 C<Treex::PML::Schema::Type>).
1024  
1025 =cut
1026  
1027 111 ▶sub get_type_by_name {
Subroutine get_type_by_name: called CC=1 SCAR=0.0
Pod documented
1028 111 my ($self,$name) = @_;
1029 111 return $self->{type}{$name};
1030 }
1031 9 *get_type_by_name_obj = \&get_type_by_name;
1032  
1033  
1034 # OBSOLETE: for backward compatibility only
1035 0 ▶sub type {
Subroutine type: not called CC=2 SCAR=17.9
Pod documented
1036 0 my ($self,$decl)=@_;
1037 0 ▶ if (UNIVERSAL::DOES::does($decl,'Treex::PML::Schema::Decl')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($decl, 'Treex::PML::Schema::Decl')) { } 0 0 0
1038 0 return $decl
1039 } else {
1040 0 return Treex::PML::Type->new($self,$decl);
1041 }
1042 }
1043  
1044 =item $schema->validate_object (object, type_decl, log, flags)
1045  
1046 Validates the data content of the given object against a specified
1047 type declaration. The type_decl argument must either be an object
1048 derived from the C<Treex::PML::Schema::Decl> class or the name of a named
1049 type.
1050  
1051 An array reference may be passed as the optional 3rd argument C<log>
1052 to obtain a detailed report of all validation errors.
1053  
1054 The C<flags> argument can specify flags that influance the
1055 validation. The following constants can binary-OR'ed to obtain the
1056 fags:
1057  
1058 PML_VALIDATE_NO_TREES - do not validate nested data with roles
1059 #CHIDLNODES or #TREES and do not require that objects with the role
1060 #NODE implement the Treex::PML::Node role.
1061  
1062 PML_VALIDATE_NO_CHILDNODES - do not validate nested data with the
1063 role #CHIDLNODES.
1064  
1065 Returns: 1 if the content conforms, 0 otherwise.
1066  
1067 =cut
1068  
1069 0 ▶sub validate_object { # (path, base_type)
Subroutine validate_object: not called CC=5 SCAR=34.0
Pod documented
1070 0 my ($schema, $object, $type,$log)=@_;
1071 0 ▶ if (defined $log and UNIVERSAL::isa($log,'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log and UNIVERSAL::isa($log, "ARRAY")) 0 0 0
Condition0%0/3
defined $log and UNIVERSAL::isa($log, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $log and UNIVERSAL::isa($log, "ARRAY")
defined $log UNIVERSAL::isa($log, "ARRAY")
Truth table0%0/3
A and B
A= defined $logB= UNIVERSAL::isa($log, "ARRAY")
ABresult
0X0
100
111
1072 0 croak "Treex::PML::Schema::validate_object: log must be an ARRAY reference";
1073 }
1074 0 ▶ $type ||= $schema->get_type_by_name($type);
Condition0%0/3
$type ||= $schema->get_type_by_name($type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= $schema->get_type_by_name($type)
$type $schema->get_type_by_name($type)
Truth table0%0/3
A ||= B
A= $typeB= $schema->get_type_by_name($type)
ABresult
1X1
011
000
1075 0 ▶ if (!ref($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type) 0 0 0
1076 0 croak "Treex::PML::Schema::validate_object: Cannot determine data type";
1077 }
1078 0 return $type->validate_object($object,{log => $log});
1079 }
1080  
1081  
1082 =item $schema->validate_field (object, attr-path, type, log)
1083  
1084 This method is similar to C<validate_object>, but in this case the
1085 validation is restricted to the data substructure of C<object>
1086 specified by the C<attr-path> argument.
1087  
1088 C<type> is the type of C<object> specified either by the name of a
1089 named type, or as a Treex::PML::Type, or a type declaration.
1090  
1091 An array reference may be passed as the optional 3rd argument C<log>
1092 to obtain a detailed report of all validation errors.
1093  
1094 Returns: 1 if the content conforms, 0 otherwise.
1095  
1096 =cut
1097  
1098 0 ▶sub validate_field {
Subroutine validate_field: not called CC=8 SCAR=42.8
Pod documented
1099 0 my ($schema, $object, $path, $type, $log) = @_;
1100 0 ▶ if (defined $log and UNIVERSAL::isa($log,'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log and UNIVERSAL::isa($log, "ARRAY")) 0 0 0
Condition0%0/3
defined $log and UNIVERSAL::isa($log, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $log and UNIVERSAL::isa($log, "ARRAY")
defined $log UNIVERSAL::isa($log, "ARRAY")
Truth table0%0/3
A and B
A= defined $logB= UNIVERSAL::isa($log, "ARRAY")
ABresult
0X0
100
111
1101 0 croak "Treex::PML::Schema::validate_field: log must be an ARRAY reference";
1102 }
1103 0 ▶ if (!ref($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type) 0 0 0
1104 0 my $named_type = $schema->get_type_by_name($type);
1105 0 ▶ croak "Treex::PML::Schema::validate_field: Cannot find type '$type'"
Branch: 1 branch
BranchTrueFalseTotal
unless $named_type 0 0 0
1106 unless $named_type;
1107 0 $type = $named_type;
1108 }
1109 0 ▶ if (!(defined($path) and length($path))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path and length $path) 0 0 0
Condition0%0/3
defined $path and length $path
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and length $path
defined $path length $path
Truth table0%0/3
A and B
A= defined $pathB= length $path
ABresult
0X0
100
111
1110 0 return $type->validate_object($object, { log => $log });
1111 }
1112 0 $type = $type->find($path);
1113 0 ▶ croak "Treex::PML::Schema::validate_field: Cannot determine data type for attribute-path '$path'" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
1114 return
1115 0 $type->validate_object(Treex::PML::Instance::get_data($object,$path),{ path => $path,
1116 log => $log
1117 });
1118 }
1119  
1120  
1121 =item $schema->get_paths_to_atoms (\@decls, \%opts)
1122  
1123 This method returns a list of all non-periodic canonical paths leading
1124 from given types to atomic values. Currently only the following options
1125 are supported:
1126  
1127 no_childnodes => $bool
1128  
1129 If true, the method does not descent to member types with the role
1130 #CHILDNODES.
1131  
1132 no_nodes => $bool
1133  
1134 If true, the method does not descent to member types with the role
1135 #NODE (except for the starting types).
1136  
1137 with_LM => $bool
1138  
1139 If true, the paths will include a LM step for each List type on the path.
1140  
1141 with_AM => $bool
1142  
1143 If true, the paths will include a AM step for each Alt type on the path.
1144  
1145 with_Seq_brackets => $bool
1146  
1147 If true, the paths will append a [0] after each step representing a sequence element
1148  
1149 =cut
1150  
1151 0 ▶sub get_paths_to_atoms {
Subroutine get_paths_to_atoms: not called CC=3 SCAR=24.8
Pod documented
1152 0 my ($self,$types,$opts) = @_;
1153 # find node type
1154  
1155 0 ▶ unless (defined $types) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $types) 0 0 0
1156 0 $types = [ $self->node_types ];
1157 }
1158 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1159 0 return $self->_get_paths_to_atoms($types,{},$opts);
1160 }
1161  
1162 0 ▶sub _get_paths_to_atoms {
Subroutine _get_paths_to_atoms: not called CC=29 SCAR=67.7
1163 0 my ($self,$types,$seen,$opts)=@_;
1164 0 my @result;
1165 0 my $no_children = $opts->{no_childnodes};
1166 0 my $no_nodes = $opts->{no_nodes};
1167 0 my $with_LM = $opts->{with_LM};
1168 0 my $with_AM = $opts->{with_AM};
1169 0 my $with_Seq_brackets = $opts->{with_Seq_brackets};
1170 0 foreach my $type (@$types) {
1171 0 ▶ next if $seen->{$type};
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$type} 0 0 0
1172 0 my $decl_is = $type->get_decl_type;
1173 0 ▶ next if $no_children and $type->get_role eq '#CHILDNODES';
Branch: 1 branch
BranchTrueFalseTotal
if $no_children and $type->get_role eq "#CHILDNODES" 0 0 0
Condition0%0/3
$no_children and $type->get_role eq "#CHILDNODES"
!ll&&!rl&&r
000
MC/DC0%0/2
$no_children and $type->get_role eq "#CHILDNODES"
$no_children $type->get_role eq "#CHILDNODES"
Truth table0%0/3
A and B
A= $no_childrenB= $type->get_role eq "#CHILDNODES"
ABresult
0X0
100
111
1174 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 or not $with_LM and $decl_is == 6 or not $with_AM and $decl_is == 7) 0 0 0
Condition0%0/24
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13 or not $with_LM and $decl_is == 6 or not $with_AM and $decl_is == 7
l!l&&r!l&&!r
000
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13 or not $with_LM and $decl_is == 6
l!l&&r!l&&!r
000
$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
not $with_LM and $decl_is == 6
!ll&&!rl&&r
000
not $with_AM and $decl_is == 7
!ll&&!rl&&r
000
MC/DC0%0/9
$decl_is == 1 or $decl_is == 2 or $decl_is == 11 or $decl_is == 12 or $decl_is == 13 or not $with_LM and $decl_is == 6 or not $with_AM and $decl_is == 7
$decl_is == 1 $decl_is == 2 $decl_is == 11 $decl_is == 12 $decl_is == 13 not $with_LM $decl_is == 6 not $with_AM $decl_is == 7
Truth table0%0/12
A or B or C or D or E or not(F) and G or not(H) and I
A= $decl_is == 1B= $decl_is == 2C= $decl_is == 11D= $decl_is == 12E= $decl_is == 13F= not $with_LMG= $decl_is == 6H= not $with_AMI= $decl_is == 7
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
0000011XX1
000000X111
0000010111
000000X0X0
000000X100
00000100X0
0000010100
1175 $decl_is == PML_ROOT_DECL ||
1176 $decl_is == PML_ATTRIBUTE_DECL ||
1177 $decl_is == PML_MEMBER_DECL ||
1178 $decl_is == PML_ELEMENT_DECL ||
1179 (!$with_LM && $decl_is == PML_LIST_DECL) ||
1180 (!$with_AM && $decl_is == PML_ALT_DECL)) {
1181 0 $type = $type->get_knit_content_decl;
1182 0 ▶ next if $no_nodes and $type->get_role eq '#NODE';
Branch: 1 branch
BranchTrueFalseTotal
if $no_nodes and $type->get_role eq "#NODE" 0 0 0
Condition0%0/3
$no_nodes and $type->get_role eq "#NODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$no_nodes and $type->get_role eq "#NODE"
$no_nodes $type->get_role eq "#NODE"
Truth table0%0/3
A and B
A= $no_nodesB= $type->get_role eq "#NODE"
ABresult
0X0
100
111
1183 0 redo;
1184 }
1185 0 ▶ next unless ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type 0 0 0
1186 0 my @members;
1187 0 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 5 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 0 0 0
elsif ($decl_is == 4) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 6) { } 0 0 0
elsif ($decl_is == 7) { } 0 0 0
1188 0 @members = map { [$_,$_->get_knit_name] } $type->get_members;
1189 } elsif ($decl_is == PML_CONTAINER_DECL) {
1190 0 my $cdecl = $type->get_knit_content_decl;
1191 0 ▶ @members = ((map { [ $_, $_->get_name ] } $type->get_attributes),
Branch: 1 branch
BranchTrueFalseTotal
$cdecl ? : 0 0 0
1192 ($cdecl ? [$cdecl, '#content'] : ()));
1193 } elsif ($decl_is == PML_SEQUENCE_DECL) {
1194 0 ▶ if ($with_Seq_brackets) {
Branch: 1 branch
BranchTrueFalseTotal
if ($with_Seq_brackets) { } 0 0 0
1195 0 @members = map { [ $_, $_->get_name.'[0]' ] } $type->get_elements;
1196 } else {
1197 0 @members = map { [ $_, $_->get_name ] } $type->get_elements;
1198 }
1199 } elsif ($decl_is == PML_LIST_DECL) {
1200 0 @members = [$type->get_knit_content_decl,'LM'];
1201 } elsif ($decl_is == PML_ALT_DECL) {
1202 0 @members = [$type->get_knit_content_decl,'AM'];
1203 } else {
1204 0 push @result, qq{};
1205 }
1206 0 ▶ if (@members) {
Branch: 1 branch
BranchTrueFalseTotal
if (@members) 0 0 0
1207 0 for my $m (@members) {
1208 0 my ($mdecl,$name) = @$m;
1209 0 local $seen->{$type}=1;
1210 0 ▶ push @result, map { (defined($_) and length($_)) ? $name."/".$_ : $name }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
1211 $self->_get_paths_to_atoms([$mdecl],$seen,$opts);
1212 }
1213 }
1214 }
1215 0 my %uniq;
1216 0 ▶ return grep { !$uniq{$_} && ($uniq{$_}=1) } @result;
Condition0%0/2
!$uniq{$_} && ($uniq{$_} = 1)
!ll
00
MC/DC0%0/1
!$uniq{$_} && ($uniq{$_} = 1)
!$uniq{$_}
Truth table0%0/2
not(A)
A= !$uniq{$_}
Aresult
00
11
1217 }
1218  
1219  
1220 =item $schema->attributes (decl...)
1221  
1222 This function tries to emulate the behavior of
1223 C<<< Treex::PML::FSFormat->attributes >>> to some extent.
1224  
1225 Return attribute paths to all atomic subtypes of given type
1226 declarations. If no type declaration objects are given, then types
1227 with role C<#NODE> are assumed. This function never descends to
1228 subtypes with role C<#CHILDNODES>.
1229  
1230 =cut
1231  
1232 0 ▶sub attributes {
Subroutine attributes: not called CC=2 SCAR=17.9
Pod documented
1233 0 my ($self,@types) = @_;
1234 # find node type
1235 0 ▶ return $self->get_paths_to_atoms(@types ? \@types : undef, { no_childnodes => 1 });
Branch: 1 branch
BranchTrueFalseTotal
@types ? : 0 0 0
1236 }
1237  
1238  
1239  
1240 67 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
1241 67 my ($schema,$opts)=@_;
1242 67 $schema->{URL} = $opts->{URL};
1243 67 $schema->{-api_version} = '2.0';
1244 }
1245  
1246  
1247 # these functions are used internally by the serializer
1248 11 ▶sub serialize_exclude_keys {
Subroutine serialize_exclude_keys: called CC=1 SCAR=0.0
Pod undocumented
1249 11 return qw(URL revision description);
1250 }
1251 11 ▶sub serialize_get_children {
Subroutine serialize_get_children: called CC=2 SCAR=7.0
Pod undocumented
1252 11 my ($self,$opts)=@_;
1253 11 my @children = $self->SUPER::serialize_get_children($opts);
1254 return (
1255 22 ▶ (grep { defined($_->[1]) and length($_->[1]) } (
Condition66%2/3
defined $_->[1] && length $_->[1]
!ll&&!rl&&r
8014
MC/DC50%1/2
defined $_->[1] && length $_->[1]
defined $_->[1] length $_->[1]
Truth table66%2/3
A && B
A= defined $_->[1]B= length $_->[1]
ABresult
0X0
100
111
1256 ['revision',$self->{revision}],
1257 ['description',$self->{description}]
1258 )
1259 ),
1260 62 (grep { $_->[0] eq 'reference' } @children),
1261 62 (grep { $_->[0] eq 'root' } @children),
1262 11 (grep { $_->[0] !~ /^(?:root|reference)$/ } @children)
1263 );
1264 }
1265  
1266 =item $schema->post_process($options)
1267  
1268 Auxiliary method used internally by the PML Schema parser. It
1269 simplifies the schema and for each declaration object creates back
1270 references to its parent declaration and schema and pre-computes the
1271 type attribute path returned by $decl->get_decl_path().
1272  
1273 =cut
1274  
1275 67 ▶sub post_process {
Subroutine post_process: called CC=1 SCAR=0.0
Pod documented
1276 67 my ($schema,$opts)=@_;
1277 67 $schema->simplify($opts);
1278 2384 ▶ $schema->for_each_decl(sub{
Subroutine __ANON__: called CC=24 SCAR=32.1
1279 2384 my ($decl)=@_;
1280 2384 weaken( $decl->{-schema} = $schema );
1281 2384 my $parent = $decl->{-parent};
1282 2384 my $decl_is = $decl->get_decl_type;
1283 2384 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7 or $decl_is == 9 or $decl_is == 10 or $decl_is == 8) { } 1053 1331 2384
elsif ($decl_is == 12) { } 607 724 1331
Condition100%21/21
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7 or $decl_is == 9 or $decl_is == 10 or $decl_is == 8
l!l&&r!l&&!r
5864671331
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7 or $decl_is == 9 or $decl_is == 10
l!l&&r!l&&!r
58421798
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7 or $decl_is == 9
l!l&&r!l&&!r
494901800
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
484101890
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6
l!l&&r!l&&!r
3781061900
$decl_is == 3 or $decl_is == 4 or $decl_is == 5
l!l&&r!l&&!r
287912006
$decl_is == 3 or $decl_is == 4
l!l&&r!l&&!r
189982097
MC/DC100%8/8
$decl_is == 3 or $decl_is == 4 or $decl_is == 5 or $decl_is == 6 or $decl_is == 7 or $decl_is == 9 or $decl_is == 10 or $decl_is == 8
$decl_is == 3 $decl_is == 4 $decl_is == 5 $decl_is == 6 $decl_is == 7 $decl_is == 9 $decl_is == 10 $decl_is == 8
Truth table100%9/9
A or B or C or D or E or F or G or H
A= $decl_is == 3B= $decl_is == 4C= $decl_is == 5D= $decl_is == 6E= $decl_is == 7F= $decl_is == 9G= $decl_is == 10H= $decl_is == 8
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
1284 $decl_is == PML_STRUCTURE_DECL ||
1285 $decl_is == PML_CONTAINER_DECL ||
1286 $decl_is == PML_SEQUENCE_DECL ||
1287 $decl_is == PML_LIST_DECL ||
1288 $decl_is == PML_ALT_DECL ||
1289 $decl_is == PML_CHOICE_DECL ||
1290 $decl_is == PML_CONSTANT_DECL ||
1291 $decl_is == PML_CDATA_DECL
1292 ) {
1293 1053 my $parent_is = $parent->get_decl_type;
1294 1053 ▶ if ($parent_is == PML_TYPE_DECL) {
Branch: 6 branches
BranchTrueFalseTotal
if ($parent_is == 1) { } 400 653 1053
elsif ($parent_is == 2) { } 28 625 653
elsif ($parent_is == 11 or $parent_is == 12 or $parent_is == 13) { } 479 146 625
elsif ($parent_is == 4 and $decl_is != 11) { } 98 48 146
elsif ($parent_is == 6) { } 47 1 48
elsif ($parent_is == 7) { } 1 0 1
1295 400 $decl->{-path} = '!'.$parent->get_name;
1296 } elsif ($parent_is == PML_ROOT_DECL) {
1297 28 $decl->{-path} = '';
1298 ▶ } elsif ($parent_is == PML_ATTRIBUTE_DECL ||
Condition100%6/6
$parent_is == 11 or $parent_is == 12 or $parent_is == 13
l!l&&r!l&&!r
4763146
$parent_is == 11 or $parent_is == 12
l!l&&r!l&&!r
96380149
MC/DC100%3/3
$parent_is == 11 or $parent_is == 12 or $parent_is == 13
$parent_is == 11 $parent_is == 12 $parent_is == 13
Truth table100%4/4
A or B or C
A= $parent_is == 11B= $parent_is == 12C= $parent_is == 13
ABCresult
1XX1
01X1
0011
0000
1299 $parent_is == PML_MEMBER_DECL ||
1300 $parent_is == PML_ELEMENT_DECL) {
1301 479 $decl->{-path} = $parent->{-parent}{-path}.'/'.$parent->get_name;
1302 ▶ } elsif ($parent_is == PML_CONTAINER_DECL and $decl_is != PML_ATTRIBUTE_DECL) {
Condition66%2/3
$parent_is == 4 and $decl_is != 11
!ll&&!rl&&r
48098
MC/DC50%1/2
$parent_is == 4 and $decl_is != 11
$parent_is == 4 $decl_is != 11
Truth table66%2/3
A and B
A= $parent_is == 4B= $decl_is != 11
ABresult
0X0
100
111
1303 98 $decl->{-path} = $parent->{-path}.'/#content';
1304 } elsif ($parent_is == PML_LIST_DECL) {
1305 47 $decl->{-path} = $parent->{-path}.'/LM';
1306 } elsif ($parent_is == PML_ALT_DECL) {
1307 1 $decl->{-path} = $parent->{-path}.'/AM';
1308 }
1309 1053 ▶ if ($decl_is == PML_LIST_DECL and !$decl->{-decl} and $decl->{role} eq '#KNIT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 6 and not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT") 0 1053 1053
Condition83%5/6
$decl_is == 6 and not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT"
!ll&&!rl&&r
994590
$decl_is == 6 and not $decl->{"-decl"}
!ll&&!rl&&r
9474759
MC/DC0%0/3
$decl_is == 6 and not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT"
$decl_is == 6 not $decl->{"-decl"} $decl->{"role"} eq "#KNIT"
Truth table75%3/4
A and not(B) and C
A= $decl_is == 6B= not $decl->{"-decl"}C= $decl->{"role"} eq "#KNIT"
ABCresult
0XX0
10X0
1100
1111
1310 # warn ("List $decl->{-path} with role=\"#KNIT\" must have a content type declaration: assuming <cdata format=\"PMLREF\">!\n");
1311 0 __fix_knit_type($schema,$decl,$decl->{-path}.'/LM');
1312 }
1313 } elsif ($decl_is == PML_MEMBER_DECL) {
1314 607 ▶ if (!$decl->{-decl} and $decl->{role} eq '#KNIT') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT") 0 607 607
Condition66%2/3
not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT"
!ll&&!rl&&r
3802270
MC/DC0%0/2
not $decl->{"-decl"} and $decl->{"role"} eq "#KNIT"
not $decl->{"-decl"} $decl->{"role"} eq "#KNIT"
Truth table66%2/3
not(A) and B
A= not $decl->{"-decl"}B= $decl->{"role"} eq "#KNIT"
ABresult
0X0
100
111
1315 # warn ("Member $decl->{-parent}{-path}/$decl->{-name} with role=\"#KNIT\" must have a content type declaration: assuming <cdata format=\"PMLREF\">!\n");
1316 0 __fix_knit_type($schema,$decl);
1317 }
1318 }
1319 67 });
1320 }
1321  
1322 0 ▶sub __fix_knit_type {
Subroutine __fix_knit_type: not called CC=4 SCAR=30.0
1323 0 my ($schema,$decl,$path)=@_;
1324 0 $decl->{-decl}='cdata';
1325 0 my $cdata = $decl->{cdata}= bless {
1326 format => 'PMLREF',
1327 -xml_name => 'cdata',
1328 -attributes => [ 'format' ],
1329 }, 'Treex::PML::Schema::CDATA';
1330 0 weaken( $cdata->{-schema} = $schema );
1331 0 weaken( $cdata->{-parent} = $decl );
1332 0 ▶ if (defined $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $path) { } 0 0 0
elsif ($decl->{'-parent'} and $decl->{'-name'}) { } 0 0 0
1333 0 $cdata->{-path} = $path;
1334 ▶ } elsif ($decl->{-parent} and $decl->{-name}) {
Condition0%0/3
$decl->{"-parent"} and $decl->{"-name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$decl->{"-parent"} and $decl->{"-name"}
$decl->{"-parent"} $decl->{"-name"}
Truth table0%0/3
A and B
A= $decl->{"-parent"}B= $decl->{"-name"}
ABresult
0X0
100
111
1335 0 $cdata->{-path} = "$decl->{-parent}{-path}/$decl->{-name}";
1336 }
1337 }
1338  
1339 707 ▶sub _traverse_data {
Subroutine _traverse_data: called CC=10 SCAR=24.1
1340 707 my ($data,$sub,$seen,$hashes_only)=@_;
1341 707 $seen->{$data}=1;
1342 707 ▶ if (UNIVERSAL::isa($data,'ARRAY')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($data, 'ARRAY')) { } 337 370 707
elsif (UNIVERSAL::isa($data, 'HASH')) { } 370 0 370
1343 337 ▶ $sub->($data,0) unless $hashes_only;
Branch: 1 branch
BranchTrueFalseTotal
unless $hashes_only 0 337 337
1344 337 foreach my $val (@$data) {
1345 499 ▶ if (ref($val) and !exists $seen->{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val and not exists $seen->{$val}) 0 499 499
Condition33%1/3
ref $val and not exists $seen->{$val}
!ll&&!rl&&r
49900
MC/DC0%0/2
ref $val and not exists $seen->{$val}
ref $val not exists $seen->{$val}
Truth table33%1/3
A and not(B)
A= ref $valB= not exists $seen->{$val}
ABresult
0X0
100
111
1346 0 _traverse_data($val,$sub,$seen,$hashes_only);
1347 }
1348 }
1349 } elsif (UNIVERSAL::isa($data,'HASH')) {
1350 370 $sub->($data,1);
1351 370 foreach my $val (values %$data) {
1352 2948 ▶ if (ref($val) and !exists $seen->{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val and not exists $seen->{$val}) 625 2323 2948
Condition100%3/3
ref $val and not exists $seen->{$val}
!ll&&!rl&&r
1716607625
MC/DC100%2/2
ref $val and not exists $seen->{$val}
ref $val not exists $seen->{$val}
Truth table100%3/3
A and not(B)
A= ref $valB= not exists $seen->{$val}
ABresult
0X0
100
111
1353 625 _traverse_data($val,$sub,$seen,$hashes_only);
1354 }
1355 }
1356 }
1357 }
1358  
1359  
1360  
1361 =back
1362  
1363 =head1 CLASSES FOR TYPE DECLARATIONS
1364  
1365 =over 3
1366  
1367 =item L<Treex::PML::Schema::Decl>
1368  
1369 =item L<Treex::PML::Schema::Root>
1370  
1371 =item L<Treex::PML::Schema::Type>
1372  
1373 =item L<Treex::PML::Schema::Struct>
1374  
1375 =item L<Treex::PML::Schema::Container>
1376  
1377 =item L<Treex::PML::Schema::Seq>
1378  
1379 =item L<Treex::PML::Schema::List>
1380  
1381 =item L<Treex::PML::Schema::Alt>
1382  
1383 =item L<Treex::PML::Schema::Choice>
1384  
1385 =item L<Treex::PML::Schema::CDATA>
1386  
1387 =item L<Treex::PML::Schema::Constant>
1388  
1389 =item L<Treex::PML::Schema::Member>
1390  
1391 =item L<Treex::PML::Schema::Element>
1392  
1393 =item L<Treex::PML::Schema::Attribute>
1394  
1395 =back
1396  
1397 =cut
1398  
1399 9 1;
1400  
1401 __END__
« PML/Backend/Storable.pm ↑ Summary PML/Backend/PML.pm »