PML/Instance/Reader.pm

filter: Statementstmt 70.7% 509 / 719 Branchbran 52.6% 202 / 384 Conditioncond 37.5% 129 / 344 MC/DCmcdc 16.5% 31 / 187 Subroutinesub 82.0% 41 / 50 Podpod 0.0% 0 / 14 totaltotal 53.7% 912 / 1698 CC 324 SCAR 70.3
CC
324
Cov
58%
load
3714.3
__ANON__
422.4
read_header
91.7
CRAP 1126.2
« PML/Backend/CSTS/Fs2csts.pm ↑ Summary PML/Backend/CSTS/Csts2fs.pm »
1 package Treex::PML::Instance::Reader;
2 {
3 9 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶no warnings qw(recursion);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 our $VERSION = '2.29'; # version template
15 }
16 9 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use Treex::PML::Instance::Common qw(:diagnostics :constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use Treex::PML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use XML::LibXML::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use Treex::PML::IO qw(open_uri close_uri rename_uri);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 9 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 XAT_TYPE => 0,
26 XAT_NAME => 1,
27 XAT_VALUE => 1,
28 XAT_NS => 2,
29 XAT_ATTRS => 3,
30 XAT_CHILDREN => 5,
31 XAT_LINE => 4,
32 9 };
33  
34 9 our $STRICT =1;
35 9 our $XTC_FLAGS;
36 9 ▶use vars qw( $HAVE_XS );
Subroutine BEGIN: called CC=1 SCAR=0.0
37 9 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=13.6
38 9 ▶ if (!$ENV{PML_COMPILE_NO_XS} && eval {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ENV{'PML_COMPILE_NO_XS'} and eval { do { require XML::CompactTree::XS; 'XML::CompactTree::XS'->import; $Treex::PML::Instance::Reader::HAVE_XS = 1; 1 } }) { } 0 9 9
Condition33%1/3
not $ENV{"PML_COMPILE_NO_XS"} and eval { do { require XML::CompactTree::XS; "XML::CompactTree::XS"->import; $Treex::PML::Instance::Reader::HAVE_XS = 1; 1 } }
!ll&&!rl&&r
090
MC/DC0%0/2
not $ENV{"PML_COMPILE_NO_XS"} and eval { do { require XML::CompactTree::XS; "XML::CompactTree::XS"->import; $Treex::PML::Instance::Reader::HAVE_XS = 1; 1 } }
not $ENV{"PML_COMPILE_NO_XS"} eval { do { require XML::CompactTree::XS; "XML::CompactTree::XS"->import; $Treex::PML::Instance::Reader::HAVE_XS = 1; 1 } }
Truth table33%1/3
not(A) and B
A= not $ENV{"PML_COMPILE_NO_XS"}B= eval { do { require XML::CompactTree::XS; "XML::CompactTree::XS"->import; $Treex::PML::Instance::Reader::HAVE_XS = 1; 1 } }
ABresult
0X0
100
111
39 9 require XML::CompactTree::XS;
40 0 import XML::CompactTree::XS;
41 0 $HAVE_XS = 1;
42 0 1;
43 }) {
44 # print STDERR "Using XML::CompactTree::XS\n" if $HAVE_XS;
45 0 $XTC_FLAGS = XML::CompactTree::XS::XCT_ATTRIBUTE_ARRAY()|
46 XML::CompactTree::XS::XCT_LINE_NUMBERS()|
47 XML::CompactTree::XS::XCT_IGNORE_COMMENTS();
48 } else {
49 9 require XML::CompactTree;
50 9 import XML::CompactTree;
51 9 $XTC_FLAGS = XML::CompactTree::XCT_ATTRIBUTE_ARRAY()|
52 XML::CompactTree::XCT_LINE_NUMBERS()|
53 XML::CompactTree::XCT_IGNORE_COMMENTS();
54 9 $HAVE_XS = 0;
55 }
56 }
57  
58 9 my (%handlers,%src,
59 %handler_cache,@handler_cache,
60 %schema_cache,@schema_cache
61 );
62  
63 # TODO:
64 # - create one handler per cdata+format type
65 # - test inline schemas
66  
67 9 our $CACHE_HANDLERS=1;
68 9 our $CACHE_SCHEMAS=1;
69 9 our $MAX_SCHEMA_CACHE_SIZE=50;
70  
71 9 our $VALIDATE_CDATA=0;
72 9 our $VALIDATE_SEQUENCES=1;
73 9 our $BUILD_TREES = 1;
74 9 our $LOAD_REFFILES = 1;
75 9 our $KNIT = 1;
76  
77 9 our $READER_OPTS = {
78 no_cdata => 1,
79 clean_namespaces => 1,
80 expand_entities => 1,
81 expand_xinclude => 1,
82 no_xinclude_nodes => 1,
83 };
84  
85 9 require Treex::PML;
86  
87 65 ▶sub _get_handlers_cache_key {
Subroutine _get_handlers_cache_key: called CC=6 SCAR=20.3
88 65 my ($schema)=@_;
89 65 my $key="$schema"; $key=~s/.*=//; # strip class
90 return
91 [
92 65 ▶ $key,
Condition50%5/10
$Treex::PML::Instance::Reader::VALIDATE_CDATA || 0
l!l
065
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES || 0
l!l
650
$Treex::PML::Instance::Reader::BUILD_TREES || 0
l!l
650
$Treex::PML::Instance::Reader::LOAD_REFFILES || 0
l!l
650
$Treex::PML::Instance::Reader::KNIT || 0
l!l
650
MC/DC0%0/1
$Treex::PML::Instance::Reader::VALIDATE_CDATA || 0
$Treex::PML::Instance::Reader::VALIDATE_CDATA
MC/DC0%0/1
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES || 0
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES
MC/DC0%0/1
$Treex::PML::Instance::Reader::BUILD_TREES || 0
$Treex::PML::Instance::Reader::BUILD_TREES
MC/DC0%0/1
$Treex::PML::Instance::Reader::LOAD_REFFILES || 0
$Treex::PML::Instance::Reader::LOAD_REFFILES
MC/DC0%0/1
$Treex::PML::Instance::Reader::KNIT || 0
$Treex::PML::Instance::Reader::KNIT
Truth table50%1/2
A
A= $Treex::PML::Instance::Reader::VALIDATE_CDATA
Aresult
11
00
Truth table50%1/2
A
A= $Treex::PML::Instance::Reader::VALIDATE_SEQUENCES
Aresult
11
00
Truth table50%1/2
A
A= $Treex::PML::Instance::Reader::BUILD_TREES
Aresult
11
00
Truth table50%1/2
A
A= $Treex::PML::Instance::Reader::LOAD_REFFILES
Aresult
11
00
Truth table50%1/2
A
A= $Treex::PML::Instance::Reader::KNIT
Aresult
11
00
93 join ',',
94 $key,
95 $VALIDATE_CDATA || 0,
96 $VALIDATE_SEQUENCES || 0,
97 $BUILD_TREES || 0,
98 $LOAD_REFFILES || 0,
99 $KNIT || 0,
100 $Treex::PML::Node::TYPE,
101 $Treex::PML::Node::lbrother,
102 $Treex::PML::Node::rbrother,
103 $Treex::PML::Node::parent,
104 $Treex::PML::Node::firstson,
105 ];
106 }
107  
108 65 ▶sub _get_schema_cache_key {
Subroutine _get_schema_cache_key: called CC=6 SCAR=20.5
109 65 my ($schema_file)=@_;
110 65 ▶ if ((blessed($schema_file) and $schema_file->isa('URI'))) { # assume URI
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($schema_file) and $schema_file->isa("URI")) 65 0 65
Condition33%1/3
builtin::blessed($schema_file) and $schema_file->isa("URI")
!ll&&!rl&&r
0065
MC/DC0%0/2
builtin::blessed($schema_file) and $schema_file->isa("URI")
builtin::blessed($schema_file) $schema_file->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($schema_file)B= $schema_file->isa("URI")
ABresult
0X0
100
111
111 65 ▶ if (($schema_file->scheme||'') eq 'file') {
Branch: 1 branch
BranchTrueFalseTotal
if (($schema_file->scheme || '') eq 'file') { } 65 0 65
Condition50%1/2
$schema_file->scheme || ''
l!l
650
MC/DC0%0/1
$schema_file->scheme || ''
$schema_file->scheme
Truth table50%1/2
A
A= $schema_file->scheme
Aresult
11
00
112 65 $schema_file = $schema_file->file
113 } else {
114 0 return '0 '.$schema_file;
115 }
116 }
117 65 ▶ if (-f $schema_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $schema_file) 65 0 65
118 65 my $mtime = (stat $schema_file)[9];
119 65 return $mtime.' '.$schema_file;
120 }
121 }
122  
123 65 ▶sub get_cached_schema {
Subroutine get_cached_schema: called CC=4 SCAR=13.9
Pod undocumented
124 65 my ($schema_file)=@_;
125 65 ▶ return unless defined $schema_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $schema_file 0 65 65
126 65 my $cached = $schema_cache{$schema_file};
127 65 ▶ if ($cached and $schema_cache[-1] ne $schema_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached and $schema_cache[-1] ne $schema_file) 14 51 65
Condition100%3/3
$cached and $schema_cache[-1] ne $schema_file
!ll&&!rl&&r
282314
MC/DC100%2/2
$cached and $schema_cache[-1] ne $schema_file
$cached $schema_cache[-1] ne $schema_file
Truth table100%3/3
A and B
A= $cachedB= $schema_cache[-1] ne $schema_file
ABresult
0X0
100
111
128 # move the last retrieved schema to the end of the queue
129 14 @schema_cache = ((grep { $_ ne $schema_file } @schema_cache),$schema_file);
130 }
131 65 return $cached;
132 }
133  
134 28 ▶sub cache_schema {
Subroutine cache_schema: called CC=3 SCAR=16.8
Pod undocumented
135 28 my ($key,$schema)=@_;
136 28 push @schema_cache,$key;
137 28 $schema_cache{$key} = $schema;
138 28 ▶ if (@schema_cache > $MAX_SCHEMA_CACHE_SIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if (@schema_cache > $Treex::PML::Instance::Reader::MAX_SCHEMA_CACHE_SIZE) 0 28 28
139 0 my $del = delete $schema_cache{ shift @schema_cache };
140 0 delete $handler_cache{ $del }; # delete also from the handler cache
141 0 @handler_cache = grep { $_->[0] ne $del } @handler_cache;
142 0 ▶ if (exists &Treex::PML::Instance::Writer::forget_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists &Treex::PML::Instance::Writer::forget_schema) 0 0 0
143 0 Treex::PML::Instance::Writer::forget_schema($schema);
144 }
145 }
146 }
147  
148 65 ▶sub get_cached_handlers {
Subroutine get_cached_handlers: called CC=3 SCAR=11.0
Pod undocumented
149 65 my ($key)=@_;
150 65 my $subkey = $key->[1];
151 65 my $cached = $handler_cache{ $key->[0] }{ $subkey };
152 65 ▶ if ($cached and $handler_cache[-1][1] ne $subkey) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached and $handler_cache[-1][1] ne $subkey) 14 51 65
Condition100%3/3
$cached and $handler_cache[-1][1] ne $subkey
!ll&&!rl&&r
282314
MC/DC100%2/2
$cached and $handler_cache[-1][1] ne $subkey
$cached $handler_cache[-1][1] ne $subkey
Truth table100%3/3
A and B
A= $cachedB= $handler_cache[-1][1] ne $subkey
ABresult
0X0
100
111
153 # move the last retrieved schema to the end of the queue
154 14 @handler_cache = ((grep { $_->[1] ne $subkey } @handler_cache),$key);
155 }
156 65 return $cached;
157 }
158  
159 28 ▶sub cache_handlers {
Subroutine cache_handlers: called CC=2 SCAR=7.6
Pod undocumented
160 28 my ($key,$handlers)=@_;
161 28 my $subkey = $key->[1];
162 28 push @handler_cache,$key;
163 28 $handler_cache{$key->[0]}{$subkey} = $handlers;
164 28 ▶ if (@handler_cache > $MAX_SCHEMA_CACHE_SIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if (@handler_cache > $Treex::PML::Instance::Reader::MAX_SCHEMA_CACHE_SIZE) 0 28 28
165 0 my $del = shift @handler_cache;
166 0 delete $handler_cache{ $del->[0] }{ $del->[1] };
167 }
168 }
169  
170 65 ▶sub load {
Subroutine load: called CC=99 SCAR=82.2
Pod undocumented
171 65 my $ctxt = shift;
172 65 my $opts = shift;
173 65 ▶ if (ref($opts) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts ne "HASH") 0 65 65
174 0 croak("Usage: Treex::PML::Instance->load({option=>value,...})\n");
175 }
176 65 ▶ if (!ref($ctxt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ctxt) 37 28 65
177 37 $ctxt = Treex::PML::Factory->createPMLInstance;
178 }
179 65 my $config = $opts->{config};
180 65 ▶ if ($config and ref(my $load_opts = $config->get_data('options/load'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config and ref(my $load_opts = $config->get_data("options/load"))) 0 65 65
Condition66%2/3
$config and ref(my $load_opts = $config->get_data("options/load"))
!ll&&!rl&&r
43220
MC/DC0%0/2
$config and ref(my $load_opts = $config->get_data("options/load"))
$config ref(my $load_opts = $config->get_data("options/load"))
Truth table66%2/3
A and B
A= $configB= ref(my $load_opts = $config->get_data("options/load"))
ABresult
0X0
100
111
181 0 $opts = {%$load_opts, %$opts};
182 }
183 65 ▶ $Treex::PML::Instance::DEBUG = $config->get_data('options/debug') if (!$Treex::PML::Instance::DEBUG and $config and defined($config->get_data('options/debug')));
Branch: 1 branch
BranchTrueFalseTotal
if not $Treex::PML::Instance::DEBUG and $config and defined $config->get_data("options/debug") 0 65 65
Condition66%4/6
not $Treex::PML::Instance::DEBUG and $config and defined $config->get_data("options/debug")
!ll&&!rl&&r
43220
not $Treex::PML::Instance::DEBUG and $config
!ll&&!rl&&r
04322
MC/DC0%0/3
not $Treex::PML::Instance::DEBUG and $config and defined $config->get_data("options/debug")
not $Treex::PML::Instance::DEBUG $config defined $config->get_data("options/debug")
Truth table50%2/4
not(A) and B and C
A= not $Treex::PML::Instance::DEBUGB= $configC= defined $config->get_data("options/debug")
ABCresult
0XX0
10X0
1100
1111
184  
185 65 ▶ local $READER_OPTS = { %$READER_OPTS, %{$opts->{parser_options} || {}} };
Condition50%1/2
$opts->{'parser_options'} || {}
l!l
065
MC/DC0%0/1
$opts->{'parser_options'} || {}
$opts->{'parser_options'}
Truth table50%1/2
A
A= $opts->{'parser_options'}
Aresult
11
00
186  
187 65 ▶ if (exists $opts->{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"filename"}) 65 0 65
188 $ctxt->set_filename( $opts->{use_resources}
189 ? Treex::PML::FindInResourcePaths($opts->{filename})
190 : $opts->{filename}
191 65 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'use_resources'} ? : 19 46 65
192 }
193 65 my $reader;
194 my $fh_to_close;
195 # print Dumper($opts),"\n";
196 65 ▶ if (defined $opts->{dom}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $opts->{'dom'}) { } 1 64 65
elsif (defined $opts->{'fh'}) { } 22 42 64
elsif (defined $opts->{'string'}) { } 9 33 42
elsif (defined $ctxt->{'_filename'}) { } 33 0 33
197 1 $reader = XML::LibXML::Reader->new(DOM => delete $opts->{dom}, %$READER_OPTS);
198 } elsif (defined $opts->{fh}) {
199 $reader = XML::LibXML::Reader->new(IO => $opts->{fh}, %$READER_OPTS,
200 22 URI => $ctxt->{'_filename'},
201 %$READER_OPTS
202 );
203 } elsif (defined $opts->{string}) {
204 $reader = XML::LibXML::Reader->new(string => $opts->{string}, %$READER_OPTS,
205 9 URI => $ctxt->{'_filename'},
206 %$READER_OPTS
207 );
208 } elsif (defined $ctxt->{_filename}) {
209 33 ▶ if ($ctxt->{_filename} eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctxt->{'_filename'} eq '-') { } 0 33 33
210 0 $reader = XML::LibXML::Reader->new(FD => \*STDIN,
211 %$READER_OPTS,
212 );
213 } else {
214 33 $fh_to_close = open_uri($ctxt->{_filename});
215 $reader = XML::LibXML::Reader->new(FD => $fh_to_close,
216 URI => $ctxt->{_filename},
217 33 %$READER_OPTS,
218 );
219 }
220 } else {
221 0 croak("Treex::PML::Instance->load: at least one of filename, fh, string, or dom arguments are required!");
222 }
223 65 eval {
224 # check NS
225 65 $reader->nextElement();
226 my @transform_map =
227 grep {
228 0 my $id = $_->{id};
229 0 ▶ if (defined($id) and length($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length $id) { } 0 0 0
Condition0%0/3
defined $id and length $id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table0%0/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
230 0 $_
231 } else {
232 0 warn(__PACKAGE__.": Skipping PML transform in ".$config->get_url." (required attribute id missing):".Dumper($_));
233 ()
234 0 }
235 }
236 65 (eval {
237 ($config and $config->get_root) ? $config->get_root->{transform_map}->values : ()
238 65 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
$config && $config->get_root ? : 22 43 65
Condition66%2/3
$config and $config->get_root
!ll&&!rl&&r
43022
MC/DC50%1/2
$config and $config->get_root
$config $config->get_root
Truth table66%2/3
A and B
A= $configB= $config->get_root
ABresult
0X0
100
111
239 65 my $root_element = $reader->localName;
240 65 ▶ my $root_ns = $reader->namespaceURI || '';
Condition50%1/2
$reader->namespaceURI || ''
l!l
650
MC/DC0%0/1
$reader->namespaceURI || ''
$reader->namespaceURI
Truth table50%1/2
A
A= $reader->namespaceURI
Aresult
11
00
241 65 ▶ if ($root_ns ne PML_NS
Branch: 1 branch
BranchTrueFalseTotal
if ($root_ns ne "http://ufal.mff.cuni.cz/pdt/pml/" or grep {($_->{"ns"} || "") eq "http://ufal.mff.cuni.cz/pdt/pml/" and ($_->{"root"} || "") eq $root_element;} @transform_map) 0 65 65
Condition33%1/3
$root_ns ne "http://ufal.mff.cuni.cz/pdt/pml/" or grep {($_->{"ns"} || "") eq "http://ufal.mff.cuni.cz/pdt/pml/" and ($_->{"root"} || "") eq $root_element;} @transform_map
l!l&&r!l&&!r
0065
MC/DC0%0/2
$root_ns ne "http://ufal.mff.cuni.cz/pdt/pml/" or grep {($_->{"ns"} || "") eq "http://ufal.mff.cuni.cz/pdt/pml/" and ($_->{"root"} || "") eq $root_element;} @transform_map
$root_ns ne "http://ufal.mff.cuni.cz/pdt/pml/" grep {($_->{"ns"} || "") eq "http://ufal.mff.cuni.cz/pdt/pml/" and ($_->{"root"} || "") eq $root_element;} @transform_map
Truth table33%1/3
A or B
A= $root_ns ne "http://ufal.mff.cuni.cz/pdt/pml/"B= grep {($_->{"ns"} || "") eq "http://ufal.mff.cuni.cz/pdt/pml/" and ($_->{"root"} || "") eq $root_element;} @transform_map
ABresult
1X1
011
000
242 0 ▶ or grep { (($_->{ns}||'') eq PML_NS and ($_->{root}||'') eq $root_element) } @transform_map) {
Condition0%0/7
($_->{'ns'} || '') eq 'http://ufal.mff.cuni.cz/pdt/pml/' && ($_->{'root'} || '') eq $root_element
!ll&&!rl&&r
000
$_->{'ns'} || ''
l!l
00
$_->{'root'} || ''
l!l
00
MC/DC0%0/2
($_->{'ns'} || '') eq 'http://ufal.mff.cuni.cz/pdt/pml/' && ($_->{'root'} || '') eq $root_element
$_->{'ns'} $_->{'root'}
Truth table0%0/3
A && B
A= $_->{'ns'}B= $_->{'root'}
ABresult
0X0
100
111
243 0 ▶ if ($config and $config->get_root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config and $config->get_root) 0 0 0
Condition0%0/3
$config and $config->get_root
!ll&&!rl&&r
000
MC/DC0%0/2
$config and $config->get_root
$config $config->get_root
Truth table0%0/3
A and B
A= $configB= $config->get_root
ABresult
0X0
100
111
244 # TRANSFORM
245 0 $reader->preserveNode;
246 0 $reader->finish;
247 0 my $dom = $reader->document;
248 0 foreach my $transform (@transform_map) {
249 0 my $id = $transform->{'id'};
250 0 my ($in_xsl) = $transform->{in};
251 0 ▶ my $type = $in_xsl && $in_xsl->{'type'};
Condition0%0/3
$in_xsl && $in_xsl->{'type'}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_xsl && $in_xsl->{'type'}
$in_xsl $in_xsl->{'type'}
Truth table0%0/3
A && B
A= $in_xslB= $in_xsl->{'type'}
ABresult
0X0
100
111
252 0 ▶ next unless ($type and $type =~ /^(?:xslt|perl|pipe|shell)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $type and $type =~ /^(?:xslt|perl|pipe|shell)$/ 0 0 0
Condition0%0/3
$type and $type =~ /^(?:xslt|perl|pipe|shell)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$type and $type =~ /^(?:xslt|perl|pipe|shell)$/
$type $type =~ /^(?:xslt|perl|pipe|shell)$/
Truth table0%0/3
A and B
A= $typeB= $type =~ /^(?:xslt|perl|pipe|shell)$/
ABresult
0X0
100
111
253 0 my $test = $transform->{'test'};
254 0 _debug("Trying transformation rule '$id'");
255 0 ▶ if (($test or $transform->{ns} or $transform->{root})
Branch: 1 branch
BranchTrueFalseTotal
if ($test || $transform->{'ns'} || $transform->{'root'} and !$transform->{'ns'} || $transform->{'ns'} eq $root_ns and !$transform->{'root'} || $transform->{'root'} eq $root_element and not $test or eval { do { $dom->find($test) } }) { } 0 0 0
Condition0%0/24
$test || $transform->{"ns"} || $transform->{"root"} and !$transform->{"ns"} || $transform->{"ns"} eq $root_ns and !$transform->{"root"} || $transform->{"root"} eq $root_element and not $test or eval { do { $dom->find($test) } }
l!l&&r!l&&!r
000
$test || $transform->{"ns"} || $transform->{"root"} and !$transform->{"ns"} || $transform->{"ns"} eq $root_ns and !$transform->{"root"} || $transform->{"root"} eq $root_element and not $test
!ll&&!rl&&r
000
$test || $transform->{"ns"} || $transform->{"root"} and !$transform->{"ns"} || $transform->{"ns"} eq $root_ns and !$transform->{"root"} || $transform->{"root"} eq $root_element
!ll&&!rl&&r
000
$test || $transform->{"ns"} || $transform->{"root"} and !$transform->{"ns"} || $transform->{"ns"} eq $root_ns
!ll&&!rl&&r
000
$test or $transform->{"ns"} or $transform->{"root"}
l!l&&r!l&&!r
000
$test or $transform->{"ns"}
l!l&&r!l&&!r
000
not $transform->{"ns"} or $transform->{"ns"} eq $root_ns
l!l&&r!l&&!r
000
not $transform->{"root"} or $transform->{"root"} eq $root_element
l!l&&r!l&&!r
000
MC/DC0%0/9
$test || $transform->{"ns"} || $transform->{"root"} and !$transform->{"ns"} || $transform->{"ns"} eq $root_ns and !$transform->{"root"} || $transform->{"root"} eq $root_element and not $test or eval { do { $dom->find($test) } }
$test $transform->{"ns"} $transform->{"root"} not $transform->{"ns"} $transform->{"ns"} eq $root_ns not $transform->{"root"} $transform->{"root"} eq $root_element not $test eval { do { $dom->find($test) } }
Truth table0%0/56
A or B or C and not(D) or E and not(F) or G and not(H) or I
A= $testB= $transform->{"ns"}C= $transform->{"root"}D= not $transform->{"ns"}E= $transform->{"ns"} eq $root_nsF= not $transform->{"root"}G= $transform->{"root"} eq $root_elementH= not $testI= eval { do { $dom->find($test) } }
ABCDEFGHIresult
1XX1X1X1X1
1XX1X011X1
1XX011X1X1
1XX01011X1
01X1X1X1X1
01X1X011X1
01X011X1X1
01X01011X1
0011X1X1X1
0011X011X1
001011X1X1
00101011X1
000XXXXX11
1XX00XXX11
01X00XXX11
00100XXX11
1XX1X00X11
1XX0100X11
01X1X00X11
01X0100X11
0011X00X11
0010100X11
1XX1X1X011
1XX1X01011
1XX011X011
1XX0101011
01X1X1X011
01X1X01011
01X011X011
01X0101011
0011X1X011
0011X01011
001011X011
0010101011
000XXXXX00
1XX00XXX00
01X00XXX00
00100XXX00
1XX1X00X00
1XX0100X00
01X1X00X00
01X0100X00
0011X00X00
0010100X00
1XX1X1X000
1XX1X01000
1XX011X000
1XX0101000
01X1X1X000
01X1X01000
01X011X000
01X0101000
0011X1X000
0011X01000
001011X000
0010101000
256 and (!$transform->{ns} or $transform->{ns} eq $root_ns)
257 and (!$transform->{root} or $transform->{root} eq $root_element)
258 0 and !$test or eval { $dom->find($test) }) {
259 0 ▶ if ($type eq 'xslt') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'xslt') { } 0 0 0
elsif ($type eq 'perl') { } 0 0 0
elsif ($type eq 'pipe' or $type eq 'shell') { } 0 0 0
260 0 ▶ die "Buggy libxslt version 10127\n" if XSLT_BUG;
Branch: 1 branch
BranchTrueFalseTotal
if XSLT_BUG() 0 0 0
261 0 ▶ if (eval { require XML::LibXSLT; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require XML::LibXSLT; 1 } }) { } 0 0 0
262 0 my $in_xsl_href = URI->new(Encode::encode_utf8($in_xsl->get_member('href')));
263 0 ▶ next unless $in_xsl_href;
Branch: 1 branch
BranchTrueFalseTotal
unless $in_xsl_href 0 0 0
264 0 _debug("Transforming to PML with XSLT '$in_xsl_href'");
265 0 $ctxt->{'_transform_id'} = $id;
266 0 my $params = $in_xsl->content;
267 0 my %params;
268 0 ▶ %params = map { $_->{'name'} => $_->value } $params->values if $params;
Branch: 1 branch
BranchTrueFalseTotal
if $params 0 0 0
269 0 $in_xsl_href = Treex::PML::ResolvePath($config->{'_filename'}, $in_xsl_href, 1);
270 0 my $xslt = XML::LibXSLT->new;
271 0 ▶ my $in_xsl_parsed = $xslt->parse_stylesheet_file($in_xsl_href)
Condition0%0/2
$xslt->parse_stylesheet_file($in_xsl_href) || die("Cannot locate XSL stylesheet '${in_xsl_href}' for transformation $id\n")
l!l
00
MC/DC0%0/1
$xslt->parse_stylesheet_file($in_xsl_href) || die("Cannot locate XSL stylesheet '${in_xsl_href}' for transformation $id\n")
$xslt->parse_stylesheet_file($in_xsl_href)
Truth table0%0/2
A
A= $xslt->parse_stylesheet_file($in_xsl_href)
Aresult
11
00
272 || die("Cannot locate XSL stylesheet '$in_xsl_href' for transformation $id\n");
273 0 $dom = $in_xsl_parsed->transform($dom,%params);
274 0 ▶ $dom->setBaseURI($ctxt->{'_filename'}) if $dom and $dom->can('setBaseURI');
Branch: 1 branch
BranchTrueFalseTotal
if $dom and $dom->can("setBaseURI") 0 0 0
Condition0%0/3
$dom and $dom->can("setBaseURI")
!ll&&!rl&&r
000
MC/DC0%0/2
$dom and $dom->can("setBaseURI")
$dom $dom->can("setBaseURI")
Truth table0%0/3
A and B
A= $domB= $dom->can("setBaseURI")
ABresult
0X0
100
111
275 0 ▶ $dom->setURI($ctxt->{'_filename'}) if $dom and $dom->can('setURI');
Branch: 1 branch
BranchTrueFalseTotal
if $dom and $dom->can("setURI") 0 0 0
Condition0%0/3
$dom and $dom->can("setURI")
!ll&&!rl&&r
000
MC/DC0%0/2
$dom and $dom->can("setURI")
$dom $dom->can("setURI")
Truth table0%0/3
A and B
A= $domB= $dom->can("setURI")
ABresult
0X0
100
111
276 0 $reader = XML::LibXML::Reader->new(DOM => $dom);
277 0 $reader->nextElement();
278 0 last;
279 } else {
280 0 warn "Cannot use XML::LibXSLT for transformation!\n";
281 }
282 } elsif ($type eq 'perl') {
283 0 my $code = $in_xsl->get_member('command');
284 0 ▶ next unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
285 0 _debug("Transforming to PML with Perl code: $code");
286 0 $ctxt->{'_transform_id'} = $id;
287 0 my $params = $in_xsl->content;
288 0 my %params;
289 0 ▶ %params = map { $_->{'name'} => $_->value } $params->values if $params;
Branch: 1 branch
BranchTrueFalseTotal
if $params 0 0 0
290 0 $dom = perl_transform($code, $dom, %params);
291 0 ▶ die("Perl-based transformation '$id' failed: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
292 0 ▶ die("Perl-based transformation didn't return a XML::LibXML::Document object!\n") unless
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($dom) and $dom->isa("XML::LibXML::Document") 0 0 0
Condition0%0/3
builtin::blessed($dom) and $dom->isa("XML::LibXML::Document")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($dom) and $dom->isa("XML::LibXML::Document")
builtin::blessed($dom) $dom->isa("XML::LibXML::Document")
Truth table0%0/3
A and B
A= builtin::blessed($dom)B= $dom->isa("XML::LibXML::Document")
ABresult
0X0
100
111
293 (blessed($dom) and $dom->isa('XML::LibXML::Document'));
294 0 ▶ $dom->setBaseURI($ctxt->{'_filename'}) if $dom and $dom->can('setBaseURI');
Branch: 1 branch
BranchTrueFalseTotal
if $dom and $dom->can("setBaseURI") 0 0 0
Condition0%0/3
$dom and $dom->can("setBaseURI")
!ll&&!rl&&r
000
MC/DC0%0/2
$dom and $dom->can("setBaseURI")
$dom $dom->can("setBaseURI")
Truth table0%0/3
A and B
A= $domB= $dom->can("setBaseURI")
ABresult
0X0
100
111
295 0 ▶ $dom->setURI($ctxt->{'_filename'}) if $dom and $dom->can('setURI');
Branch: 1 branch
BranchTrueFalseTotal
if $dom and $dom->can("setURI") 0 0 0
Condition0%0/3
$dom and $dom->can("setURI")
!ll&&!rl&&r
000
MC/DC0%0/2
$dom and $dom->can("setURI")
$dom $dom->can("setURI")
Truth table0%0/3
A and B
A= $domB= $dom->can("setURI")
ABresult
0X0
100
111
296 0 $reader = XML::LibXML::Reader->new(DOM => $dom);
297 0 $reader->nextElement();
298 0 last;
299 ▶ } elsif ($type eq 'pipe' or $type eq 'shell') {
Condition0%0/3
$type eq "pipe" or $type eq "shell"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "pipe" or $type eq "shell"
$type eq "pipe" $type eq "shell"
Truth table0%0/3
A or B
A= $type eq "pipe"B= $type eq "shell"
ABresult
1X1
011
000
300 0 my $code = $in_xsl->get_member('command');
301 0 ▶ next unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
302 0 _debug("Transforming to PML with $type code: $code");
303 0 $ctxt->{'_transform_id'} = $id;
304 0 my $params = $in_xsl->content;
305 0 my @params;
306 0 ▶ @params = grep {defined and length } map { $_->{'name'} => $_->value } $params->values if $params;
Branch: 1 branch
BranchTrueFalseTotal
if $params 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
307 0 my $tmp_file_in;
308 0 ▶ if ($type eq 'pipe') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'pipe') { } 0 0 0
309 0 (my $fh, $tmp_file_in) = File::Temp::tempfile();
310 0 $dom->toFH($fh);
311 0 close $fh;
312 } else {
313 0 push @params, $dom->URI;
314 }
315 0 my $tmp_file_out;
316 {
317 0 local *OLDIN;
318 0 local *OLDOUT;
319 0 open OLDOUT,"<&STDOUT";
320 0 open OLDIN,"<&STDIN";
321  
322 0 ▶ if ($type eq 'pipe') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'pipe') { } 0 0 0
323 0 open STDIN, '<', $tmp_file_in;
324 } else {
325 0 close STDIN;
326 }
327 0 (undef, $tmp_file_out) = File::Temp::tempfile();
328 0 open STDOUT, '>', $tmp_file_out;
329 0 system($code,@params);
330 0 ▶ unlink $tmp_file_in if $tmp_file_in;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp_file_in 0 0 0
331 0 open STDIN,"<&OLDIN";
332 0 open STDOUT,">&OLDOUT";
333 }
334 {
335 0 ▶ open(my $fh, '<', $tmp_file_out) or die("Failed to read output from pipe transformation: $code\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $tmp_file_out or die "Failed to read output from pipe transformation: $code\n" 0 0 0
336 0 ▶ unlink $tmp_file_out if $tmp_file_out;
Branch: 1 branch
BranchTrueFalseTotal
if $tmp_file_out 0 0 0
337 0 $reader = XML::LibXML::Reader->new(IO => $fh, URI => $ctxt->{'_filename'});
338 }
339 0 $reader->nextElement();
340 0 last;
341 }
342 } else {
343 0 _debug("failed");
344 }
345 }
346 }
347 0 ▶ if (($reader->namespaceURI||'') ne PML_NS) {
Branch: 1 branch
BranchTrueFalseTotal
if (($reader->namespaceURI || "") ne "http://ufal.mff.cuni.cz/pdt/pml/") 0 0 0
Condition0%0/2
$reader->namespaceURI || ''
l!l
00
MC/DC0%0/1
$reader->namespaceURI || ''
$reader->namespaceURI
Truth table0%0/2
A
A= $reader->namespaceURI
Aresult
11
00
348 0 ▶ my $f = $ctxt->{'_filename'} || '';
Condition0%0/2
$ctxt->{'_filename'} || ''
l!l
00
MC/DC0%0/1
$ctxt->{'_filename'} || ''
$ctxt->{'_filename'}
Truth table0%0/2
A
A= $ctxt->{'_filename'}
Aresult
11
00
349 0 ▶ die("Root element of '$f' isn't in PML namespace: '".($reader->localName()||'')."' ".($reader->namespaceURI()||''))
Condition0%0/4
$reader->localName || ''
l!l
00
$reader->namespaceURI || ''
l!l
00
MC/DC0%0/1
$reader->localName || ''
$reader->localName
MC/DC0%0/1
$reader->namespaceURI || ''
$reader->namespaceURI
Truth table0%0/2
A
A= $reader->localName
Aresult
11
00
Truth table0%0/2
A
A= $reader->namespaceURI
Aresult
11
00
350 }
351 }
352  
353 65 $ctxt->{_root} = read_header($ctxt,$reader,$opts);
354 65 my $schema = $ctxt->{'_schema'};
355 65 ▶ unless (ref($schema)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $schema) 0 65 65
356 0 die("Instance doesn't provide PML schema!");
357 }
358 65 ▶ unless (length($schema->{version}||'')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length($schema->{"version"} || "")) 0 65 65
Condition50%1/2
$schema->{'version'} || ''
l!l
650
MC/DC0%0/1
$schema->{'version'} || ''
$schema->{'version'}
Truth table50%1/2
A
A= $schema->{'version'}
Aresult
11
00
359 0 die("PML Schema file ".$ctxt->{'_schema-url'}." does not specify version!");
360 }
361 65 ▶ if (index(SUPPORTED_PML_VERSIONS," ".$schema->{version}." ")<0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index(" 1.1 1.2 ", ' ' . $schema->{"version"} . ' ') == -1) 0 65 65
362 0 die("Unsupported PML Schema version ".$schema->{version}." in ".$ctxt->{'_schema-url'});
363 }
364  
365 {
366 # preprocess the options selected_references and selected_keys:
367 # we map the reffile names to reffile id's
368 65 my $sel_knit = ($ctxt->{_selected_knits} =
369 65 $opts->{selected_knits});
370 my $sel_refs = ($ctxt->{_selected_references} =
371 65 $opts->{selected_references});
372 65 ▶ croak("Treex::PML::Instance->load: selected_knits must be a Hash ref!")
Branch: 1 branch
BranchTrueFalseTotal
if defined $sel_knit and ref $sel_knit ne "HASH" 0 65 65
Condition33%1/3
defined $sel_knit and ref $sel_knit ne "HASH"
!ll&&!rl&&r
6500
MC/DC0%0/2
defined $sel_knit and ref $sel_knit ne "HASH"
defined $sel_knit ref $sel_knit ne "HASH"
Truth table33%1/3
A and B
A= defined $sel_knitB= ref $sel_knit ne "HASH"
ABresult
0X0
100
111
373 if defined($sel_knit) && ref($sel_knit) ne 'HASH';
374 65 ▶ croak("Treex::PML::Instance->load: selected_references must be a Hash ref!")
Branch: 1 branch
BranchTrueFalseTotal
if defined $sel_refs and ref $sel_refs ne "HASH" 0 65 65
Condition33%1/3
defined $sel_refs and ref $sel_refs ne "HASH"
!ll&&!rl&&r
6500
MC/DC0%0/2
defined $sel_refs and ref $sel_refs ne "HASH"
defined $sel_refs ref $sel_refs ne "HASH"
Truth table33%1/3
A and B
A= defined $sel_refsB= ref $sel_refs ne "HASH"
ABresult
0X0
100
111
375 if defined($sel_refs) && ref($sel_refs) ne 'HASH';
376 ($ctxt->{'_selected_knits_ids'},
377 $ctxt->{'_selected_references_ids'}) = map {
378 65 my $sel = $_;
379 my $ret = {
380 (defined($sel) ?
381 (map {
382 0 ▶ my $ids = $ctxt->{'_refnames'}->{$_};
Branch: 1 branch
BranchTrueFalseTotal
defined $sel ? : 0 130 130
383 0 my $val = $sel->{$_};
384 0 ▶ map { $_=>$val }
Branch: 2 branches
BranchTrueFalseTotal
defined $ids ? : 0 0 0
ref $ids ? : 0 0 0
385 defined($ids) ? (ref($ids) ? @$ids : ($ids)) : ()
386 } keys %$sel) : ())
387 };
388 130 $ret
389 } ($sel_knit,$sel_refs);
390 }
391  
392 65 $ctxt->read_reffiles({use_resources=>$opts->{use_resources}});
393 65 $ctxt->{'_no_read_trees'} = $opts->{no_trees};
394 65 ▶ local $BUILD_TREES = $opts->{no_trees} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_trees'} ? : 0 65 65
395 65 ▶ local $LOAD_REFFILES = $opts->{no_references} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_references'} ? : 0 65 65
396 65 ▶ local $KNIT = $opts->{no_knit} ? 0 : $LOAD_REFFILES;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_knit'} ? : 0 65 65
397 65 ▶ local $VALIDATE_CDATA =$opts->{validate_cdata} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'validate_cdata'} ? : 0 65 65
398 65 ▶ local $VALIDATE_SEQUENCES =$opts->{ignore_content_patterns} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'ignore_content_patterns'} ? : 0 65 65
399 65 $ctxt->{'_id-hash'}={};
400  
401 65 prepare_handlers($ctxt);
402 65 ▶ dump_handlers($ctxt) if $opts->{dump_handlers} or $ENV{PML_COMPILE_DUMP};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"dump_handlers"} or $ENV{"PML_COMPILE_DUMP"} 0 65 65
Condition33%1/3
$opts->{"dump_handlers"} or $ENV{"PML_COMPILE_DUMP"}
l!l&&r!l&&!r
0065
MC/DC0%0/2
$opts->{"dump_handlers"} or $ENV{"PML_COMPILE_DUMP"}
$opts->{"dump_handlers"} $ENV{"PML_COMPILE_DUMP"}
Truth table33%1/3
A or B
A= $opts->{"dump_handlers"}B= $ENV{"PML_COMPILE_DUMP"}
ABresult
1X1
011
000
403 65 load_data($ctxt,$reader,$opts);
404 65 ▶ while ($reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read) 0 65 65
405 0 ▶ if ($reader->nodeType == XML_READER_TYPE_PROCESSING_INSTRUCTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->nodeType == 7) 0 0 0
406 0 push @{$ctxt->{'_pi'}}, [ $reader->name,$reader->value ];
407 }
408 }
409  
410 65 $handlers{'#initialize'}->($ctxt);
411 65 $ctxt->{_root} = $handlers{'#root'}->($ctxt->{_root});
412 };
413 65 ▶ ($handlers{'#cleanup'}||sub{})->();
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
$handlers{'#cleanup'} || sub { }
l!l&&r!l&&!r
6500
MC/DC0%0/2
$handlers{'#cleanup'} || sub { }
$handlers{'#cleanup'} sub { }
Truth table33%1/3
A || B
A= $handlers{'#cleanup'}B= sub { }
ABresult
1X1
011
000
414 65 %handlers=();
415 65 ▶ close_uri($fh_to_close) if defined $fh_to_close;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fh_to_close 33 32 65
416 65 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 65 65
417 65 $ctxt->{'_parser'} = undef;
418 65 return $ctxt;
419 }
420  
421 ######################################################
422 # $ctxt
423  
424 0 ▶sub _reader_address {
Subroutine _reader_address: not called CC=1 SCAR=6.9
425 0 my ($ctxt,$reader)=@_;
426 0 my $line_number=$reader->lineNumber;
427 0 return " at ".$ctxt->{'_filename'}." line ".$line_number."\n";
428 }
429  
430 65 ▶sub read_header {
Subroutine read_header: called CC=36 SCAR=45.2
Pod undocumented
431 65 my ($ctxt,$reader,$opts)=@_;
432  
433 # manually extract the root node
434 65 my $root = [XML_READER_TYPE_ELEMENT,
435 $reader->localName,
436 undef,
437 ];
438 # read root node attributes
439 65 $root->[XAT_LINE] = 0;
440 65 $root->[XAT_ATTRS] = readAttributes($reader);
441 65 my $found_head = 0;
442 65 ▶ while ($reader->read == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read == 1) 95 0 95
443 95 my $type = $reader->nodeType;
444 95 ▶ if ($type == XML_READER_TYPE_TEXT) { # no CDATA
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 3) { } 0 95 95
elsif ($type == 1) { } 65 30 95
445 0 die "Unexpected content of a root element preceding <head>"._reader_address($ctxt,$reader);
446 } elsif ($type == XML_READER_TYPE_ELEMENT) {
447 65 ▶ if ($reader->localName eq 'head' and $reader->namespaceURI eq PML_NS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->localName eq 'head' and $reader->namespaceURI eq 'http://ufal.mff.cuni.cz/pdt/pml/') { } 65 0 65
Condition33%1/3
$reader->localName eq "head" and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
!ll&&!rl&&r
0065
MC/DC0%0/2
$reader->localName eq "head" and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
$reader->localName eq "head" $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
Truth table33%1/3
A and B
A= $reader->localName eq "head"B= $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
ABresult
0X0
100
111
448 # we have head!
449 65 $found_head = 1;
450 65 last;
451 } else {
452 0 die "Unexpected element '".$reader->name."' precedes PML header <head>"._reader_address($ctxt,$reader);
453 }
454 }
455 }
456 65 ▶ unless ($found_head) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_head) 0 65 65
457 0 die "Did not find PML <head> element: the document '".$ctxt->{_filename}."' is not a PML instance!";
458 }
459  
460 65 my (%references,%named_references);
461 65 ▶ while ($reader->read == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read == 1) 190 0 190
462 190 ▶ last if $reader->depth<=1;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->depth <= 1 65 125 190
463 125 my $type = $reader->nodeType;
464 125 ▶ if ($type == XML_READER_TYPE_ELEMENT and $reader->namespaceURI eq PML_NS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1 and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/") 91 34 125
Condition66%2/3
$type == 1 and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
!ll&&!rl&&r
34091
MC/DC50%1/2
$type == 1 and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
$type == 1 $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
Truth table66%2/3
A and B
A= $type == 1B= $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
ABresult
0X0
100
111
465 91 my $name = $reader->localName;
466 91 ▶ if ($name eq 'schema') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'schema') { } 65 26 91
elsif ($name eq 'references') { } 26 0 26
467 65 ▶ if ($ctxt->{'_schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctxt->{"_schema"}) 0 65 65
468 0 warn "Multiple <schema> elements in a PML <head>!";
469 0 ▶ $reader->nextSibling || last;
Branch: 1 branch
BranchTrueFalseTotal
$reader->nextSibling or last 0 0 0
470 0 redo;
471 }
472 # read schema here:
473 65 ▶ my %a = @{ readAttributes($reader) || [] };
Condition50%1/2
readAttributes($reader) || []
l!l
650
MC/DC0%0/1
readAttributes($reader) || []
readAttributes($reader)
Truth table50%1/2
A
A= readAttributes($reader)
Aresult
11
00
474 65 my $schema_file = delete $a{href};
475 65 ▶ if (defined $schema_file and length $schema_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema_file and length $schema_file) { } 65 0 65
Condition33%1/3
defined $schema_file and length $schema_file
!ll&&!rl&&r
0065
MC/DC0%0/2
defined $schema_file and length $schema_file
defined $schema_file length $schema_file
Truth table33%1/3
A and B
A= defined $schema_fileB= length $schema_file
ABresult
0X0
100
111
476 65 $schema_file = URI->new(Encode::encode_utf8($schema_file));
477 # print "$schema_file\n";
478 65 $ctxt->{'_schema-url'} = $schema_file; # store the original URL, not the resolved one!
479 65 my $schema_path = Treex::PML::ResolvePath($ctxt->{'_filename'},$schema_file,1);
480 65 my $key = _get_schema_cache_key($schema_path);
481 65 ▶ if (!($ctxt->{'_schema'}=get_cached_schema($key))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ctxt->{"_schema"} = get_cached_schema($key)) 28 37 65
482 # print "loading schema $schema_path\n";
483 $ctxt->{'_schema'} =
484 Treex::PML::Factory->createPMLSchema({
485 filename => $schema_path,
486 use_resources => 1,
487 revision_error =>
488 28 "Error: ".$ctxt->{'_filename'}." requires different revision of PML schema %f: %e\n",
489 %a, # revision_opts
490 });
491 28 ▶ cache_schema($key, $ctxt->{'_schema'}) if $CACHE_SCHEMAS;
Branch: 1 branch
BranchTrueFalseTotal
if $Treex::PML::Instance::Reader::CACHE_SCHEMAS 28 0 28
492 }
493 } else {
494 # inline schema
495 $ctxt->{'_schema'} = Treex::PML::Factory->createPMLSchema({
496 reader=>$reader,
497 base_url => $ctxt->{'_filename'},
498 use_resources => 1,
499 revision_error =>
500 0 ▶ "Error: ".($ctxt->{'_filename'}||'document')." requires different revision of PML schema %f: %e\n",
Condition0%0/2
$ctxt->{'_filename'} || 'document'
l!l
00
MC/DC0%0/1
$ctxt->{'_filename'} || 'document'
$ctxt->{'_filename'}
Truth table0%0/2
A
A= $ctxt->{'_filename'}
Aresult
11
00
501 %a, # revision_opts
502 });
503 }
504 } elsif ($name eq 'references') {
505 26 ▶ if ($reader->read) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->read) 26 0 26
506 26 ▶ while ($reader->depth==3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->depth == 3) 41 0 41
507 41 ▶ if ($reader->localName eq 'reffile' and
Branch: 1 branch
BranchTrueFalseTotal
if ($reader->localName eq "reffile" and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/") 33 8 41
Condition66%2/3
$reader->localName eq "reffile" and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
!ll&&!rl&&r
8033
MC/DC50%1/2
$reader->localName eq "reffile" and $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
$reader->localName eq "reffile" $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
Truth table66%2/3
A and B
A= $reader->localName eq "reffile"B= $reader->namespaceURI eq "http://ufal.mff.cuni.cz/pdt/pml/"
ABresult
0X0
100
111
508 $reader->namespaceURI eq PML_NS) {
509 33 ▶ my %a = @{ readAttributes($reader) || [] };
Condition50%1/2
readAttributes($reader) || []
l!l
330
MC/DC0%0/1
readAttributes($reader) || []
readAttributes($reader)
Truth table50%1/2
A
A= readAttributes($reader)
Aresult
11
00
510 33 my ($id,$name,$href) = @a{qw(id name href)};
511 33 ▶ if (defined($id) and length($id) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length $id and defined $href and length $href) { } 33 0 33
Condition33%3/9
defined $id and length $id and defined $href and length $href
!ll&&!rl&&r
0033
defined $id and length $id and defined $href
!ll&&!rl&&r
0033
defined $id and length $id
!ll&&!rl&&r
0033
MC/DC0%0/4
defined $id and length $id and defined $href and length $href
defined $id length $id defined $href length $href
Truth table20%1/5
A and B and C and D
A= defined $idB= length $idC= defined $hrefD= length $href
ABCDresult
0XXX0
10XX0
110X0
11100
11111
512 defined($href) and length($href)) {
513 33 ▶ if (defined $name and length $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 33 0 33
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
0033
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
514 33 my $prev_ids = $named_references{ $name };
515 33 ▶ if (defined $prev_ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_ids) { } 0 33 33
516 0 ▶ if (ref($prev_ids)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $prev_ids) { } 0 0 0
517 0 push @$prev_ids,$id;
518 } else {
519 0 $named_references{ $name }=Treex::PML::Factory->createAlt([$prev_ids,$id],1);
520 }
521 } else {
522 33 $named_references{ $name } = $id;
523 }
524 }
525 # Encode: all filenames must(!) be bytes
526 $references{$id} = Treex::PML::ResolvePath
527 ($ctxt->{'_filename'},
528 URI->new(Encode::encode_utf8($href)),
529 33 $opts->{use_resources});
530 # Resources are not used for non-readas references,
531 # though, they must be handled manually.
532 } else {
533 0 warn "Missing id or href attribute on a <reffile>: ignoring\n";
534 }
535 }
536 41 ▶ $reader->nextSibling || last;
Branch: 1 branch
BranchTrueFalseTotal
$reader->nextSibling or last 15 26 41
537 }
538 }
539 }
540 }
541 }
542 $ctxt->{'_schema'} or
543 65 ▶ die "Did not find <schema> element in PML <head>: the document '".$ctxt->{_filename}."' is not a valid PML instance!";
Branch: 1 branch
BranchTrueFalseTotal
$ctxt->{"_schema"} or die q[Did not find <schema> element in PML <head>: the document '] . $ctxt->{"_filename"} . q[' is not a valid PML instance!] 65 0 65
544 65 $ctxt->{'_references'} = \%references;
545 65 $ctxt->{'_refnames'} = \%named_references;
546 65 return $root;
547 }
548  
549 65 ▶sub prepare_handlers {
Subroutine prepare_handlers: called CC=3 SCAR=11.0
Pod undocumented
550 65 my ($ctxt,$opts)=@_;
551 65 %handlers=();
552 65 my $schema = $ctxt->{'_schema'};
553 65 my $key=_get_handlers_cache_key($schema);
554 65 my $cached = get_cached_handlers($key);
555 65 ▶ if ($cached) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached) { } 37 28 65
556 37 %handlers= @$cached;
557 } else {
558 28 compile_schema($schema);
559 28 ▶ cache_handlers($key,[%handlers]) if $CACHE_HANDLERS;
Branch: 1 branch
BranchTrueFalseTotal
if $Treex::PML::Instance::Reader::CACHE_HANDLERS 28 0 28
560 }
561 }
562  
563 0 ▶sub dump_handlers {
Subroutine dump_handlers: not called CC=5 SCAR=34.0
Pod undocumented
564 0 my $dir = '.pml_compile.d';
565 0 ▶ (-d $dir) || mkdir($dir) || die "Can't dump to $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or mkdir $dir or die "Can't dump to ${dir}: $!\n" 0 0 0
Condition0%0/3
-d $dir or mkdir $dir
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $dir or mkdir $dir
-d $dir mkdir $dir
Truth table0%0/3
A or B
A= -d $dirB= mkdir $dir
ABresult
1X1
011
000
566 # print "created $dir\n";
567 0 for my $f (keys %src) {
568 0 my $dump_file = File::Spec->catfile($dir,$f);
569 0 ▶ open (my $fh, '>:utf8', $dump_file)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:utf8", $dump_file or die "Can't write to ${dump_file}: $!\n" 0 0 0
570 || die "Can't write to $dump_file: $!\n";
571 0 my $sub = $src{$f};
572 0 $sub=~s/^\s*#line[^\n]*\n//;
573 0 print $fh ($sub);
574 0 close $fh;
575 }
576 }
577  
578 65 ▶sub load_data {
Subroutine load_data: called CC=5 SCAR=18.5
Pod undocumented
579 65 my ($ctxt,$reader)=@_;
580 65 my $root = $ctxt->{_root};
581 65 my ($children);
582 65 ▶ $reader->read if $reader->nodeType == XML_READER_TYPE_END_ELEMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $reader->nodeType == 15 65 0 65
583 65 ▶ if ($HAVE_XS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::HAVE_XS) { } 0 65 65
584 0 my %ns;
585 0 $children = XML::CompactTree::XS::readLevelToPerl(
586 $reader,
587 $XTC_FLAGS,
588 \%ns
589 );
590 0 ▶ $root->[XAT_NS]=$ns{(PML_NS)} || -1;
Condition0%0/2
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'} || -1
l!l
00
MC/DC0%0/1
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'} || -1
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'}
Truth table0%0/2
A
A= $ns{'http://ufal.mff.cuni.cz/pdt/pml/'}
Aresult
11
00
591 } else {
592 65 my %ns;
593 65 $children = XML::CompactTree::readLevelToPerl(
594 $reader,
595 $XTC_FLAGS,
596 \%ns
597 );
598 65 ▶ $root->[XAT_NS]=$ns{(PML_NS)} || -1;
Condition50%1/2
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'} || -1
l!l
650
MC/DC0%0/1
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'} || -1
$ns{'http://ufal.mff.cuni.cz/pdt/pml/'}
Truth table50%1/2
A
A= $ns{'http://ufal.mff.cuni.cz/pdt/pml/'}
Aresult
11
00
599 }
600  
601 65 $root->[XAT_CHILDREN]=$children;
602 # print Dumper($root);
603  
604 # print Dumper({references => $ctxt->{'_references'},
605 # refnames => $ctxt->{'_refnames'}});
606 65 return $root;
607 }
608  
609 30 ▶sub _set_trees_seq {
Subroutine _set_trees_seq: called CC=10 SCAR=25.6
610 30 my ($ctxt,$type,$data)=@_;
611 30 $ctxt->{'_pml_trees_type'} = $type;
612 30 ▶ my $trees = $ctxt->{'_trees'} ||= Treex::PML::Factory->createList;
Condition33%1/3
$ctxt->{"_trees"} ||= "Treex::PML::Factory"->createList
l!l&&r!l&&!r
0300
MC/DC0%0/2
$ctxt->{"_trees"} ||= "Treex::PML::Factory"->createList
$ctxt->{"_trees"} "Treex::PML::Factory"->createList
Truth table33%1/3
A ||= B
A= $ctxt->{"_trees"}B= "Treex::PML::Factory"->createList
ABresult
1X1
011
000
613 30 ▶ my $prolog = $ctxt->{'_pml_prolog'} ||= Treex::PML::Factory->createSeq;
Condition33%1/3
$ctxt->{"_pml_prolog"} ||= "Treex::PML::Factory"->createSeq
l!l&&r!l&&!r
0300
MC/DC0%0/2
$ctxt->{"_pml_prolog"} ||= "Treex::PML::Factory"->createSeq
$ctxt->{"_pml_prolog"} "Treex::PML::Factory"->createSeq
Truth table33%1/3
A ||= B
A= $ctxt->{"_pml_prolog"}B= "Treex::PML::Factory"->createSeq
ABresult
1X1
011
000
614 30 ▶ my $epilog = $ctxt->{'_pml_epilog'} ||= Treex::PML::Factory->createSeq;
Condition33%1/3
$ctxt->{"_pml_epilog"} ||= "Treex::PML::Factory"->createSeq
l!l&&r!l&&!r
0300
MC/DC0%0/2
$ctxt->{"_pml_epilog"} ||= "Treex::PML::Factory"->createSeq
$ctxt->{"_pml_epilog"} "Treex::PML::Factory"->createSeq
Truth table33%1/3
A ||= B
A= $ctxt->{"_pml_epilog"}B= "Treex::PML::Factory"->createSeq
ABresult
1X1
011
000
615 30 my $phase = 0; # prolog
616 30 foreach my $element (@$data) {
617 495 my $val = $element->[1];
618 495 ▶ if (UNIVERSAL::DOES::does($val,'Treex::PML::Node')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($val, 'Treex::PML::Node')) { } 476 19 495
619 476 ▶ if ($phase == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 0) 30 446 476
620 30 $phase = 1;
621 }
622 476 ▶ if ($phase == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 1) { } 476 0 476
623 476 $val->{'#name'} = $element->[0]; # manually delegate_name on this element
624 476 push @$trees, $val;
625 } else {
626 0 $prolog->push_element_obj($element);
627 }
628 } else {
629 19 ▶ if ($phase == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 1) 0 19 19
630 0 $phase = 2; # start epilog
631 }
632 19 ▶ if ($phase == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 0) { } 19 0 19
633 19 $prolog->push_element_obj($element);
634 } else {
635 0 $epilog->push_element_obj($element);
636 }
637 }
638 }
639 }
640  
641 163 ▶sub readAttributes {
Subroutine readAttributes: called CC=7 SCAR=19.9
Pod undocumented
642 163 my ($r)=@_;
643 163 my @attrs;
644 163 my ($prefix,$name);
645 163 ▶ if ($r->moveToFirstAttribute==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->moveToFirstAttribute == 1) 163 0 163
646 163 ▶ do {{
Branch: 1 branch
BranchTrueFalseTotal
$r->moveToNextAttribute == 1 and do { do { { $prefix = $r->prefix; $name = $r->localName; push @attrs, ($name, $r->value) unless $prefix and $prefix eq "xmlns" or not $prefix and $name eq "xmlns"; } } } 66 163 229
647 229 $prefix = $r->prefix;
648 229 $name = $r->localName;
649 229 ▶ push @attrs, ($name,$r->value) unless ($prefix and $prefix eq 'xmlns') or (!$prefix and $name eq 'xmlns');
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix and $prefix eq "xmlns" or not $prefix and $name eq "xmlns" 164 65 229
Condition55%5/9
$prefix and $prefix eq "xmlns" or not $prefix and $name eq "xmlns"
l!l&&r!l&&!r
065164
$prefix and $prefix eq "xmlns"
!ll&&!rl&&r
22900
not $prefix and $name eq "xmlns"
!ll&&!rl&&r
016465
MC/DC25%1/4
$prefix and $prefix eq "xmlns" or not $prefix and $name eq "xmlns"
$prefix $prefix eq "xmlns" not $prefix $name eq "xmlns"
Truth table28%2/7
A and B or not(C) and D
A= $prefixB= $prefix eq "xmlns"C= not $prefixD= $name eq "xmlns"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
650 }} while ($r->moveToNextAttribute==1);
651 163 $r->moveToElement;
652 }
653 163 \@attrs;
654 }
655  
656  
657 17 ▶sub _paste_last_code {
Subroutine _paste_last_code: called CC=1 SCAR=0.0
658 17 my ($node,$prev,$p)=@_;
659 17 return qq`
660 #$node\->{'$Treex::PML::Node::rbrother'}=undef;
661 $prev\->{'$Treex::PML::Node::rbrother'}=$node;
662 weaken( $node\->{'$Treex::PML::Node::lbrother'} = $prev );
663 weaken( $node\->{'$Treex::PML::Node::parent'} = $p );
664 `;
665 }
666 17 ▶sub _paste_first_code {
Subroutine _paste_first_code: called CC=1 SCAR=0.0
667 17 my ($node,$p)=@_;
668 17 return qq`
669 #$node\->{'$Treex::PML::Node::rbrother'}=undef;
670 #$node\->{'$Treex::PML::Node::lbrother'}=undef;
671 $p\->{'$Treex::PML::Node::firstson'}=$node;
672 weaken( $node\->{'$Treex::PML::Node::parent'} = $p );
673 `;
674 }
675  
676 48 ▶sub hash_id_code {
Subroutine hash_id_code: called CC=1 SCAR=0.0
Pod undocumented
677 48 my ($key,$value)=@_;
678 48 return q`
679 for (`.$key.q`) {
680 if (defined and length) {
681 if (exists($ID_HASH->{$ID_PREFIX.$_}) and
682 $ID_HASH->{$ID_PREFIX.$_} != `.$value.q`) {
683 warn("Duplicated ID '$_'");
684 }
685 weaken( $ID_HASH->{$ID_PREFIX.$_} = `.$value.q` );
686 }
687 }`
688 }
689  
690 24 ▶sub _fix_id_member {
Subroutine _fix_id_member: called CC=10 SCAR=27.3
691 24 my ($decl)=@_;
692 24 ▶ return unless $decl;
Branch: 1 branch
BranchTrueFalseTotal
unless $decl 0 24 24
693 24 my ($idM) = $decl->find_members_by_role('#ID');
694 24 ▶ if ($idM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idM) 24 0 24
695 # what follows is a hack fixing buggy PDT 2.0 schemas
696 24 my $cdecl = $idM->get_content_decl(1); # no_resolve
697 24 ▶ if ($cdecl and $cdecl->get_decl_type == PML_CDATA_DECL and $cdecl->get_format eq 'ID') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq 'ID') { } 6 18 24
elsif ($cdecl = $idM->get_content_decl) { } 18 0 18
Condition50%3/6
$cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq "ID"
!ll&&!rl&&r
0186
$cdecl and $cdecl->get_decl_type == 8
!ll&&!rl&&r
0024
MC/DC33%1/3
$cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq "ID"
$cdecl $cdecl->get_decl_type == 8 $cdecl->get_format eq "ID"
Truth table50%2/4
A and B and C
A= $cdeclB= $cdecl->get_decl_type == 8C= $cdecl->get_format eq "ID"
ABCresult
0XX0
10X0
1100
1111
698 6 $cdecl->set_format('PMLREF');
699 } elsif ($cdecl = $idM->get_content_decl()) {
700 18 ▶ if ($cdecl and $cdecl->get_decl_type == PML_CDATA_DECL and $cdecl->get_format eq 'ID') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq "ID") 0 18 18
Condition33%2/6
$cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq "ID"
!ll&&!rl&&r
0180
$cdecl and $cdecl->get_decl_type == 8
!ll&&!rl&&r
0018
MC/DC0%0/3
$cdecl and $cdecl->get_decl_type == 8 and $cdecl->get_format eq "ID"
$cdecl $cdecl->get_decl_type == 8 $cdecl->get_format eq "ID"
Truth table25%1/4
A and B and C
A= $cdeclB= $cdecl->get_decl_type == 8C= $cdecl->get_format eq "ID"
ABCresult
0XX0
10X0
1100
1111
701 0 warn "Trying to knit object of type '".$decl->get_decl_path."' which has an #ID-attribute ".
702 "'".$idM->get_name."' declared as <cdata format=\"ID\"/>. ".
703 "Note that the data-type for #ID-attributes in objects knitted as DOM should be ".
704 "<cdata format=\"PMLREF\"/> (Hint: redeclare with <derive> for imported types).";
705 }
706 }
707 }
708 24 return $idM;
709 }
710  
711 10 ▶sub knit_code {
Subroutine knit_code: called CC=5 SCAR=16.9
Pod undocumented
712 10 my ($decl,$assign,$fail)=@_;
713 10 my $sub = q`
714 if ($ref) {
715 $ref =~ s/^(?:(.*?)\#)//;
716 my $file_id = $1||'';
717 my $do_knit=$selected_knits->{$file_id};
718 unless (defined($do_knit) and $do_knit==0) {
719 my $target;
720 if (length $file_id) {
721 my $f = $parsed_reffile->{ $file_id };
722 if (ref $f) {
723 if (UNIVERSAL::DOES::does($f,'Treex::PML::Instance')) {
724 $target = $f->{'_id-hash'}->{$ref};
725 $target->{'#knit_prefix'}=$file_id;
726 } else { # DOM`;
727 10 ▶ if ($decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl) { } 10 0 10
728 10 my $idM = _fix_id_member($decl);
729 10 ▶ my $idM_name = $idM && $idM->get_name;
Condition33%1/3
$idM && $idM->get_name
!ll&&!rl&&r
0010
MC/DC0%0/2
$idM && $idM->get_name
$idM $idM->get_name
Truth table33%1/3
A && B
A= $idMB= $idM->get_name
ABresult
0X0
100
111
730 10 my $decl_path = $decl->get_decl_path; $decl_path =~ s/^!//;
731 10 ▶ $sub .= q`
Branch: 1 branch
BranchTrueFalseTotal
$Treex::PML::Instance::Reader::HAVE_XS ? : 0 10 10
732 my $dom_node = $ref_index->{$file_id}{$ref} || $f->getElementsById($ref);
733 if (defined $dom_node) {
734 $target = $ID_HASH->{$ID_PREFIX.$file_id.'#'.$ref};
735 if (!defined $target) {
736 my $p = $ID_PREFIX;
737 $ID_PREFIX.=$file_id.'#';
738 my $r = XML::LibXML::Reader->new(string=>'<f xmlns="`.PML_NS.q`">'.$dom_node->toString.'</f>');
739 $r->nextElement;
740 # print $r, $dom_node->toString,"\n";
741 my %ns;
742 my $tree = XML::CompactTree`.($HAVE_XS ? '::XS' : '').q`::readSubtreeToPerl($r,`.$XTC_FLAGS.q`,\%ns);
743 my $index = $pml_ns_index;
744 $pml_ns_index = $ns{'`.PML_NS.q`'} || -1;
745 # print "index: $pml_ns_index\n";
746 # print Dumper($tree->[0][XAT_CHILDREN][0]);
747 $target = $handlers{'`.$decl_path.q`'}->($tree->[XAT_CHILDREN][0]);`;
748 10 ▶ if ($idM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idM) 10 0 10
749 10 $sub .= q`
750 $target->{`.$idM_name.q`}=$file_id.'#'.$target->{`.$idM_name.q`} if $target;`;
751 }
752 10 $sub .= q`
753 $pml_ns_index = $index;
754 $weaken=0;
755 $ID_PREFIX=$p;
756 }
757 }`;
758 } else {
759 0 $sub .= q`
760 warn("DOM knit error: knit content type not declared in the schema!\n");`;
761 }
762 10 $sub.=q`
763 }
764 } else {
765 warn("warning: KNIT failed: document '$file_id' not loaded\n");
766 }
767 } else {
768 $target = $ID_HASH->{$ID_PREFIX.$ref};
769 }
770 if (ref $target) {`.$assign.q`
771 } else {
772 warn("warning: KNIT failed: ID $ref not found in reffile '$file_id'\n");`.$fail.q`
773 }
774 }
775 }
776 `;
777 10 return $sub;
778 }
779  
780 0 ▶sub _report_error {
Subroutine _report_error: not called CC=2 SCAR=17.9
781 0 my ($err)=@_;
782 0 ▶ if ($STRICT) {die $err} else {warn $err};
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::STRICT) { } 0 0 0
783 }
784 0 ▶sub _unhandled {
Subroutine _unhandled: not called CC=1 SCAR=6.9
785 0 my ($what,$pml_file,$el,$path)=@_;
786 0 _report_error( "Error: $what not declared for type '$path' at ".$pml_file." line ".$el->[XAT_LINE] );
787 0 ▶ return sub{};
Subroutine __ANON__: not called CC=1 SCAR=6.9
788 }
789  
790 28 ▶sub compile_schema {
Subroutine compile_schema: called CC=1 SCAR=0.3
Pod undocumented
791 28 my ($schema)=@_;
792 28 my $schema_name = $schema->get_root_decl->get_name;
793 28 my ($ctxt,$pml_file,$pml_ns_index,$ID_HASH,$ID_PREFIX,$selected_knits,$ref_index,$parsed_reffile,$trees_type,$have_trees);
794 65 ▶ $handlers{'#cleanup'}= sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
795 65 undef $_ for ($ctxt,$pml_file,$pml_ns_index,$ID_HASH,$ID_PREFIX,$selected_knits,$ref_index,$parsed_reffile);
796 28 };
797 65 ▶ $handlers{'#initialize'}= sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
798 65 my ($instance)=@_;
799 65 $ctxt = $instance;
800 65 $pml_file = $instance->{'_filename'};
801 65 $pml_ns_index = $instance->{_root}->[XAT_NS];
802 65 $selected_knits = $instance->{_selected_knits_ids};
803 65 $ref_index = $instance->{'_ref-index'};
804 65 $ID_HASH = $instance->{'_id-hash'};
805 65 ▶ $ID_PREFIX = $instance->{'_id_prefix'} || '';
Condition50%1/2
$instance->{'_id_prefix'} || ''
l!l
065
MC/DC0%0/1
$instance->{'_id_prefix'} || ''
$instance->{'_id_prefix'}
Truth table50%1/2
A
A= $instance->{'_id_prefix'}
Aresult
11
00
806 65 $parsed_reffile=$instance->{'_ref'};
807 65 $have_trees = 0;
808 28 };
809 1302 ▶ $schema->for_each_decl(sub {
Subroutine __ANON__: called CC=113 SCAR=60.5
810 1302 my ($decl)=@_;
811 # no warnings 'uninitialized';
812 1302 my $decl_type=$decl->get_decl_type;
813 1302 my $path = $decl->get_decl_path;
814 1302 ▶ $path =~ s/^!// if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 541 761 1302
815 1302 ▶ return if $decl_type == PML_ATTRIBUTE_DECL ||
Branch: 1 branch
BranchTrueFalseTotal
if $decl_type == 11 or $decl_type == 12 or $decl_type == 1 or $decl_type == 13 725 577 1302
Condition100%9/9
$decl_type == 11 or $decl_type == 12 or $decl_type == 1 or $decl_type == 13
l!l&&r!l&&!r
66857577
$decl_type == 11 or $decl_type == 12 or $decl_type == 1
l!l&&r!l&&!r
451217634
$decl_type == 11 or $decl_type == 12
l!l&&r!l&&!r
54397851
MC/DC100%4/4
$decl_type == 11 or $decl_type == 12 or $decl_type == 1 or $decl_type == 13
$decl_type == 11 $decl_type == 12 $decl_type == 1 $decl_type == 13
Truth table100%5/5
A or B or C or D
A= $decl_type == 11B= $decl_type == 12C= $decl_type == 1D= $decl_type == 13
ABCDresult
1XXX1
01XX1
001X1
00011
00000
816 $decl_type == PML_MEMBER_DECL ||
817 $decl_type == PML_TYPE_DECL ||
818 $decl_type == PML_ELEMENT_DECL;
819 577 ▶ if ($decl_type == PML_ROOT_DECL) {
Branch: 9 branches
BranchTrueFalseTotal
if ($decl_type == 2) { } 28 549 577
elsif ($decl_type == 3) { } 105 444 549
elsif ($decl_type == 4) { } 41 403 444
elsif ($decl_type == 5) { } 41 362 403
elsif ($decl_type == 6) { } 45 317 362
elsif ($decl_type == 7) { } 8 309 317
elsif ($decl_type == 8) { } 245 64 309
elsif ($decl_type == 9) { } 62 2 64
elsif ($decl_type == 10) { } 2 0 2
820 28 my $name = $decl->get_name;
821 28 my $cpath = $decl->get_content_decl->get_decl_path;
822 28 $cpath =~ s/^!//;
823 28 my $src = $schema_name.'__generated_read_root';
824 28 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
825 sub {
826 my ($p)=@_;
827 unless (ref($p) and
828 $p->[XAT_TYPE] == XML_READER_TYPE_ELEMENT and
829 $p->[XAT_NS] == $pml_ns_index and
830 $p->[XAT_NAME] eq '`.$name.q`'
831 ) {
832 die q(Did not find expected root element '`.$name.q` in ').$pml_file;
833 }
834 return ($handlers{ '`.$cpath.q`' })->($p);
835 }`;
836 28 $src{$src}=$sub;
837 28 ▶ $handlers{'#root'}=eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28 28
838 } elsif ($decl_type == PML_STRUCTURE_DECL) {
839 # print $path,"\n";
840 105 my $src = $schema_name.'__generated_read_structure@'.$path;
841 105 $src=~y{/}{@};
842 105 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
843 sub {
844 my ($p)=@_;
845 my $a=$p->[XAT_ATTRS];
846 my $c=$p->[XAT_CHILDREN];
847 # print join(",",map {defined($_) ? $_ : 'undef'} $p->[XAT_NAME],$p->[XAT_LINE],@$p)."\n";
848 my (%s,$k,$v);`;
849 105 ▶ if ($VALIDATE_CDATA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::VALIDATE_CDATA) { } 0 105 105
850 0 $sub .= q`
851 if ($a) {
852 while (@$a) {
853 $k=shift @$a;
854 $v=shift @$a;
855 $s{ $k } = ($handlers{ '`.$path.q`/'.$k }||_unhandled("attribute member '$k'",$pml_file,$p,'`.$path.q`'))->( $v );
856 }
857 }`;
858 } else {
859 105 $sub .= q`
860 %s = @$a if $a;`;
861 }
862 105 $sub .= q`
863 if ($c) {
864 for my $el (@$c) {
865 unless (ref($el) and $el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT
866 and $el->[XAT_NS] == $pml_ns_index) {
867 if (!ref($el) || $el->[XAT_TYPE] == XML_READER_TYPE_TEXT || $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
868 warn q(Ignoring unexpected text content ').$el->[XAT_VALUE].q(' in a structure '`.$path.q`');
869 } elsif ($el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT) {
870 warn q(Ignoring unexpected element ').$el->[XAT_NAME].q(' in a structure '`.$path.q`');
871 }
872 next;
873 }
874 $k = $el->[XAT_NAME];
875 $s{ $k } = ($handlers{ '`.$path.q`/'.$k }||_unhandled("member '$k'",$pml_file,$el,'`.$path.q`'))->($el);
876 }
877 }`;
878 105 my ($id, $children_member);
879 105 for my $member ($decl->get_members) {
880 397 my $mdecl = $member->get_content_decl;
881 397 ▶ if ($member->is_required) {
Branch: 2 branches
BranchTrueFalseTotal
if ($member->is_required) { } 88 309 397
elsif ($mdecl and $mdecl->get_decl_type == 10) { } 2 307 309
882 88 my $name = $member->get_name;
883 88 ▶ if ($mdecl && $mdecl->get_role eq '#TREES') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl and $mdecl->get_role eq '#TREES') { } 0 88 88
Condition33%1/3
$mdecl and $mdecl->get_role eq "#TREES"
!ll&&!rl&&r
0880
MC/DC0%0/2
$mdecl and $mdecl->get_role eq "#TREES"
$mdecl $mdecl->get_role eq "#TREES"
Truth table33%1/3
A and B
A= $mdeclB= $mdecl->get_role eq "#TREES"
ABresult
0X0
100
111
884 # this is a bit of a hack:
885 # in this case, if the trees have been read from the member, the member handler returns
886 # a stub value '#TREES' that will get deleted
887 0 $sub.=q`
888 ref or ($_ eq '#TREES' and delete($s{'`.$name.q`'})) or warn q(Missing required member '`.$name.q`' in structure '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE] for $s{'`.$name.q`'};`;
889 } else {
890 88 $sub.=q`
891 ref or defined and length or warn q(Missing required member '`.$name.q`' in structure '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE] for $s{'`.$name.q`'};`;
892 }
893 ▶ } elsif ($mdecl and $mdecl->get_decl_type == PML_CONSTANT_DECL) {
Condition66%2/3
$mdecl and $mdecl->get_decl_type == 10
!ll&&!rl&&r
03072
MC/DC50%1/2
$mdecl and $mdecl->get_decl_type == 10
$mdecl $mdecl->get_decl_type == 10
Truth table66%2/3
A and B
A= $mdeclB= $mdecl->get_decl_type == 10
ABresult
0X0
100
111
894 $sub.=q`
895 2 defined or $_="`.quotemeta($mdecl->{value}).q`" for $s{'`.$member->get_name.q`'};`;
896 }
897 397 my $role = $member->get_role;
898 397 ▶ if ($KNIT and !$role) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::KNIT and not $role) 343 54 397
Condition66%2/3
$Treex::PML::Instance::Reader::KNIT and not $role
!ll&&!rl&&r
054343
MC/DC50%1/2
$Treex::PML::Instance::Reader::KNIT and not $role
$Treex::PML::Instance::Reader::KNIT not $role
Truth table66%2/3
A and not(B)
A= $Treex::PML::Instance::Reader::KNITB= not $role
ABresult
0X0
100
111
899 343 ▶ $mdecl ||= $member->get_content_decl;
Condition33%1/3
$mdecl ||= $member->get_content_decl
l!l&&r!l&&!r
34300
MC/DC0%0/2
$mdecl ||= $member->get_content_decl
$mdecl $member->get_content_decl
Truth table33%1/3
A ||= B
A= $mdeclB= $member->get_content_decl
ABresult
1X1
011
000
900 343 ▶ if ($mdecl and $mdecl->get_decl_type == PML_LIST_DECL and
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl and $mdecl->get_decl_type == 6 and $mdecl->get_role eq "#KNIT") 9 334 343
Condition83%5/6
$mdecl and $mdecl->get_decl_type == 6 and $mdecl->get_role eq "#KNIT"
!ll&&!rl&&r
310249
$mdecl and $mdecl->get_decl_type == 6
!ll&&!rl&&r
031033
MC/DC66%2/3
$mdecl and $mdecl->get_decl_type == 6 and $mdecl->get_role eq "#KNIT"
$mdecl $mdecl->get_decl_type == 6 $mdecl->get_role eq "#KNIT"
Truth table75%3/4
A and B and C
A= $mdeclB= $mdecl->get_decl_type == 6C= $mdecl->get_role eq "#KNIT"
ABCresult
0XX0
10X0
1100
1111
901 $mdecl->get_role eq '#KNIT') {
902 9 my $mname = $member->get_name;
903 9 my $knit_name = $mname; $knit_name=~s/\.rf$//;
904 # warn("#KNIT on list not yet implemented: ".$member->get_name."\n");
905 9 $sub .=q`
906 my $ref_list = $s{'`.$mname.q`'};
907 if ($ref_list) {
908 my (@knit_list,@weaken,$weaken);
909 for my $ref (@$ref_list) {
910 $weaken=1;`
911 .knit_code($mdecl->get_knit_content_decl(),q`
912 push @knit_list, $target;
913 push @weaken, $weaken;`,
914 q`undef $ref_list; last;`)
915 .q`
916 }
917 if (defined $ref_list) {
918 my $i=0;
919 for (@knit_list) {
920 weaken($_) if $weaken[$i++];
921 }
922 $s{'`.$knit_name.q`'}=Treex::PML::Factory->createList(\@knit_list);`;
923 9 ▶ if ($mname ne $knit_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mname ne $knit_name) 9 0 9
924 9 $sub .= q`delete $s{'`.$mname.q`'};`;
925 }
926 9 $sub .= q`
927 } else {
928 warn("KNIT failed on list '`.$mname.q`'");
929 }
930 }`;
931 9 next;
932 }
933 }
934 388 ▶ if ($role eq '#ID') {
Branch: 4 branches
BranchTrueFalseTotal
if ($role eq '#ID') { } 38 350 388
elsif (not $trees_type and $role eq '#TREES' and $Treex::PML::Instance::Reader::BUILD_TREES) { } 3 347 350
elsif ($role eq '#CHILDNODES') { } 7 340 347
elsif ($role eq '#KNIT' and $Treex::PML::Instance::Reader::KNIT) { } 1 678 679
935 38 $id = $member->get_name;
936 ▶ } elsif (!$trees_type and $role eq '#TREES' and $BUILD_TREES) {
Condition83%5/6
not $trees_type and $role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
34703
not $trees_type and $role eq "#TREES"
!ll&&!rl&&r
552923
MC/DC66%2/3
not $trees_type and $role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
not $trees_type $role eq "#TREES" $Treex::PML::Instance::Reader::BUILD_TREES
Truth table75%3/4
not(A) and B and C
A= not $trees_typeB= $role eq "#TREES"C= $Treex::PML::Instance::Reader::BUILD_TREES
ABCresult
0XX0
10X0
1100
1111
937 3 ▶ $mdecl ||= $member->get_content_decl;
Condition33%1/3
$mdecl ||= $member->get_content_decl
l!l&&r!l&&!r
300
MC/DC0%0/2
$mdecl ||= $member->get_content_decl
$mdecl $member->get_content_decl
Truth table33%1/3
A ||= B
A= $mdeclB= $member->get_content_decl
ABresult
1X1
011
000
938 3 my $mtype = $mdecl->get_decl_type;
939 3 ▶ if ($mtype == PML_LIST_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mtype == 6) { } 3 0 3
elsif ($mtype == 5) { } 0 0 0
940 # check that content type is of role #NODE
941 3 my $cmdecl = $mdecl->get_content_decl;
942 3 my $cmdecl_type = $cmdecl->get_decl_type;
943 3 ▶ unless ($cmdecl && ($cmdecl->get_role||'') eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdecl and ($cmdecl->get_role || "") eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4) 0 3 3
Condition36%4/11
$cmdecl and ($cmdecl->get_role || "") eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
!ll&&!rl&&r
003
$cmdecl and ($cmdecl->get_role || "") eq "#NODE"
!ll&&!rl&&r
003
$cmdecl->get_role || ''
l!l
30
$cmdecl_type == 3 or $cmdecl_type == 4
l!l&&r!l&&!r
300
MC/DC0%0/4
$cmdecl and ($cmdecl->get_role || "") eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
$cmdecl $cmdecl->get_role $cmdecl_type == 3 $cmdecl_type == 4
Truth table20%1/5
A and B and C or D
A= $cmdeclB= $cmdecl->get_roleC= $cmdecl_type == 3D= $cmdecl_type == 4
ABCDresult
0XXX0
10XX0
11000
111X1
11011
944 ($cmdecl_type == PML_STRUCTURE_DECL or
945 $cmdecl_type == PML_CONTAINER_DECL)) {
946 0 _report_error("List '$path' with role #TREES may only contain structures or containers with role #NODE in schema ".
947 $decl->get_schema->get_url."\n");
948 }
949 3 $trees_type = $mdecl;
950 3 $sub .= q`
951 unless ($have_trees) {
952 $ctxt->{'_pml_trees_type'} = $trees_type;
953 $have_trees=1;
954 $ctxt->{'_trees'} = delete $s{'`.$member->get_name.q`'};
955 }`;
956 } elsif ($mtype == PML_SEQUENCE_DECL) {
957 0 $trees_type = $mdecl;
958 0 $sub .= q`
959 unless ($have_trees) {
960 $have_trees=1;
961 defined($_) && _set_trees_seq($ctxt,$trees_type,$_->elements_list) for (delete $s{'`.$member->get_name.q`'});
962 }`;
963 } else {
964 0 _report_error("#TREES member '$path/".$member->get_name."' is neither a list nor a sequence in schema ".$member->get_schema->get_url."\n");
965 }
966 } elsif ($role eq '#CHILDNODES') {
967 7 ▶ if ($children_member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children_member) { } 0 7 7
968 0 _report_error("#CHILDNODES role defined on multiple members of type '$path': '$children_member' and '".$member->get_name."' in schema ".$member->get_schema->get_url."\n");
969 } else {
970 7 $children_member=$member->get_name;
971 }
972 ▶ } elsif ($role eq '#KNIT' and $KNIT) {
Condition66%2/3
$role eq "#KNIT" and $Treex::PML::Instance::Reader::KNIT
!ll&&!rl&&r
33901
MC/DC50%1/2
$role eq "#KNIT" and $Treex::PML::Instance::Reader::KNIT
$role eq "#KNIT" $Treex::PML::Instance::Reader::KNIT
Truth table66%2/3
A and B
A= $role eq "#KNIT"B= $Treex::PML::Instance::Reader::KNIT
ABresult
0X0
100
111
973 1 my $mname = $member->get_name;
974 1 my $knit_name = $mname; $knit_name=~s/\.rf$//;
975 1 ▶ $sub .= q`
Branch: 1 branch
BranchTrueFalseTotal
$mname ne $knit_name ? : 1 0 1
976 my $ref = $s{'`.$mname.q`'}; my $weaken = 1;`
977 .knit_code($member->get_knit_content_decl,q`
978 if ($weaken) {
979 weaken( $s{'`.$knit_name.q`'}=$target );
980 } else {
981 $s{'`.$knit_name.q`'}=$target;
982 } `.
983 ($mname ne $knit_name ? q`delete $s{'`.$mname.q`'};` : ''), '');
984 }
985 }
986 105 ▶ if ($decl->get_role eq '#NODE' and $BUILD_TREES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_role eq '#NODE' and $Treex::PML::Instance::Reader::BUILD_TREES) { } 7 98 105
Condition66%2/3
$decl->get_role eq "#NODE" and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
9807
MC/DC50%1/2
$decl->get_role eq "#NODE" and $Treex::PML::Instance::Reader::BUILD_TREES
$decl->get_role eq "#NODE" $Treex::PML::Instance::Reader::BUILD_TREES
Truth table66%2/3
A and B
A= $decl->get_role eq "#NODE"B= $Treex::PML::Instance::Reader::BUILD_TREES
ABresult
0X0
100
111
987 7 $sub .= q`
988 my $node = Treex::PML::Factory->createTypedNode($decl,\%s,1);
989 # my $node = bless \%s, 'Treex::PML::Node';
990 # $node->{`.$Treex::PML::Node::TYPE.q`}=$decl;`;
991 7 ▶ if ($children_member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children_member) 7 0 7
992 7 my $cdecl = $decl->get_member_by_name($children_member)->get_content_decl;
993 7 my $ctype = $cdecl->get_decl_type;
994 7 ▶ if ($ctype == PML_LIST_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctype == 6) { } 7 0 7
elsif ($ctype == 5) { } 0 0 0
995 7 my $cmdecl = $cdecl->get_content_decl;
996 7 my $cmdecl_type = $cmdecl->get_decl_type;
997 7 ▶ unless ($cmdecl->get_role eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4) 0 7 7
Condition33%2/6
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
!ll&&!rl&&r
007
$cmdecl_type == 3 or $cmdecl_type == 4
l!l&&r!l&&!r
700
MC/DC0%0/3
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
$cmdecl->get_role eq "#NODE" $cmdecl_type == 3 $cmdecl_type == 4
Truth table25%1/4
A and B or C
A= $cmdecl->get_role eq "#NODE"B= $cmdecl_type == 3C= $cmdecl_type == 4
ABCresult
0XX0
1000
11X1
1011
998 ($cmdecl_type == PML_STRUCTURE_DECL or
999 $cmdecl_type == PML_CONTAINER_DECL)) {
1000 0 _report_error("List '$path' with role #CHILDNODES may only contain structures or containers with role #NODE in schema '".
1001 $decl->get_schema->get_url."'; got ".$cmdecl->get_decl_type_str." (".$cmdecl->get_decl_path.") with role '".$cmdecl->get_role."' instead!\n");
1002 }
1003 7 $sub .= q`
1004 my $content = delete $node->{'`.$children_member.q`'};
1005 if ($content) {
1006 my $prev;
1007 foreach my $son (@{ $content }) {
1008 if ($prev) {
1009 `._paste_last_code(qw($son $prev $node)).q`
1010 } else {
1011 `._paste_first_code(qw($son $node)).q`
1012 }
1013 $prev = $son;
1014 }
1015 }`;
1016 } elsif ($ctype == PML_SEQUENCE_DECL) {
1017 0 for my $edecl ($cdecl->get_elements) {
1018 0 my $cmdecl = $edecl->get_content_decl;
1019 0 my $cmdecl_type = $cmdecl->get_decl_type;
1020 0 ▶ unless ($cmdecl->get_role eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4) 0 0 0
Condition0%0/6
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
!ll&&!rl&&r
000
$cmdecl_type == 3 or $cmdecl_type == 4
l!l&&r!l&&!r
000
MC/DC0%0/3
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
$cmdecl->get_role eq "#NODE" $cmdecl_type == 3 $cmdecl_type == 4
Truth table0%0/4
A and B or C
A= $cmdecl->get_role eq "#NODE"B= $cmdecl_type == 3C= $cmdecl_type == 4
ABCresult
0XX0
1000
11X1
1011
1021 ($cmdecl_type == PML_STRUCTURE_DECL or
1022 $cmdecl_type == PML_CONTAINER_DECL)) {
1023 0 _report_error("Sequence '$path' with role #CHILDNODES may only contain structures or containers with role #NODE in schema '".
1024 $decl->get_schema->get_url."'; got ".$cmdecl->get_decl_type_str." (".$cmdecl->get_decl_path.") with role '".$cmdecl->get_role."' instead!\n");
1025 }
1026 }
1027 0 $sub .= q`
1028 my $content = delete $node->{'`.$children_member.q`'};
1029 if ($content) {
1030 # $content->delegate_names('#name');
1031 foreach my $element (@{$content->[0]}) { # manually delegate
1032 $element->[1]{'#name'} = $element->[0]; # store element's name in key $key of its value
1033 }
1034 my $prev;
1035 foreach my $son (map $_->[1], @{$content->[0]}) { # $content->values
1036 if ($prev) {
1037 `._paste_last_code(qw($son $prev $node)).q`
1038 } else {
1039 `._paste_first_code(qw($son $node)).q`
1040 }
1041 $prev = $son;
1042 }
1043 }`;
1044 } else {
1045 0 _report_error("Role #CHILDNODES can only occur on a structure member of type list or sequence, not on ".$cdecl->get_decl_type_str." '$path' in schema ".$cdecl->get_schema->get_url."\n");
1046 }
1047 }
1048 } else {
1049 98 $sub.=q`
1050 my $node = Treex::PML::Factory->createStructure(\%s,1);
1051 # my $node = bless \%s, 'Treex::PML::Struct';
1052 `;
1053 }
1054 105 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 38 67 105
1055 38 $sub.=hash_id_code(qq(\$s{'$id'}),'$node');
1056 }
1057 105 $sub.=q`
1058 return $node;
1059 }`;
1060 # print $sub;
1061 105 $src{$src}=$sub;
1062 105 ▶ $handlers{$path} = eval($sub); die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 105 105
1063 } elsif ($decl_type == PML_CONTAINER_DECL) {
1064 41 my %attributes;
1065 41 @attributes{ map $_->get_name, $decl->get_attributes } = ();
1066 41 my $cdecl = $decl->get_content_decl;
1067 41 ▶ my $cpath = $cdecl && $cdecl->get_decl_path;
Condition33%1/3
$cdecl && $cdecl->get_decl_path
!ll&&!rl&&r
0041
MC/DC0%0/2
$cdecl && $cdecl->get_decl_path
$cdecl $cdecl->get_decl_path
Truth table33%1/3
A && B
A= $cdeclB= $cdecl->get_decl_path
ABresult
0X0
100
111
1068 41 ▶ $cpath=~s/^!// if $cpath;
Branch: 1 branch
BranchTrueFalseTotal
if $cpath 41 0 41
1069 41 my $src = $schema_name.'__generated_read_container@'.$path;
1070 41 $src=~y{/}{@};
1071 41 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1072 sub {
1073 my ($p)=@_;
1074 my $a=$p->[XAT_ATTRS];
1075 my $c=$p->[XAT_CHILDREN];
1076 my (%s,$k,$v,$content,@a_rest);
1077 if ($a) {
1078 while (@$a) {
1079 $k=shift @$a;
1080 $v=shift @$a;
1081 if (exists $attributes{$k}) {`;
1082 41 ▶ if ($VALIDATE_CDATA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::VALIDATE_CDATA) { } 0 41 41
1083 0 $sub .= q`
1084 $s{ $k } = ($handlers{ '`.$path.q`/'.$k }||_unhandled("attribute '$k'",$pml_file,$p,'`.$path.q`'))->( $v );`;
1085 } else {
1086 41 $sub .= q`
1087 $s{ $k } = $v;`;
1088 }
1089 41 $sub .= q`
1090 } else {
1091 push @a_rest, $k, $v;
1092 }
1093 }
1094 }
1095 $p->[XAT_ATTRS]=\@a_rest;`;
1096 41 ▶ if ($cdecl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cdecl) { } 41 0 41
1097 41 $sub .= q`
1098 $content = $handlers{ '`.$cpath.q`' }->($p);`;
1099 } else {
1100 0 $sub .= q`
1101 !$c or !grep { !($_->[XAT_TYPE] == XML_READER_TYPE_WHITESPACE or $_->[XAT_TYPE] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE) } @$c or _report_error(qq(Unexpected content of an empty container type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);`;
1102 }
1103 41 my $id;
1104 41 for my $member ($decl->get_attributes) {
1105 54 ▶ if ($member->is_required) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member->is_required) 19 35 54
1106 19 my $name = $member->get_name;
1107 19 $sub.=q`
1108 ref or defined and length or _report_error(q(missing required attribute '`.$name.q`' in container '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]) for $s{'`.$name.q`'};`;
1109 }
1110 54 ▶ if ($member->get_role eq '#ID') {
Branch: 1 branch
BranchTrueFalseTotal
if ($member->get_role eq "#ID") 10 44 54
1111 10 $id = $member->get_name;
1112 }
1113 }
1114 41 ▶ if ($decl->get_role eq '#NODE' and $BUILD_TREES) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_role eq '#NODE' and $Treex::PML::Instance::Reader::BUILD_TREES) { } 17 24 41
Condition66%2/3
$decl->get_role eq "#NODE" and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
24017
MC/DC50%1/2
$decl->get_role eq "#NODE" and $Treex::PML::Instance::Reader::BUILD_TREES
$decl->get_role eq "#NODE" $Treex::PML::Instance::Reader::BUILD_TREES
Truth table66%2/3
A and B
A= $decl->get_role eq "#NODE"B= $Treex::PML::Instance::Reader::BUILD_TREES
ABresult
0X0
100
111
1115 17 $sub .= q`
1116 my $node = Treex::PML::Factory->createTypedNode($decl,\%s,1);
1117 # my $node = bless \%s, 'FSNode';
1118 # $node->{`.$Treex::PML::Node::TYPE.q`}=$decl;`;
1119 17 ▶ if ($cdecl and ($cdecl->get_role||'') eq '#CHILDNODES') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cdecl and ($cdecl->get_role || '') eq '#CHILDNODES') { } 10 7 17
elsif ($cdecl) { } 7 0 7
Condition80%4/5
$cdecl and ($cdecl->get_role || "") eq "#CHILDNODES"
!ll&&!rl&&r
0710
$cdecl->get_role || ''
l!l
107
MC/DC50%1/2
$cdecl and ($cdecl->get_role || "") eq "#CHILDNODES"
$cdecl $cdecl->get_role
Truth table66%2/3
A and B
A= $cdeclB= $cdecl->get_role
ABresult
0X0
100
111
1120 10 my $ctype = $cdecl->get_decl_type;
1121 10 ▶ if ($ctype == PML_LIST_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctype == 6) { } 2 8 10
elsif ($ctype == 5) { } 8 0 8
1122 2 my $cmdecl = $cdecl->get_content_decl;
1123 2 my $cmdecl_type = $cmdecl->get_decl_type;
1124 2 ▶ unless ($cmdecl->get_role eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4) 0 2 2
Condition33%2/6
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
!ll&&!rl&&r
002
$cmdecl_type == 3 or $cmdecl_type == 4
l!l&&r!l&&!r
200
MC/DC0%0/3
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
$cmdecl->get_role eq "#NODE" $cmdecl_type == 3 $cmdecl_type == 4
Truth table25%1/4
A and B or C
A= $cmdecl->get_role eq "#NODE"B= $cmdecl_type == 3C= $cmdecl_type == 4
ABCresult
0XX0
1000
11X1
1011
1125 ($cmdecl_type == PML_STRUCTURE_DECL or
1126 $cmdecl_type == PML_CONTAINER_DECL)) {
1127 0 _report_error("List '$path' with role #CHILDNODES may only contain structures or containers with role #NODE in schema '".
1128 $decl->get_schema->get_url."'; got ".$cmdecl->get_decl_type_str." (".$cmdecl->get_decl_path.") with role '".$cmdecl->get_role."' instead!\n");
1129 }
1130 2 $sub .= q`
1131 if ($content) {
1132 my $prev;
1133 foreach my $son (@{ $content }) {
1134 if ($prev) {
1135 `._paste_last_code(qw($son $prev $node)).q`
1136 } else {
1137 `._paste_first_code(qw($son $node)).q`
1138 }
1139 $prev = $son;
1140 }
1141 }`;
1142 } elsif ($ctype == PML_SEQUENCE_DECL) {
1143 8 for my $edecl ($cdecl->get_elements) {
1144 12 ▶ my $cmdecl = $edecl->get_content_decl or
Branch: 1 branch
BranchTrueFalseTotal
my $cmdecl = $edecl->get_content_decl or _report_error(q[Element '] . $edecl->get_name . "' of sequence '${path}' has no content type declaration") 12 0 12
1145 _report_error("Element '".$edecl->get_name."' of sequence '$path' has no content type declaration");
1146 12 my $cmdecl_type = $cmdecl->get_decl_type;
1147 12 ▶ unless ($cmdecl->get_role eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4) 0 12 12
Condition33%2/6
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
!ll&&!rl&&r
0012
$cmdecl_type == 3 or $cmdecl_type == 4
l!l&&r!l&&!r
0120
MC/DC0%0/3
$cmdecl->get_role eq "#NODE" and $cmdecl_type == 3 || $cmdecl_type == 4
$cmdecl->get_role eq "#NODE" $cmdecl_type == 3 $cmdecl_type == 4
Truth table25%1/4
A and B or C
A= $cmdecl->get_role eq "#NODE"B= $cmdecl_type == 3C= $cmdecl_type == 4
ABCresult
0XX0
1000
11X1
1011
1148 ($cmdecl_type == PML_STRUCTURE_DECL or
1149 $cmdecl_type == PML_CONTAINER_DECL)) {
1150 0 _report_error("Sequence '$path' with role #CHILDNODES may only contain structures or containers with role #NODE in schema '".
1151 $decl->get_schema->get_url."'; got ".$cmdecl->get_decl_type_str." (".$cmdecl->get_decl_path.") with role '".$cmdecl->get_role."' instead!\n");
1152 }
1153 }
1154 8 $sub .= q`
1155 if ($content) {
1156 # $content->delegate_names('#name');
1157 foreach my $element (@{$content->[0]}) { # manually delegate
1158 $element->[1]{'#name'} = $element->[0]; # store element's name in key $key of its value
1159 }
1160 my $prev;
1161 foreach my $son (map $_->[1], @{$content->[0]}) { # $content->values
1162 if ($prev) {
1163 `._paste_last_code(qw($son $prev $node)).q`
1164 } else {
1165 `._paste_first_code(qw($son $node)).q`
1166 }
1167 $prev = $son;
1168 }
1169 }`;
1170 } else {
1171 0 _report_error("Role #CHILDNODES can only occur on a container content type if it is a list or sequence, not on a ".$cdecl->get_decl_type_str." '".$path."' in schema ".$cdecl->get_schema->get_url."\n");
1172 }
1173 } elsif ($cdecl) {
1174 7 $sub .= q`
1175 $node->{'#content'} = $content if $content;`;
1176 }
1177 } else {
1178 24 $sub.=q`
1179 my $node = Treex::PML::Factory->createContainer($content,\%s,1);
1180 # $s{'#content'}=$content if $content;
1181 # my $node = bless \%s, 'Treex::PML::Container';`;
1182 }
1183 41 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 10 31 41
1184 10 $sub.=hash_id_code(qq(\$s{'$id'}),'$node');
1185 }
1186 41 $sub.=q`
1187 return $node;
1188 }`;
1189 # print $sub;
1190 41 $src{$src}=$sub;
1191 41 ▶ $handlers{$path} = eval($sub); die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 41 41
1192 } elsif ($decl_type == PML_SEQUENCE_DECL) {
1193 41 my $src = $schema_name.'__generated_read_sequence@'.$path;
1194 41 $src=~y{/}{@};
1195 41 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1196 sub {
1197 my ($p)=@_;
1198 my $c=$p->[XAT_CHILDREN];
1199 return undef unless $c and @$c;
1200 my @seq;
1201 my $k;
1202 for my $el (@$c) {
1203 if (ref($el) and $el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT
1204 and $el->[XAT_NS] == $pml_ns_index) {
1205 # print "element: $el->[XAT_NAME]\n";
1206 $k = $el->[XAT_NAME];
1207 push @seq, bless [$k, ($handlers{ '`.$path.q`/'.$k }||_unhandled("element '$k'",$pml_file,$el,'`.$path.q`'))->($el)], 'Treex::PML::Seq::Element';`;
1208 41 ▶ if ($decl->is_mixed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->is_mixed) { } 1 40 41
1209 1 $sub .= q`
1210 } elsif (!ref($el)) {`;
1211 1 $sub .= q`
1212 push @seq, bless ['#TEXT',$el], 'Treex::PML::Seq::Element';
1213 } elsif ($el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA
1214 or $el->[XAT_TYPE] == XML_READER_TYPE_WHITESPACE or $el->[XAT_TYPE] == XML_READER_TYPE_SIGNIFICANT_WHITESPACE) {
1215 push @seq, bless ['#TEXT',$el->[XAT_VALUE]], 'Treex::PML::Seq::Element';
1216 }`;
1217 } else {
1218 40 $sub .= q`
1219 } elsif (!ref($el) or $el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
1220 _report_error(q(Unexpected text content in a non-mixed sequence '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1221 }`;
1222 }
1223 41 $sub .= q`
1224 }`;
1225 41 my $content_pattern = $decl->get_content_pattern;
1226 41 ▶ if ($VALIDATE_SEQUENCES and $content_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::VALIDATE_SEQUENCES and $content_pattern) 9 32 41
Condition66%2/3
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES and $content_pattern
!ll&&!rl&&r
0329
MC/DC50%1/2
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES and $content_pattern
$Treex::PML::Instance::Reader::VALIDATE_SEQUENCES $content_pattern
Truth table66%2/3
A and B
A= $Treex::PML::Instance::Reader::VALIDATE_SEQUENCESB= $content_pattern
ABresult
0X0
100
111
1227 9 my $re = Treex::PML::Seq::content_pattern2regexp($content_pattern);
1228 9 $sub .= q`
1229 unless (join('',map '<'.$_->[0].'>',@seq) =~ m{^`.$re.q`$}ox) {
1230 warn("Sequence content (".join(",",map $_->[0], @seq).") does not follow the pattern `.quotemeta($content_pattern).q` in ".$pml_file.' line '.$p->[XAT_LINE]);
1231 }`;
1232 }
1233 41 ▶ if (!$trees_type and $decl->get_role eq '#TREES' and $BUILD_TREES) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES) 10 31 41
Condition83%5/6
not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
31010
not $trees_type and $decl->get_role eq "#TREES"
!ll&&!rl&&r
52610
MC/DC66%2/3
not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
not $trees_type $decl->get_role eq "#TREES" $Treex::PML::Instance::Reader::BUILD_TREES
Truth table75%3/4
not(A) and B and C
A= not $trees_typeB= $decl->get_role eq "#TREES"C= $Treex::PML::Instance::Reader::BUILD_TREES
ABCresult
0XX0
10X0
1100
1111
1234 10 $trees_type = $decl;
1235 10 $sub .= q`
1236 unless ($have_trees) {
1237 $have_trees=1;
1238 _set_trees_seq($ctxt,$trees_type,\@seq);
1239 return;
1240 }`;
1241 }
1242 41 ▶ if ($content_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_pattern) { } 9 32 41
1243 9 $sub .= q`
1244 return Treex::PML::Factory->createSeq(\@seq, "`.quotemeta($content_pattern).q`",1);
1245 }`;
1246 } else {
1247 32 $sub .= q`
1248 return Treex::PML::Factory->createSeq(\@seq, undef, 1);
1249 }`;
1250 }
1251 41 $src{$src}=$sub;
1252 41 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 41 41
1253 } elsif ($decl_type == PML_LIST_DECL) {
1254 # print $path."\t@".$decl->get_decl_type_str,"\n";
1255 45 ▶ my $cdecl = $decl->get_content_decl
Branch: 1 branch
BranchTrueFalseTotal
my $cdecl = $decl->get_content_decl or croak("Invalid PML Schema: list type without content: ", $decl->get_decl_path) 45 0 45
1256 or croak("Invalid PML Schema: list type without content: ",$decl->get_decl_path);
1257 45 my $cpath = $cdecl->get_decl_path;
1258 45 $cpath=~s/^!//;
1259 45 my $src = $schema_name.'__generated_read_list@'.$path;
1260 45 $src=~y{/}{@};
1261 45 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1262 sub {
1263 my ($p)=@_;
1264 my $c=$p->[XAT_CHILDREN];
1265 my $a=$p->[XAT_ATTRS];
1266 return undef unless $c and @$c or $a and @$a;
1267 my @list;
1268 my $singleton = $a && @$a ? 1 : 0;
1269 unless ($singleton) {
1270 for my $el (@$c) {
1271 if (!ref($el) or $el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
1272 $singleton = 1;
1273 last;
1274 } elsif ($el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT) {
1275 $singleton = 1 if $el->[XAT_NAME] ne 'LM' and $el->[XAT_NS] == $pml_ns_index;
1276 last;
1277 }
1278 }}
1279 if ($singleton) {
1280 @list = ($handlers{ '`.$cpath.q`' }->($p));
1281 } else {
1282 for my $el (@$c) {
1283 if (ref($el) and $el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT and $el->[XAT_NS] == $pml_ns_index) {
1284 $el->[XAT_NAME] eq 'LM' or _report_error(q(Unexpected non-LM element ').$el->[XAT_NAME].q(' in a list: '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1285 push @list, $handlers{ '`.$cpath.q`' }->($el);
1286 } elsif (!ref($el) or $el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
1287 _report_error(q(Unexpected text content in a list '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1288 }
1289 }
1290 }`;
1291 45 ▶ if (!$trees_type and $decl->get_role eq '#TREES' and $BUILD_TREES) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES) 0 45 45
Condition50%3/6
not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
4500
not $trees_type and $decl->get_role eq "#TREES"
!ll&&!rl&&r
18270
MC/DC0%0/3
not $trees_type and $decl->get_role eq "#TREES" and $Treex::PML::Instance::Reader::BUILD_TREES
not $trees_type $decl->get_role eq "#TREES" $Treex::PML::Instance::Reader::BUILD_TREES
Truth table50%2/4
not(A) and B and C
A= not $trees_typeB= $decl->get_role eq "#TREES"C= $Treex::PML::Instance::Reader::BUILD_TREES
ABCresult
0XX0
10X0
1100
1111
1292 0 my $cdecl_type = $cdecl->get_decl_type;
1293 0 ▶ unless ($cdecl && ($cdecl->get_role||'') eq '#NODE' &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($cdecl and ($cdecl->get_role || "") eq "#NODE" and $cdecl_type == 3 || $cdecl_type == 4) 0 0 0
Condition0%0/11
$cdecl and ($cdecl->get_role || "") eq "#NODE" and $cdecl_type == 3 || $cdecl_type == 4
!ll&&!rl&&r
000
$cdecl and ($cdecl->get_role || "") eq "#NODE"
!ll&&!rl&&r
000
$cdecl->get_role || ''
l!l
00
$cdecl_type == 3 or $cdecl_type == 4
l!l&&r!l&&!r
000
MC/DC0%0/4
$cdecl and ($cdecl->get_role || "") eq "#NODE" and $cdecl_type == 3 || $cdecl_type == 4
$cdecl $cdecl->get_role $cdecl_type == 3 $cdecl_type == 4
Truth table0%0/5
A and B and C or D
A= $cdeclB= $cdecl->get_roleC= $cdecl_type == 3D= $cdecl_type == 4
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1294 ($cdecl_type == PML_STRUCTURE_DECL or
1295 $cdecl_type == PML_CONTAINER_DECL)) {
1296 0 _report_error("List '$path' with role #TREES may only contain structures or containers with role #NODE in schema ".
1297 $decl->get_schema->get_url."\n");
1298 }
1299 0 $trees_type = $decl;
1300 0 $sub .= q`
1301 unless ($have_trees) {
1302 $have_trees = 1;
1303 $ctxt->{'_pml_trees_type'} = $trees_type;
1304 $ctxt->{'_trees'} = Treex::PML::Factory->createList(\@list,1);
1305 return;
1306 }`;
1307 }
1308 45 $sub .= q`
1309 return Treex::PML::Factory->createList(\@list,1);
1310 }`;
1311 # print $sub;
1312 45 $src{$src}=$sub;
1313 45 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 45 45
1314 } elsif ($decl_type == PML_ALT_DECL) {
1315 # print $path."\t@".$decl->get_decl_type_str,"\n";
1316 8 my $cpath = $decl->get_content_decl->get_decl_path;
1317 8 $cpath=~s/^!//;
1318 8 my $src = $schema_name.'__generated_read_alt@'.$path;
1319 8 $src=~y{/}{@};
1320 8 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1321 sub {
1322 my ($p)=@_;
1323 my $c=$p->[XAT_CHILDREN];
1324 my $a=$p->[XAT_ATTRS];
1325 return undef unless $c and @$c or $a and @$a;
1326 my $singleton = $a && @$a ? 1 : 0;
1327 unless ($singleton) {
1328 for my $el (@$c) {
1329 if (!ref($el) or $el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
1330 $singleton = 1;
1331 last;
1332 } elsif ($el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT and $el->[XAT_NS] == $pml_ns_index) {
1333 $singleton = 1 if $el->[XAT_NAME] ne 'AM';
1334 last;
1335 }
1336 }
1337 }
1338 if ($singleton) {
1339 return $handlers{ '`.$cpath.q`' }->($p);
1340 } else {
1341 my @alt;
1342 for my $el (@$c) {
1343 if (ref($el) and $el->[XAT_TYPE] == XML_READER_TYPE_ELEMENT and $el->[XAT_NS] == $pml_ns_index) {
1344 $el->[XAT_NAME] eq 'AM' or _report_error(q(Unexpected non-AM element ').$el->[XAT_NAME].q(' in an alt: '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1345 push @alt, $handlers{ '`.$cpath.q`' }->($el);
1346 } elsif (!ref($el) or $el->[XAT_TYPE] == XML_READER_TYPE_TEXT or $el->[XAT_TYPE] == XML_READER_TYPE_CDATA) {
1347 _report_error(q(Unexpected text content in an alt: '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1348 }
1349 }
1350 return @alt == 0 ? undef : @alt == 1 ? $alt[0] :
1351 #return bless \@alt, 'Treex::PML::Alt';
1352 Treex::PML::Factory->createAlt(\@alt,1);
1353 }
1354 }
1355 `;
1356 # print $sub;
1357 8 $src{$src}=$sub;
1358 8 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
1359  
1360 } elsif ($decl_type == PML_CDATA_DECL) {
1361 245 my $src = $schema_name.'__generated_read_cdata@'.$path;
1362 245 $src=~y{/}{@};
1363 245 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1364 sub {
1365 my ($p)=@_;
1366 my $text;
1367 if (ref($p)) {
1368 my $c = $p->[XAT_CHILDREN];
1369 return undef unless $c and @$c;
1370 my $type;
1371 $text = join '',
1372 map {
1373 if (ref($_)) {
1374 $type = $_->[XAT_TYPE];
1375 if ($type == XML_READER_TYPE_TEXT ||
1376 $type == XML_READER_TYPE_WHITESPACE ||
1377 $type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
1378 $type == XML_READER_TYPE_CDATA) {
1379 $_->[XAT_VALUE]
1380 } elsif ($type == XML_READER_TYPE_ELEMENT) {
1381 _report_error(q(Element found where only character data were expected in element <).$_->[XAT_NAME].q(> of CDATA type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1382 }
1383 } else {
1384 $_
1385 }
1386 } @$c;`;
1387 245 my $format_checker;
1388 245 ▶ if ($VALIDATE_CDATA and $decl->get_format ne 'any') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::PML::Instance::Reader::VALIDATE_CDATA and $decl->get_format ne 'any') { } 0 245 245
Condition33%1/3
$Treex::PML::Instance::Reader::VALIDATE_CDATA and $decl->get_format ne "any"
!ll&&!rl&&r
24500
MC/DC0%0/2
$Treex::PML::Instance::Reader::VALIDATE_CDATA and $decl->get_format ne "any"
$Treex::PML::Instance::Reader::VALIDATE_CDATA $decl->get_format ne "any"
Truth table33%1/3
A and B
A= $Treex::PML::Instance::Reader::VALIDATE_CDATAB= $decl->get_format ne "any"
ABresult
0X0
100
111
1389 0 $sub .=q`
1390 } else {
1391 $text = $p;
1392 }`;
1393 0 $format_checker = $decl->_get_format_checker();
1394 0 ▶ if (defined $format_checker) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $format_checker) 0 0 0
1395 0 ▶ if (ref($format_checker) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $format_checker eq 'CODE') { } 0 0 0
1396 0 $sub .= q`
1397 if (defined $text and length $text and !$format_checker->($text)) {`;
1398 } else {
1399 0 $sub .= q`
1400 if (defined $text and length $text and $text !~ $format_checker) {`;
1401 }
1402 0 $sub .= q`
1403 warn("CDATA value '$text' does not conform to format '`.$decl->get_format.q`' at ".$pml_file.' line '.$p->[XAT_LINE]);
1404 }`;
1405 }
1406 0 $sub .= q`
1407 return $text;
1408 }`;
1409 } else {
1410 245 $sub .=q`
1411 return $text;
1412 } else {
1413 return $p;
1414 }
1415 }`;
1416 }
1417 # print $sub;
1418 245 $src{$src}=$sub;
1419 245 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 245 245
1420 } elsif ($decl_type == PML_CHOICE_DECL) {
1421 # print $path,"\n";
1422 62 my $value_hash = $decl->{value_hash};
1423 62 ▶ unless ($value_hash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value_hash) 62 0 62
1424 62 $value_hash={};
1425 62 @{$value_hash}{@{$decl->{values}}}=();
1426 62 $decl->{value_hash}=$value_hash;
1427 }
1428 62 my $src = $schema_name.'__generated_read_choice@'.$path;
1429 62 $src=~y{/}{@};
1430 62 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1431 sub {
1432 my ($p)=@_;
1433 my $text;
1434 if (ref($p)) {
1435 my $c = $p->[XAT_CHILDREN];
1436 return undef unless @$c;
1437 $c=$c->[0];
1438 if (ref($c)) {
1439 my $type = $c->[XAT_TYPE];
1440 if ($type == XML_READER_TYPE_TEXT ||
1441 $type == XML_READER_TYPE_WHITESPACE ||
1442 $type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
1443 $type == XML_READER_TYPE_CDATA) {
1444 $text = $c->[XAT_VALUE]
1445 } elsif ($type == XML_READER_TYPE_ELEMENT) {
1446 _report_error(q(Element found where only character data were expected in element <).$p->[XAT_NAME].q(> of choice type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1447 }
1448 } else {
1449 $text = $c;
1450 }
1451 } else {
1452 $text=$p;
1453 }
1454 return undef unless defined $text;
1455 exists($value_hash->{$text}) or _report_error(qq(Invalid value '$text' in element <).$p->[XAT_NAME].q(> of choice type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1456 return $text;
1457 }`;
1458 # print $sub;
1459 62 $src{$src}=$sub;
1460 62 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 62 62
1461 } elsif ($decl_type == PML_CONSTANT_DECL) {
1462 # print $path,"\n";
1463 2 my $value = quotemeta($decl->{value});
1464 2 my $src = $schema_name.'__generated_read_constant@'.$path;
1465 2 $src=~y{/}{@};
1466 2 my $sub = q`#line 0 ".pml_compile.d/`.$src.q`"
1467 sub {
1468 my ($p)=@_;
1469 my $text;
1470 if (ref($p)) {
1471 my $c = $p->[XAT_CHILDREN];
1472 return undef unless $c and @$c;
1473 $c=$c->[0];
1474 if (ref($c)) {
1475 my $type = $c->[XAT_TYPE];
1476 if ($type == XML_READER_TYPE_TEXT ||
1477 $type == XML_READER_TYPE_WHITESPACE ||
1478 $type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
1479 $type == XML_READER_TYPE_CDATA) {
1480 $text = $c->[XAT_VALUE]
1481 } elsif ($type == XML_READER_TYPE_ELEMENT) {
1482 _report_error(q(Unexpected element occurrence in element <).$p->[XAT_NAME].q(> of constant type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1483 }
1484 } else {
1485 $text = $c;
1486 }
1487 } else {
1488 $text=$p;
1489 }
1490 !(defined($text) and length($text)) or ($text eq "`.$value.q`") or
1491 _report_error(qq(Invalid value '$text' in element <).$p->[XAT_NAME].q(> of constant type '`.$path.q`' at ).$pml_file.' line '.$p->[XAT_LINE]);
1492 return $text;
1493 }`;
1494 # print $sub;
1495 2 $src{$src}=$sub;
1496 2 ▶ $handlers{$path} = eval $sub; die _nl($sub)."\n".$@.' ' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
1497 }
1498 # print "@_\n";
1499 28 });
1500 $schema->for_each_decl(
1501 1302 ▶ sub {
Subroutine __ANON__: called CC=14 SCAR=34.3
1502 1302 my ($decl)=@_;
1503 1302 my $decl_type=$decl->get_decl_type;
1504 1302 ▶ if ($decl_type == PML_ATTRIBUTE_DECL ||
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_type == 11 or $decl_type == 12 or $decl_type == 13) 508 794 1302
Condition100%6/6
$decl_type == 11 or $decl_type == 12 or $decl_type == 13
l!l&&r!l&&!r
45157794
$decl_type == 11 or $decl_type == 12
l!l&&r!l&&!r
54397851
MC/DC100%3/3
$decl_type == 11 or $decl_type == 12 or $decl_type == 13
$decl_type == 11 $decl_type == 12 $decl_type == 13
Truth table100%4/4
A or B or C
A= $decl_type == 11B= $decl_type == 12C= $decl_type == 13
ABCresult
1XX1
01X1
0011
0000
1505 $decl_type == PML_MEMBER_DECL ||
1506 $decl_type == PML_ELEMENT_DECL
1507 ) {
1508 508 my $parent = $decl->get_parent_decl;
1509 508 my $path = $parent->get_decl_path . '/'. $decl->get_name;
1510 508 ▶ $path =~ s/^!// if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 508 0 508
1511 508 my $mdecl;
1512 508 ▶ if ($decl_type == PML_MEMBER_DECL and $decl->is_required) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_type == 12 and $decl->is_required) 88 420 508
Condition100%3/3
$decl_type == 12 and $decl->is_required
!ll&&!rl&&r
11130988
MC/DC100%2/2
$decl_type == 12 and $decl->is_required
$decl_type == 12 $decl->is_required
Truth table100%3/3
A and B
A= $decl_type == 12B= $decl->is_required
ABresult
0X0
100
111
1513 # a hack that fixes missing content of a required member
1514 # containing a construct with the role #TREES
1515 #
1516 # the modified handler returns string '#TREES' instead
1517 # and the value gets deleted in the structure handler
1518 88 $mdecl = $decl->get_content_decl;
1519 88 ▶ if ($mdecl->get_role eq '#TREES' and $mdecl==$trees_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl->get_role eq "#TREES" and $mdecl == $trees_type) 0 88 88
Condition33%1/3
$mdecl->get_role eq "#TREES" and $mdecl == $trees_type
!ll&&!rl&&r
8800
MC/DC0%0/2
$mdecl->get_role eq "#TREES" and $mdecl == $trees_type
$mdecl->get_role eq "#TREES" $mdecl == $trees_type
Truth table33%1/3
A and B
A= $mdecl->get_role eq "#TREES"B= $mdecl == $trees_type
ABresult
0X0
100
111
1520 0 my $mpath = $mdecl->get_decl_path;
1521 0 ▶ $mpath =~ s/^!// if $mpath;
Branch: 1 branch
BranchTrueFalseTotal
if $mpath 0 0 0
1522 0 my $handler = $handlers{$mpath};
1523 0 ▶ $handlers{$path}=sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
1524 0 ▶ if (!$have_trees and $BUILD_TREES) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $have_trees and $Treex::PML::Instance::Reader::BUILD_TREES) { } 0 0 0
Condition0%0/3
not $have_trees and $Treex::PML::Instance::Reader::BUILD_TREES
!ll&&!rl&&r
000
MC/DC0%0/2
not $have_trees and $Treex::PML::Instance::Reader::BUILD_TREES
not $have_trees $Treex::PML::Instance::Reader::BUILD_TREES
Truth table0%0/3
not(A) and B
A= not $have_treesB= $Treex::PML::Instance::Reader::BUILD_TREES
ABresult
0X0
100
111
1525 0 my $ret = &$handler;
1526 0 ▶ return '#TREES' if $have_trees and !defined($ret);
Branch: 1 branch
BranchTrueFalseTotal
if $have_trees and not defined $ret 0 0 0
Condition0%0/3
$have_trees and not defined $ret
!ll&&!rl&&r
000
MC/DC0%0/2
$have_trees and not defined $ret
$have_trees not defined $ret
Truth table0%0/3
A and not(B)
A= $have_treesB= not defined $ret
ABresult
0X0
100
111
1527 0 return $ret;
1528 } else {
1529 0 return &$handler;
1530 }
1531 0 };
1532 0 return;
1533 }
1534 }
1535 # print "$path\n";
1536 508 ▶ if (!exists($handlers{$path})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $handlers{$path}) 251 257 508
1537 251 ▶ $mdecl ||= $decl->get_content_decl;
Condition66%2/3
$mdecl ||= $decl->get_content_decl
l!l&&r!l&&!r
62450
MC/DC0%0/2
$mdecl ||= $decl->get_content_decl
$mdecl $decl->get_content_decl
Truth table66%2/3
A ||= B
A= $mdeclB= $decl->get_content_decl
ABresult
1X1
011
000
1538 251 ▶ my $mpath = $mdecl && $mdecl->get_decl_path;
Condition33%1/3
$mdecl && $mdecl->get_decl_path
!ll&&!rl&&r
00251
MC/DC0%0/2
$mdecl && $mdecl->get_decl_path
$mdecl $mdecl->get_decl_path
Truth table33%1/3
A && B
A= $mdeclB= $mdecl->get_decl_path
ABresult
0X0
100
111
1539 251 ▶ if ($mpath) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mpath) 251 0 251
1540 251 $mpath =~ s/^!//;
1541 # print "mapping $path -> $mpath ... $handlers{$mpath}\n";
1542 251 $handlers{$path} = $handlers{$mpath};
1543 }
1544 }
1545 }
1546 28 });
1547 }
1548  
1549 0 ▶sub _nl {
Subroutine _nl: not called CC=1 SCAR=6.9
1550 0 my ($str)=@_;
1551 0 my $i=0;
1552 0 return join "\n", map sprintf("%4d\t",$i++).$_, split /\n/, $str;
1553 }
1554  
1555 }
1556  
1557 {
1558 # outside the main blog so that we leak no lexicals other than $dom
1559 9 ▶ sub perl_transform {
Subroutine perl_transform: not called CC=1 SCAR=1.2
Pod undocumented
1560 0 return eval shift();
1561 }
1562 }
1563  
1564 9 1;
1565 __END__
« PML/Backend/CSTS/Fs2csts.pm ↑ Summary PML/Backend/CSTS/Csts2fs.pm »