PML2BASE.pm

filter: Statementstmt 8.0% 61 / 755 Branchbran 0.0% 0 / 424 Conditioncond 0.0% 0 / 372 MC/DCmcdc 0.0% 0 / 188 Subroutinesub 32.1% 18 / 56 Podpod 0.0% 0 / 33 totaltotal 4.3% 79 / 1828 CC 377 SCAR 69.4
CC
377
Cov
4%
traverse_data
3192.0
__ANON__
1892.0
finish
1482.0
CRAP 1034.5
↑ Summary PML2BASE/Relation/Treex/AEParentCIterator.pm »
1 package PMLTQ::PML2BASE;
2 6 our $AUTHORITY = 'cpan:MATY';
3 6 $PMLTQ::PML2BASE::VERSION = '3.0.1';
4 # ABSTRACT: Convert from PML to SQL
5  
6  
7 6 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 $|=1;
11 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶use open qw(:std :utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # $SIG{__WARN__} = sub { Carp::cluck(@_); };
17  
18 6 ▶use constant MAX_NAME_LENGTH => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 ▶use constant HYBRID=>1; # create both separate node table and node table with attributes
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use constant NO_TREE_TABLE=>2; # don't create one common common node table for all node types
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use constant MAX_MIN_ORD=>4; # node tables have #max_ord and #min_ord columns
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use constant TOP_TREE_FLAG=>8; # The <root>__#files table has a 'top' column indicating that
Subroutine BEGIN: called CC=1 SCAR=0.0
24 # a given root node belongs to the top-level tree list
25 # of a file (i.e. it is not a nested #NODE within
26 # some non-#NODE and non-#TREES data structure)
27 #
28 # Generic SQL DB scheme for PML data:
29 #
30 # - every structure/container/ has a unique idx (Number) and carries attributes as columns
31 #
32 # - container has a '#content' column
33 #
34 # - cdata/constant/choice attributes are stored in the respective columns
35 #
36 # - structure/container members are in a separate table where they have a unique idx,
37 # referred to by the member column
38 #
39 # - unordered-list/alt members are stored in a separate table, whose columns
40 # are a 1:N idx referred to by the member column, and a LM/AM column
41 # containing the value (following the rules described here);
42 #
43 # - sequence members are in a separate table whose columns correspond
44 # to the elements, each containing an reference to a table
45 # representing all occurrences of that element; this table has
46 # an 1:N idx, '#pos' containing position of the element in the sequence,
47 # '#elem-pos' containing the number of preceding elements of the same name in the sequence+1,
48 # and the value, as usual. To retrieve a complete content of a certain sequence as a table,
49 # one has to use a UNION on all the element tables, ordering by #pos and possibly outputing
50 # a constant '#name' column
51 #
52 # - the table names should be derived from PML type names in a canonical way,
53 # one per PML schema type decl
54 #
55 # Possible modifications:
56 #
57 # a) cast all cdata structure members also into separate tables and thus
58 # keep varchar data in separate tables
59 #
60 # b) cast node attributes to a separate table, separating the tree structure
61 # from node data, making the tree-structure table very thin
62 # in fact: this is necessary, since nodes can be of different types
63 #
64 # c) use cdata format information to determine the table column format
65 #
66 # some hacks:
67 #
68 # - updating refs in strips .rf suffix if the member is a PMLREF but
69 # not if it is a list of PMLREFs
70 #
71 # - prefix of PMLREFs is stripped down; should be kept and
72 # used to verify the target based on filename on UPDATE
73 #
74 #
75  
76 6 ▶use Treex::PML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 6 ▶use Treex::PML::Instance;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 6 ▶use PMLTQ::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 6 ▶use PMLTQ::Relation;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 6 ▶use List::Util qw(max first);
Subroutine BEGIN: called CC=1 SCAR=0.0
81 6 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 6 PMLTQ::Relation->load();
85  
86 6 my ($file_table,$root_name,$schema,$references_table,%schema,%fh,%orig_name,%seen_ref_schema,
87 $node_table,$index_id,$last_type_no,$tree_no,$filename,
88 $idx,$node_idx, $last_tree_no, %pmlref_target_info, $relations, @dump_fns
89 );
90  
91 6 our %opts;
92  
93 0 ▶sub init {
Subroutine init: not called CC=9 SCAR=45.0
Pod undocumented
94 0 ▶ $idx = $opts{'init-idx'} || 0;
Condition0%0/2
$PMLTQ::PML2BASE::opts{'init-idx'} || 0
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{'init-idx'} || 0
$PMLTQ::PML2BASE::opts{'init-idx'}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{'init-idx'}
Aresult
11
00
95 0 ▶ $node_idx=($opts{'init-node-idx'}|| $opts{'init-idx'} || 0);
Condition0%0/5
$PMLTQ::PML2BASE::opts{'init-node-idx'} || $PMLTQ::PML2BASE::opts{'init-idx'} || 0
l!l
00
$PMLTQ::PML2BASE::opts{"init-node-idx"} or $PMLTQ::PML2BASE::opts{"init-idx"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$PMLTQ::PML2BASE::opts{'init-node-idx'} || $PMLTQ::PML2BASE::opts{'init-idx'} || 0
$PMLTQ::PML2BASE::opts{"init-node-idx"} $PMLTQ::PML2BASE::opts{"init-idx"}
Truth table0%0/3
A or B
A= $PMLTQ::PML2BASE::opts{"init-node-idx"}B= $PMLTQ::PML2BASE::opts{"init-idx"}
ABresult
1X1
011
000
96 0 $last_type_no=0;
97 0 $index_id=0;
98 0 $tree_no=0;
99 0 $filename=undef;
100 0 $relations=[];
101 0 @dump_fns=();
102  
103 0 %pmlref_target_info=();
104  
105 0 ▶ $opts{'related-schema'} ||= [];
Condition0%0/2
$PMLTQ::PML2BASE::opts{"related-schema"} ||= []
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"related-schema"} ||= []
$PMLTQ::PML2BASE::opts{"related-schema"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"related-schema"}
Aresult
11
00
106 $opts{other_schemas}||=[
107 map {
108 0 Treex::PML::Schema->new({filename=>$_,use_resources=>1})
109 0 ▶ } @{$opts{'related-schema'}}
Condition0%0/2
$PMLTQ::PML2BASE::opts{"other_schemas"} ||= [map({"Treex::PML::Schema"->new({"filename", $_, "use_resources", 1});} @{$PMLTQ::PML2BASE::opts{"related-schema"};})]
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"other_schemas"} ||= [map({"Treex::PML::Schema"->new({"filename", $_, "use_resources", 1});} @{$PMLTQ::PML2BASE::opts{"related-schema"};})]
$PMLTQ::PML2BASE::opts{"other_schemas"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"other_schemas"}
Aresult
11
00
110 ];
111 0 ▶ $opts{hybrid}||=1;
Condition0%0/2
$PMLTQ::PML2BASE::opts{"hybrid"} ||= 1
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"hybrid"} ||= 1
$PMLTQ::PML2BASE::opts{"hybrid"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"hybrid"}
Aresult
11
00
112 0 ▶ $opts{prefix}||='';
Condition0%0/2
$PMLTQ::PML2BASE::opts{"prefix"} ||= ""
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"prefix"} ||= ""
$PMLTQ::PML2BASE::opts{"prefix"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"prefix"}
Aresult
11
00
113 0 ▶ $opts{'data-dir'}||='';
Condition0%0/2
$PMLTQ::PML2BASE::opts{"data-dir"} ||= ""
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"data-dir"} ||= ""
$PMLTQ::PML2BASE::opts{"data-dir"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"data-dir"}
Aresult
11
00
114 }
115  
116 0 ▶sub destroy {
Subroutine destroy: not called CC=1 SCAR=6.9
Pod undocumented
117 0 undef $file_table;
118 0 undef $root_name;
119 0 undef $schema;
120 0 undef $references_table;
121 0 undef %schema;
122 0 undef %fh;
123 0 undef %orig_name;
124 0 undef %seen_ref_schema;
125 0 undef $node_table;
126 0 undef $index_id;
127 0 undef $last_type_no;
128 0 undef $tree_no;
129 0 undef $filename;
130 0 undef $idx;
131 0 undef $node_idx;
132 0 undef $last_tree_no;
133 0 undef %pmlref_target_info;
134 0 undef %opts;
135 0 undef $relations;
136 }
137  
138 0 ▶sub varchar { ### TODO REMOVE
Subroutine varchar: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my ($l,$non_ascii)=@_;
140 0 return "VARCHAR($l)";
141 }
142 0 ▶sub numeric { ### TODO REMOVE
Subroutine numeric: not called CC=1 SCAR=6.9
Pod undocumented
143 0 my ($l)=@_;
144 0 return "NUMERIC($l)";
145 }
146 0 ▶sub boolean { ### TODO REMOVE
Subroutine boolean: not called CC=1 SCAR=6.9
Pod undocumented
147 0 my ($l)=@_;
148 0 return "BOOLEAN";
149 }
150  
151 0 ▶sub mkdump {
Subroutine mkdump: not called CC=2 SCAR=17.9
Pod undocumented
152 return join("\t",map {
153 0 ▶ if (defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 0 0 0
154 0 my $x=$_;
155 0 $x=~s/[\t\n]/ /g;
156 0 $x=~s/(\\|\r)/\\$1/g;
157 0 $x
158 } else {
159 0 "\\N"
160 }
161 } @_)."\n";
162 }
163 0 ▶sub mkload {
Subroutine mkload: not called CC=3 SCAR=24.8
Pod undocumented
164 0 my ($f,$opts)=@_;
165 0 ▶ if ($opts && $opts->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts and $opts->{'quiet'}) { } 0 0 0
Condition0%0/3
$opts and $opts->{"quiet"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts and $opts->{"quiet"}
$opts $opts->{"quiet"}
Truth table0%0/3
A and B
A= $optsB= $opts->{"quiet"}
ABresult
0X0
100
111
166 0 return qq{ run_sql_commands '$f' 2>/dev/null 1>&2\n};
167 } else {
168 0 return qq{ run_sql_commands '$f'\n};
169 }
170 }
171 0 ▶sub mkdataload {
Subroutine mkdataload: not called CC=3 SCAR=24.8
Pod undocumented
172 0 my ($f,$opts)=@_;
173 0 ▶ if ($opts && $opts->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts and $opts->{'quiet'}) { } 0 0 0
Condition0%0/3
$opts and $opts->{"quiet"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts and $opts->{"quiet"}
$opts $opts->{"quiet"}
Truth table0%0/3
A and B
A= $optsB= $opts->{"quiet"}
ABresult
0X0
100
111
174 0 return qq{ run_loader_commands '$f' 2>/dev/null 1>&2\n};
175 } else {
176 0 return qq{ run_loader_commands '$f'\n};
177 }
178 }
179  
180 0 ▶sub complete_schema_pmlref_list {
Subroutine complete_schema_pmlref_list: not called CC=2 SCAR=17.9
Pod undocumented
181 0 my ($schema)=@_;
182 $schema->for_each_decl(
183 0 ▶ sub {
Subroutine __ANON__: not called CC=29 SCAR=67.7
184 0 my ($decl)=@_;
185 0 my $decl_is = $decl->get_decl_type;
186 0 ▶ return if ($decl->get_role||'') eq '#CHILDNODES';
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_role || "") eq "#CHILDNODES" 0 0 0
Condition0%0/2
$decl->get_role || ''
l!l
00
MC/DC0%0/1
$decl->get_role || ''
$decl->get_role
Truth table0%0/2
A
A= $decl->get_role
Aresult
11
00
187 0 ▶ return if $decl_is == PML_TYPE_DECL or $decl_is==PML_ROOT_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $decl_is == 1 or $decl_is == 2 0 0 0
Condition0%0/3
$decl_is == 1 or $decl_is == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 1 or $decl_is == 2
$decl_is == 1 $decl_is == 2
Truth table0%0/3
A or B
A= $decl_is == 1B= $decl_is == 2
ABresult
1X1
011
000
188 0 my $p=$decl->get_parent_decl;
189 0 ▶ return if ($p and $p->get_decl_type == PML_MEMBER_DECL and ($p->get_role||'') eq '#CHILDNODES');
Branch: 1 branch
BranchTrueFalseTotal
if $p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES" 0 0 0
Condition0%0/8
$p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES"
!ll&&!rl&&r
000
$p and $p->get_decl_type == 12
!ll&&!rl&&r
000
$p->get_role || ''
l!l
00
MC/DC0%0/3
$p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES"
$p $p->get_decl_type == 12 $p->get_role
Truth table0%0/4
A and B and C
A= $pB= $p->get_decl_type == 12C= $p->get_role
ABCresult
0XX0
10X0
1100
1111
190 0 ▶ return if $decl->is_atomic;
Branch: 1 branch
BranchTrueFalseTotal
if $decl->is_atomic 0 0 0
191 0 my $table = table_name($decl,1);
192 0 my @m;
193 0 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 4 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 0 0 0
elsif ($decl_is == 4) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 6 or $decl_is == 7) { } 0 0 0
194 0 @m = map [$_->get_name, $_->get_knit_content_decl], $decl->get_members;
195 } elsif ($decl_is == PML_CONTAINER_DECL) {
196 0 @m = ['#content', $_->get_content_decl],map [$_->get_name, $_->get_content_decl], $decl->get_attributes;
197 } elsif ($decl_is == PML_SEQUENCE_DECL) {
198 0 @m = map [$_->get_name, $_->get_knit_content_decl], $decl->get_elements;
199 ▶ } elsif ($decl_is == PML_LIST_DECL or $decl_is == PML_ALT_DECL) {
Condition0%0/3
$decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 6 or $decl_is == 7
$decl_is == 6 $decl_is == 7
Truth table0%0/3
A or B
A= $decl_is == 6B= $decl_is == 7
ABresult
1X1
011
000
200 0 @m = ['#value', $decl->get_knit_content_decl];
201 0 } else { return }
202 0 foreach my $member (@m) {
203 0 ▶ next unless $member->[1] and $member->[1]->get_decl_type == PML_CDATA_DECL and
Branch: 1 branch
BranchTrueFalseTotal
unless $member->[1] and $member->[1]->get_decl_type == 8 and $member->[1]->get_format eq "PMLREF" 0 0 0
Condition0%0/6
$member->[1] and $member->[1]->get_decl_type == 8 and $member->[1]->get_format eq "PMLREF"
!ll&&!rl&&r
000
$member->[1] and $member->[1]->get_decl_type == 8
!ll&&!rl&&r
000
MC/DC0%0/3
$member->[1] and $member->[1]->get_decl_type == 8 and $member->[1]->get_format eq "PMLREF"
$member->[1] $member->[1]->get_decl_type == 8 $member->[1]->get_format eq "PMLREF"
Truth table0%0/4
A and B and C
A= $member->[1]B= $member->[1]->get_decl_type == 8C= $member->[1]->get_format eq "PMLREF"
ABCresult
0XX0
10X0
1100
1111
204 $member->[1]->get_format eq 'PMLREF';
205 0 my $p=$member->[1]->get_parent_decl;
206 0 ▶ next if ($p and (($p->get_role||'') eq '#KNIT'
Branch: 1 branch
BranchTrueFalseTotal
if $p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT" 0 0 0
Condition0%0/16
$p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
($p->get_role || "") eq "#KNIT" or $p->get_decl_type == 6 || $p->get_decl_type == 7 and ($p->get_role || "") eq "#KNIT"
l!l&&r!l&&!r
000
$p->get_role || ''
l!l
00
$p->get_decl_type == 6 || $p->get_decl_type == 7 and ($p->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
$p->get_decl_type == 6 or $p->get_decl_type == 7
l!l&&r!l&&!r
000
$p->get_role || ''
l!l
00
MC/DC0%0/5
$p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT"
$p $p->get_role $p->get_decl_type == 6 $p->get_decl_type == 7 $p->get_role
Truth table0%0/7
A and B or C or D and E
A= $pB= $p->get_roleC= $p->get_decl_type == 6D= $p->get_decl_type == 7E= $p->get_role
ABCDEresult
0XXXX0
1000X0
101X00
100100
11XXX1
101X11
100111
207 or ($p->get_decl_type == PML_LIST_DECL or $p->get_decl_type == PML_ALT_DECL)
208 and ($p->get_role||'') eq '#KNIT'));
209 0 ▶ my $path =$member->[0] eq '#value' ? $table : $table.'/'.$member->[0];
Branch: 1 branch
BranchTrueFalseTotal
$member->[0] eq '#value' ? : 0 0 0
210 0 ▶ unless (ref($opts{ref}) and exists ($opts{ref}{$path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}) 0 0 0
Condition0%0/3
ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
ref $PMLTQ::PML2BASE::opts{"ref"} exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
Truth table0%0/3
A and B
A= ref $PMLTQ::PML2BASE::opts{"ref"}B= exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
ABresult
0X0
100
111
211 0 $opts{ref}{$path}='-';
212 }
213 }
214 0 });
215 0 ▶ return ($opts{ref}||={});
Condition0%0/2
$PMLTQ::PML2BASE::opts{"ref"} ||= {}
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::opts{"ref"} ||= {}
$PMLTQ::PML2BASE::opts{"ref"}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::opts{"ref"}
Aresult
11
00
216 }
217  
218 # test if a given DECL is a known PMLREF type
219 # that we can handle
220 # It can aslo produce a warning when finding an unknown PMLREF
221  
222 0 ▶sub get_pmlref_target_info {
Subroutine get_pmlref_target_info: not called CC=19 SCAR=59.4
Pod undocumented
223 0 my ($decl,$table,$column,$warn) = @_;
224 0 ▶ if (!$warn and exists($pmlref_target_info{$decl})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $warn and exists $pmlref_target_info{$decl}) 0 0 0
Condition0%0/3
not $warn and exists $pmlref_target_info{$decl}
!ll&&!rl&&r
000
MC/DC0%0/2
not $warn and exists $pmlref_target_info{$decl}
not $warn exists $pmlref_target_info{$decl}
Truth table0%0/3
not(A) and B
A= not $warnB= exists $pmlref_target_info{$decl}
ABresult
0X0
100
111
225 0 return @{$pmlref_target_info{$decl}};
226 }
227 0 ▶ my $ret = ($pmlref_target_info{$decl}||=[]);
Condition0%0/2
$pmlref_target_info{$decl} ||= []
l!l
00
MC/DC0%0/1
$pmlref_target_info{$decl} ||= []
$pmlref_target_info{$decl}
Truth table0%0/2
A
A= $pmlref_target_info{$decl}
Aresult
11
00
228 0 ▶ return unless $decl->get_decl_type == PML_CDATA_DECL and $decl->get_format eq 'PMLREF';
Branch: 1 branch
BranchTrueFalseTotal
unless $decl->get_decl_type == 8 and $decl->get_format eq "PMLREF" 0 0 0
Condition0%0/3
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
!ll&&!rl&&r
000
MC/DC0%0/2
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
$decl->get_decl_type == 8 $decl->get_format eq "PMLREF"
Truth table0%0/3
A and B
A= $decl->get_decl_type == 8B= $decl->get_format eq "PMLREF"
ABresult
0X0
100
111
229 0 my $p=$decl->get_parent_decl;
230 0 ▶ unless ($p and (($p->get_role||'') eq '#KNIT'
Branch: 1 branch
BranchTrueFalseTotal
unless ($p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT") 0 0 0
Condition0%0/16
$p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
($p->get_role || "") eq "#KNIT" or $p->get_decl_type == 6 || $p->get_decl_type == 7 and ($p->get_role || "") eq "#KNIT"
l!l&&r!l&&!r
000
$p->get_role || ''
l!l
00
$p->get_decl_type == 6 || $p->get_decl_type == 7 and ($p->get_role || "") eq "#KNIT"
!ll&&!rl&&r
000
$p->get_decl_type == 6 or $p->get_decl_type == 7
l!l&&r!l&&!r
000
$p->get_role || ''
l!l
00
MC/DC0%0/5
$p and ($p->get_role || "") eq "#KNIT" || ($p->get_decl_type == 6 || $p->get_decl_type == 7) && ($p->get_role || "") eq "#KNIT"
$p $p->get_role $p->get_decl_type == 6 $p->get_decl_type == 7 $p->get_role
Truth table0%0/7
A and B or C or D and E
A= $pB= $p->get_roleC= $p->get_decl_type == 6D= $p->get_decl_type == 7E= $p->get_role
ABCDEresult
0XXXX0
1000X0
101X00
100100
11XXX1
101X11
100111
231 or ($p->get_decl_type == PML_LIST_DECL or $p->get_decl_type == PML_ALT_DECL)
232 and ($p->get_role||'') eq '#KNIT')) {
233 0 ▶ my $o_name = $orig_name{$table} || $table;
Condition0%0/3
$orig_name{$table} || $table
l!l&&r!l&&!r
000
MC/DC0%0/2
$orig_name{$table} || $table
$orig_name{$table} $table
Truth table0%0/3
A || B
A= $orig_name{$table}B= $table
ABresult
1X1
011
000
234 0 ▶ my $path =$column eq '#value' ? $o_name : $o_name.'/'.$column;
Branch: 1 branch
BranchTrueFalseTotal
$column eq '#value' ? : 0 0 0
235 0 ▶ unless (ref($opts{ref}) and exists ($opts{ref}{$path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}) 0 0 0
Condition0%0/3
ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $PMLTQ::PML2BASE::opts{"ref"} and exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
ref $PMLTQ::PML2BASE::opts{"ref"} exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
Truth table0%0/3
A and B
A= ref $PMLTQ::PML2BASE::opts{"ref"}B= exists $PMLTQ::PML2BASE::opts{"ref"}{$path}
ABresult
0X0
100
111
236 0 ▶ warn "UNHANDLED PMLREF: $path\n" if $warn;
Branch: 1 branch
BranchTrueFalseTotal
if $warn 0 0 0
237 0 return;
238 }
239 0 ▶ if ($opts{ref}{$path} ne '-') { # ignore
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"ref"}{$path} ne "-") 0 0 0
240 0 @{$ret} = split(/:/,$opts{ref}{$path},2);
241 0 return @$ret;
242 }
243 }
244 0 return;
245 }
246  
247 # column_spec returns one or more values for colspec
248 0 ▶sub column_spec {
Subroutine column_spec: not called CC=33 SCAR=70.2
Pod undocumented
249 0 my ($table,$column,$decl,$is_required,$role)=@_;
250 0 ▶ my $create_index = (!$decl->is_atomic or (($role||'') eq '#ID')) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!$decl->is_atomic || ($role || '') eq '#ID' ? : 0 0 0
Condition0%0/5
not $decl->is_atomic or ($role || "") eq "#ID"
l!l&&r!l&&!r
000
$role || ''
l!l
00
MC/DC0%0/2
not $decl->is_atomic or ($role || "") eq "#ID"
not $decl->is_atomic $role
Truth table0%0/3
not(A) or B
A= not $decl->is_atomicB= $role
ABresult
1X1
011
000
251 0 ▶ confess("cannot determine column type for undefined declaration")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decl 0 0 0
252 unless defined $decl;
253 0 my $decl_is = $decl->get_decl_type;
254 0 ▶ my $constraint = $is_required ? ' NOT NULL' : '';
Branch: 1 branch
BranchTrueFalseTotal
$is_required ? : 0 0 0
255 0 ▶ if ($decl_is == PML_CHOICE_DECL || $decl_is == PML_CONSTANT_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($decl_is == 9 or $decl_is == 10) { } 0 0 0
elsif ($decl_is == 8) { } 0 0 0
Condition0%0/3
$decl_is == 9 or $decl_is == 10
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 9 or $decl_is == 10
$decl_is == 9 $decl_is == 10
Truth table0%0/3
A or B
A= $decl_is == 9B= $decl_is == 10
ABresult
1X1
011
000
256 0 my $max = max(map length, $decl->get_values);
257 0 ▶ if (first { !/^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/ } $decl->get_values) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { not /^(?:0|-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$/; } , $decl->get_values)) { } 0 0 0
258 0 return [$column => varchar($max).$constraint,$create_index];
259 } else {
260 0 return [$column => numeric($max).$constraint,$create_index];
261 }
262 } elsif ($decl_is == PML_CDATA_DECL) {
263 0 my $format = $decl->get_format;
264 0 ▶ return [$column => 'INT'.$constraint,$create_index] if $format =~ /(integer$|int$|short$|byte|long)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /(integer$|int$|short$|byte|long)/i 0 0 0
265 0 ▶ return [$column => boolean().$constraint,$create_index] if $format eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "boolean" 0 0 0
266 0 ▶ return [$column => 'FLOAT'.$constraint,$create_index] if $format =~ /(decimal$|float$|double$)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $format =~ /(decimal$|float$|double$)/i 0 0 0
267 0 ▶ if ($format eq 'PMLREF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "PMLREF") 0 0 0
268 0 my ($target,$target_type) = get_pmlref_target_info($decl,$table,$column,1);
269 0 ▶ if ((!$opts{'no-schema'} || $opts{'incremental'} ) and
Branch: 1 branch
BranchTrueFalseTotal
if (!$PMLTQ::PML2BASE::opts{"no-schema"} || $PMLTQ::PML2BASE::opts{"incremental"} and defined $target || defined $target_type) 0 0 0
Condition0%0/9
!$PMLTQ::PML2BASE::opts{"no-schema"} || $PMLTQ::PML2BASE::opts{"incremental"} and defined $target || defined $target_type
!ll&&!rl&&r
000
not $PMLTQ::PML2BASE::opts{"no-schema"} or $PMLTQ::PML2BASE::opts{"incremental"}
l!l&&r!l&&!r
000
defined $target or defined $target_type
l!l&&r!l&&!r
000
MC/DC0%0/4
!$PMLTQ::PML2BASE::opts{"no-schema"} || $PMLTQ::PML2BASE::opts{"incremental"} and defined $target || defined $target_type
not $PMLTQ::PML2BASE::opts{"no-schema"} $PMLTQ::PML2BASE::opts{"incremental"} defined $target defined $target_type
Truth table0%0/7
not(A) or B and C or D
A= not $PMLTQ::PML2BASE::opts{"no-schema"}B= $PMLTQ::PML2BASE::opts{"incremental"}C= defined $targetD= defined $target_type
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
270 (defined($target) or defined($target_type))) {
271 0 ▶ if (!$target_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target_type) 0 0 0
272 0 $target_type=$target;
273 0 $target=$root_name;
274 }
275 0 my $target_id;
276 0 ▶ if ($target_type=~s/[@](.*)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_type =~ s/[\@](.*)$//) 0 0 0
277 0 $target_id=$1;
278 }
279 0 my $comment = "Updating PMLREF column: $table/$column refers to nodes in $target of type $target_type";
280 0 my $col = $column;
281 0 $col=~s/\.rf$//;
282 # Possible fix for #329 - table name is renamed twice
283 #$table = rename_type($table);
284 0 my $tt;
285 0 ▶ if ($target eq $root_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $root_name) { } 0 0 0
286 0 $tt = rename_type($target_type);
287 } else {
288 0 $tt = q(' || tab || ');
289 }
290 0 my $rename='';
291 # if ($opts{syntax}=~/(oracle|postgres)/) {
292 # $rename=<<"EOF";
293 # ALTER TABLE "$table" RENAME COLUMN "#tmp" TO "$col";
294 # EOF
295 # } else {
296 # $rename=<<"EOF";
297 # ALTER TABLE "$table" ADD "$col" INT;
298 # UPDATE "$table" t SET "$col"="#tmp";
299 # ALTER TABLE "$table" DROP COLUMN "#tmp";
300 # EOF
301 # }
302 0 ▶ unless ($target_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target_id) 0 0 0
303 0 my $target_decl = eval { PMLTQ::Common::QueryTypeToDecl($target_type,$schema,@{$opts{other_schemas}}) };
304 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
305 0 ▶ if ($target_decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_decl) 0 0 0
306 0 my $decl_is = $target_decl->get_decl_type;
307 0 ▶ if ($decl_is==PML_STRUCTURE_DECL or
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 3 or $decl_is == 4) 0 0 0
Condition0%0/3
$decl_is == 3 or $decl_is == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 3 or $decl_is == 4
$decl_is == 3 $decl_is == 4
Truth table0%0/3
A or B
A= $decl_is == 3B= $decl_is == 4
ABresult
1X1
011
000
308 $decl_is==PML_CONTAINER_DECL) {
309 0 my ($id_m) = $target_decl->find_members_by_role('#ID');
310 0 ▶ if ($id_m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_m) 0 0 0
311 0 $target_id = $id_m->get_name;
312 }
313 }
314 }
315 0 ▶ $target_id||='id';
Condition0%0/2
$target_id ||= "id"
l!l
00
MC/DC0%0/1
$target_id ||= "id"
$target_id
Truth table0%0/2
A
A= $target_id
Aresult
11
00
316 }
317 0 my $sql = <<"EOF";
318 UPDATE "$table" t SET "$col"=(SELECT a."#idx" FROM "$tt" a WHERE a."$target_id"=t."$column~" LIMIT 1) WHERE "$col" IS NULL;
319 EOF
320 0 ▶ unless ($opts{incremental}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
321 0 $sql .= <<"EOF";
322 ALTER TABLE "$table" DROP COLUMN "$column~";
323 EOF
324 }
325 # unless ($opts{'no-schema'}) {
326 # $sql .= <<"EOF";
327 # CREATE INDEX "#i_${root_name}_$index_id" ON "$table" ("$col");
328 # EOF
329 # }
330 0 ▶ unless ($target eq $root_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target eq $root_name) 0 0 0
331 0 $sql =~ s/'/''/g;
332 0 my $execute = join("\n",map {qq(EXECUTE (''$_'');)} grep !/^\s*--/, grep /\S/, split /;\s*\n/, $sql);
333 0 $sql = <<"EOF"
334 CREATE OR REPLACE FUNCTION pml2base__update_pmlref() RETURNS integer AS '
335 DECLARE
336 tab VARCHAR(40);
337 BEGIN
338 SELECT "table" INTO tab FROM "#PMLTABLES" WHERE "type"=''$target_type'';
339 IF tab IS NULL THEN tab := ''$target_type''; END IF;
340 $execute
341 RETURN 1;
342 END;
343 ' LANGUAGE plpgsql;
344  
345 SELECT pml2base__update_pmlref();
346  
347 DROP FUNCTION pml2base__update_pmlref();
348  
349 EOF
350 }
351 0 $fh{'#POST_SQL'}->print($sql);
352 0 $index_id++;
353 #my $fk="";
354 #$fk=' FOREIGN KEY REFERENCES "$tt" ("#idx")' if $target eq $root_name;
355 {
356 0 my $col = $column;
357 0 $col=~s/\.rf$//;
358 0 return ([$column.'~' => 'STRING()'.$constraint,1], [$col => 'INT',1]);
359 }
360 }
361 }
362 0 return [$column => 'STRING()'.$constraint,$create_index];
363 } else {
364 0 my $ref = table_name($decl);
365 0 ▶ return [$column => qq{INT${constraint} FOREIGN KEY REFERENCES "$ref" ("#idx")}, 1]
Branch: 1 branch
BranchTrueFalseTotal
if $decl_is == 4 or $decl_is == 3 or $decl_is == 5 0 0 0
Condition0%0/6
$decl_is == 4 or $decl_is == 3 or $decl_is == 5
l!l&&r!l&&!r
000
$decl_is == 4 or $decl_is == 3
l!l&&r!l&&!r
000
MC/DC0%0/3
$decl_is == 4 or $decl_is == 3 or $decl_is == 5
$decl_is == 4 $decl_is == 3 $decl_is == 5
Truth table0%0/4
A or B or C
A= $decl_is == 4B= $decl_is == 3C= $decl_is == 5
ABCresult
1XX1
01X1
0011
0000
366 if ($decl_is==PML_CONTAINER_DECL or $decl_is==PML_STRUCTURE_DECL or $decl_is==PML_SEQUENCE_DECL);
367 0 return [$column => 'INT'.$constraint, $create_index];
368 }
369 }
370  
371 0 ▶sub to_filename {
Subroutine to_filename: not called CC=3 SCAR=24.8
Pod undocumented
372 0 my ($tab,$ext)=@_;
373 0 ▶ $ext ||= 'dump';
Condition0%0/2
$ext ||= "dump"
l!l
00
MC/DC0%0/1
$ext ||= "dump"
$ext
Truth table0%0/2
A
A= $ext
Aresult
11
00
374 0 $tab=~s{/}{_0}g;
375 0 ▶ if ($tab=~s/__#/__1/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab =~ s/__#/__1/s) { } 0 0 0
376 0 return $tab.'.'.$ext;
377 } else {
378 0 return $root_name.'__'.$tab.'.'.$ext;
379 }
380 }
381 0 ▶sub table2filename {
Subroutine table2filename: not called CC=3 SCAR=24.8
Pod undocumented
382 0 my ($tab,$ext)=@_;
383 0 $tab=~s{/#content((?:/|$))}{/7content$1}g;
384 0 ▶ if ($tab=~/#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab =~ /#/) { } 0 0 0
385 0 return to_filename($tab,$ext);
386 } else {
387 0 ▶ $ext ||= 'dump';
Condition0%0/2
$ext ||= "dump"
l!l
00
MC/DC0%0/1
$ext ||= "dump"
$ext
Truth table0%0/2
A
A= $ext
Aresult
11
00
388 0 $tab=~s{/}{_0}g;
389 0 return $root_name.'__type_'.$tab.'.'.$ext;
390 }
391 }
392  
393 0 ▶sub _abs2rel {
Subroutine _abs2rel: not called CC=6 SCAR=37.4
394 0 my ($file)=@_;
395 0 my $base=$opts{'data-dir'}; # we assume base has already been abs-path'ed
396 0 ▶ return $file unless defined($base) and length($base);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base and length $base 0 0 0
Condition0%0/3
defined $base and length $base
!ll&&!rl&&r
000
MC/DC0%0/2
defined $base and length $base
defined $base length $base
Truth table0%0/3
A and B
A= defined $baseB= length $base
ABresult
0X0
100
111
397 0 ▶ if (UNIVERSAL::isa($file,'URI')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($file, "URI")) 0 0 0
398 0 ▶ if ($file->scheme eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($file->scheme eq 'file') { } 0 0 0
elsif (not $file->scheme) { } 0 0 0
399 0 $file=$file->file;
400 } elsif (!$file->scheme) {
401 0 $file->scheme('file');
402 0 $file=$file->file;
403 } else {
404 0 return $file;
405 }
406 }
407 # This shouldn't be needed anymore
408 #$file = Cwd::abs_path($file);
409 0 return File::Spec->abs2rel($file,$base);
410 }
411  
412 0 ▶sub abs2rel {
Subroutine abs2rel: not called CC=2 SCAR=17.9
Pod undocumented
413 0 my ($file)=@_;
414 0 my $ret = _abs2rel($file);
415 0 ▶ croak "Incorrect --data_dir value '$opts{'data-dir'}' (resolved to '$ret') or invalid filename '$file'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $ret =~ /^\.\./ 0 0 0
416 ."Explanation: Paths stored in the database should not start with ../ since this breaks URLs"
417 if $ret=~m{^\.\.};
418 0 return $ret;
419 }
420  
421 6 our %node_schema = (
422 colspec => [
423 ["#idx", 'INT NOT NULL PRIMARY KEY',0],
424 ["#r", 'INT NOT NULL', 1],
425 ["#lvl", 'INT NOT NULL',0],
426 ["#chld", 'INT NOT NULL',0],
427 ["#chord", 'INT NOT NULL',0],
428 ["#parent_idx", 'INT', 1],
429 ["#root_idx", 'INT NOT NULL', 1],
430 ["#name", 'STRING()',0],
431 ["#type", 'STRING()',0],
432 ["#min_ord", 'INT',0],
433 ["#max_ord", 'INT',0],
434 # ["#ID", 'STRING()',0]
435 ],
436 );
437  
438 0 ▶sub convert_schema {
Subroutine convert_schema: not called CC=32 SCAR=69.6
Pod undocumented
439 0 $schema = shift;
440 0 my ($opts)=@_;
441 0 ▶ if ($opts{'load-rename-map'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"load-rename-map"}) 0 0 0
442 0 ▶ open my $fh, '<:utf8', $opts{'load-rename-map'} or die "Cannot load rename map: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:utf8", $PMLTQ::PML2BASE::opts{"load-rename-map"} or die "Cannot load rename map: $!\n" 0 0 0
443 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
444 0 chomp;
445 0 my ($k,$v)=split /\t/,$_;
446 0 $opts{'rename-type'}{$k}=$v;
447 }
448 0 close $fh;
449 }
450 0 ▶ if ($opts{'rename-type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{'rename-type'}) { } 0 0 0
451 0 %orig_name=(reverse %{$opts{'rename-type'}});
452 } else {
453 0 %orig_name=();
454 }
455  
456 # in theory, we can now check whether we need #min_ord and #max_ord at all
457 # and drop them if not
458  
459 0 $root_name= $opts{prefix}.$schema->get_root_name;
460 0 $node_table = $root_name."__#trees";
461 0 $file_table = $root_name."__#files";
462 0 $references_table = $root_name."__#references";
463 0 my $pmlref_table = $root_name."__#pmlref_map";
464 0 ▶ open $fh{'#INIT_LIST'},'>',get_full_path(to_filename("init",'list')) || die "$!";
Condition0%0/2
get_full_path(to_filename('init', 'list')) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename('init', 'list')) || die("$!")
get_full_path(to_filename('init', 'list'))
Truth table0%0/2
A
A= get_full_path(to_filename('init', 'list'))
Aresult
11
00
465 0 ▶ unless ($opts{'no-schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"no-schema"}) 0 0 0
466 0 ▶ open $fh{'#INIT_SQL'},'>',get_full_path(to_filename("init",'sql')) || die "$!";
Condition0%0/2
get_full_path(to_filename('init', 'sql')) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename('init', 'sql')) || die("$!")
get_full_path(to_filename('init', 'sql'))
Truth table0%0/2
A
A= get_full_path(to_filename('init', 'sql'))
Aresult
11
00
467 0 ▶ open $fh{'#DELETE_SQL'},'>',get_full_path(to_filename("delete",'sql')) || die "$!";
Condition0%0/2
get_full_path(to_filename('delete', 'sql')) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename('delete', 'sql')) || die("$!")
get_full_path(to_filename('delete', 'sql'))
Truth table0%0/2
A
A= get_full_path(to_filename('delete', 'sql'))
Aresult
11
00
468 }
469 0 ▶ unless ($opts{'no-schema'} and !$opts{'incremental'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"no-schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
Condition0%0/3
$PMLTQ::PML2BASE::opts{"no-schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}
!ll&&!rl&&r
000
MC/DC0%0/2
$PMLTQ::PML2BASE::opts{"no-schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}
$PMLTQ::PML2BASE::opts{"no-schema"} not $PMLTQ::PML2BASE::opts{"incremental"}
Truth table0%0/3
A and not(B)
A= $PMLTQ::PML2BASE::opts{"no-schema"}B= not $PMLTQ::PML2BASE::opts{"incremental"}
ABresult
0X0
100
111
470 0 ▶ open $fh{'#POST_SQL'},'>',get_full_path(to_filename("postprocess",'sql')) || die "$!";
Condition0%0/2
get_full_path(to_filename('postprocess', 'sql')) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename('postprocess', 'sql')) || die("$!")
get_full_path(to_filename('postprocess', 'sql'))
Truth table0%0/2
A
A= get_full_path(to_filename('postprocess', 'sql'))
Aresult
11
00
471 }
472 0 ▶ open $fh{'#FILE_TABLE'},'>',get_full_path(to_filename($file_table)) || die "$!";
Condition0%0/2
get_full_path(to_filename($file_table)) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename($file_table)) || die("$!")
get_full_path(to_filename($file_table))
Truth table0%0/2
A
A= get_full_path(to_filename($file_table))
Aresult
11
00
473 0 ▶ open $fh{'#REFFILE_TABLE'},'>',get_full_path(to_filename($references_table)) || die "$!";
Condition0%0/2
get_full_path(to_filename($references_table)) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename($references_table)) || die("$!")
get_full_path(to_filename($references_table))
Truth table0%0/2
A
A= get_full_path(to_filename($references_table))
Aresult
11
00
474 0 ▶ open $fh{$node_table},'>',get_full_path(to_filename($node_table)) || die "$!";
Condition0%0/2
get_full_path(to_filename($node_table)) || die("$!")
l!l
00
MC/DC0%0/1
get_full_path(to_filename($node_table)) || die("$!")
get_full_path(to_filename($node_table))
Truth table0%0/2
A
A= get_full_path(to_filename($node_table))
Aresult
11
00
475  
476 0 my ($db_cmd,$ldr_cmd,$extra_flags);
477 0 $extra_flags='';
478 0 $db_cmd = 'psql';
479 0 $ldr_cmd = 'psql';
480 0 ▶ if ($opts{'schema'} and !$opts{'incremental'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
Condition0%0/3
$PMLTQ::PML2BASE::opts{"schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}
!ll&&!rl&&r
000
MC/DC0%0/2
$PMLTQ::PML2BASE::opts{"schema"} and not $PMLTQ::PML2BASE::opts{"incremental"}
$PMLTQ::PML2BASE::opts{"schema"} not $PMLTQ::PML2BASE::opts{"incremental"}
Truth table0%0/3
A and not(B)
A= $PMLTQ::PML2BASE::opts{"schema"}B= not $PMLTQ::PML2BASE::opts{"incremental"}
ABresult
0X0
100
111
481 0 $extra_flags.=' --init|--finish'
482 }
483  
484 0 $schema{$node_table} = {
485 table => $node_table,
486 %node_schema,
487 };
488 0 $schema{$file_table} = {
489 '#decl_order' => 0,
490 table => $file_table,
491 colspec => [
492 ["#idx", 'INT NOT NULL PRIMARY KEY',0],
493 ["file", 'STRING()',0],
494 ["tree_no", 'INT',0],
495 ["top", boolean(),0],
496 ],
497 col => { file=>0 },
498 };
499 0 $schema{$references_table} = {
500 '#decl_order' => 0,
501 table => $references_table,
502 colspec => [
503 ["source", 'STRING()',0],
504 ["name", 'STRING()',0],
505 ["id", 'STRING()',1],
506 ["file", 'STRING()',0],
507 ],
508 col => { file=>0, name=>0, id=>0, source=>0 },
509 };
510  
511  
512 0 ▶ unless ($opts{'no-schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"no-schema"}) 0 0 0
513 0 $fh{'#INIT_LIST'}->print(to_filename("delete",'sql')."\n");
514 0 $fh{'#INIT_LIST'}->print(to_filename("init",'sql')."\n");
515 0 dump_schema($schema);
516 0 for my $decl ($schema->node_types) {
517 0 my $tab = table_name($decl,1);
518 0 $fh{'#INIT_SQL'}->print(qq{INSERT INTO "#PMLTYPES" VALUES('$tab','$root_name');\n\n});
519 }
520 0 $fh{'#DELETE_SQL'}->print(qq{DELETE FROM "#PML" WHERE "root"='$root_name';\n\n});
521 0 $fh{'#DELETE_SQL'}->print(qq{DELETE FROM "#PMLTYPES" WHERE "root"='$root_name';\n\n});
522  
523 # $fh{'#INIT_SQL'}->print(qq{CREATE TABLE "" (}.
524 # qq{ "ref_type" }.varchar(128).
525 # qq{, "ref_table" }.varchar(MAX_NAME_LENGTH).
526 # qq{, "target_layer" }.varchar(128).
527 # qq{, "target_table" }.varchar(MAX_NAME_LENGTH).
528 # qq{, "target_type" }.varchar(128).
529 # qq{, "pmref" }.boolean().qq{);\n});
530 0 $fh{'#INIT_SQL'}->print(qq{CREATE TABLE "$pmlref_table" (}.
531 qq{ "ref_type" }.varchar(128).
532 qq{, "ref_table" }.varchar(MAX_NAME_LENGTH).
533 qq{, "target_layer" }.varchar(128).
534 qq{, "target_table" }.varchar(MAX_NAME_LENGTH).
535 qq{, "target_type" }.varchar(128).qq{);\n\n});
536 0 $fh{'#DELETE_SQL'}->print(qq{DROP TABLE IF EXISTS "$pmlref_table";\n\n});
537 0 for my $k (sort keys %{$opts{ref}}) {
538 0 my ($t1,$t2) = split /:/,$opts{ref}{$k};
539 0 ▶ unless ($t2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t2) 0 0 0
540 0 $t2=$t1;
541 0 $t1=$root_name;
542 }
543 0 my $tab = rename_type($k);
544 0 ▶ if ($t1 eq $root_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t1 eq $root_name) { } 0 0 0
545 0 my $tab = rename_type($t2);
546 0 $fh{'#INIT_SQL'}->print(qq{INSERT INTO "$pmlref_table" VALUES('$k','$tab','$t1','$tab','$t2');\n\n});
547 } else {
548 0 $fh{'#INIT_SQL'}->print(qq{INSERT INTO "$pmlref_table" VALUES('$k','$tab','$t1',}.
549 qq{(SELECT "table" FROM "#PMLTABLES" WHERE "type"='$t2'),'$t2');\n\n});
550 0 $fh{'#INIT_SQL'}->print(qq{UPDATE "$pmlref_table" SET ("target_table")=('$t2') }.
551 qq{WHERE "ref_type"='$k' AND "target_table" IS NULL;\n\n});
552 }
553 }
554 }
555  
556 0 my $decl_order=10;
557 $schema->for_each_decl(
558 0 ▶ sub {
Subroutine __ANON__: not called CC=43 SCAR=75.5
559 0 my ($decl)=@_;
560 0 my $decl_is = $decl->get_decl_type;
561 0 ▶ return if ($decl->get_role||'') eq '#CHILDNODES';
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_role || "") eq "#CHILDNODES" 0 0 0
Condition0%0/2
$decl->get_role || ''
l!l
00
MC/DC0%0/1
$decl->get_role || ''
$decl->get_role
Truth table0%0/2
A
A= $decl->get_role
Aresult
11
00
562 0 ▶ return if $decl_is == PML_TYPE_DECL or $decl_is==PML_ROOT_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $decl_is == 1 or $decl_is == 2 0 0 0
Condition0%0/3
$decl_is == 1 or $decl_is == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 1 or $decl_is == 2
$decl_is == 1 $decl_is == 2
Truth table0%0/3
A or B
A= $decl_is == 1B= $decl_is == 2
ABresult
1X1
011
000
563 0 my $p=$decl->get_parent_decl;
564 0 ▶ if ($p and $p->get_decl_type == PML_MEMBER_DECL
Branch: 1 branch
BranchTrueFalseTotal
if ($p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES") 0 0 0
Condition0%0/8
$p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES"
!ll&&!rl&&r
000
$p and $p->get_decl_type == 12
!ll&&!rl&&r
000
$p->get_role || ''
l!l
00
MC/DC0%0/3
$p and $p->get_decl_type == 12 and ($p->get_role || "") eq "#CHILDNODES"
$p $p->get_decl_type == 12 $p->get_role
Truth table0%0/4
A and B and C
A= $pB= $p->get_decl_type == 12C= $p->get_role
ABCresult
0XX0
10X0
1100
1111
565 and ($p->get_role||'') eq '#CHILDNODES') {
566 0 return;
567 }
568 0 my $table = table_name($decl);
569 0 my $desc;
570 0 ▶ my $is_node = (($opts{no_tree_table}||$opts{hybrid}) && (($decl->get_role||'') eq '#NODE')) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($PMLTQ::PML2BASE::opts{'no_tree_table'} || $PMLTQ::PML2BASE::opts{'hybrid'}) && ($decl->get_role || '') eq '#NODE' ? : 0 0 0
Condition0%0/8
$PMLTQ::PML2BASE::opts{"no_tree_table"} || $PMLTQ::PML2BASE::opts{"hybrid"} and ($decl->get_role || "") eq "#NODE"
!ll&&!rl&&r
000
$PMLTQ::PML2BASE::opts{"no_tree_table"} or $PMLTQ::PML2BASE::opts{"hybrid"}
l!l&&r!l&&!r
000
$decl->get_role || ''
l!l
00
MC/DC0%0/3
$PMLTQ::PML2BASE::opts{"no_tree_table"} || $PMLTQ::PML2BASE::opts{"hybrid"} and ($decl->get_role || "") eq "#NODE"
$PMLTQ::PML2BASE::opts{"no_tree_table"} $PMLTQ::PML2BASE::opts{"hybrid"} $decl->get_role
Truth table0%0/5
A or B and C
A= $PMLTQ::PML2BASE::opts{"no_tree_table"}B= $PMLTQ::PML2BASE::opts{"hybrid"}C= $decl->get_role
ABCresult
00X0
1X00
0100
1X11
0111
571 0 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 10 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 0 0 0
elsif ($decl_is == 4) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 13) { } 0 0 0
elsif ($decl_is == 6) { } 0 0 0
elsif ($decl_is == 7) { } 0 0 0
elsif ($decl_is == 9) { } 0 0 0
elsif ($decl_is == 10) { } 0 0 0
elsif ($decl_is == 8) { } 0 0 0
elsif ($decl_is == 11 or $decl_is == 12 or $decl_is == 13) { } 0 0 0
572 my @m = grep {
573 0 ▶ (!defined($_->get_role) or ($_->get_role ne '#CHILDNODES' and $_->get_role ne '#TREES'))
Condition0%0/14
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
!ll&&!rl&&r
000
not defined $_->get_role or $_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
l!l&&r!l&&!r
000
$_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
!ll&&!rl&&r
000
$_->get_content_decl && $_->get_content_decl->get_role || ''
l!l
00
$_->get_content_decl and $_->get_content_decl->get_role
!ll&&!rl&&r
000
MC/DC0%0/5
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
not defined $_->get_role $_->get_role ne "#CHILDNODES" $_->get_role ne "#TREES" $_->get_content_decl $_->get_content_decl->get_role
Truth table0%0/8
not(A) or B and C && D and E
A= not defined $_->get_roleB= $_->get_role ne "#CHILDNODES"C= $_->get_role ne "#TREES"D= $_->get_content_declE= $_->get_content_decl->get_role
ABCDEresult
00XXX0
010XX0
1XX0X0
1XX100
0110X0
011100
1XX111
011111
574 and (($_->get_content_decl && $_->get_content_decl->get_role ||'') ne '#TREES')
575 } $decl->get_members;
576 $desc = {
577 table=> $table,
578 colspec => [
579 0 ▶ ($is_node ? @{$node_schema{colspec}} : ['#idx', 'INT NOT NULL PRIMARY KEY', 0]),
Branch: 1 branch
BranchTrueFalseTotal
$is_node ? : 0 0 0
580 map column_spec($table,$_->get_knit_name,$_->get_knit_content_decl,$_->is_required,$_->get_role),
581 @m
582 ],
583 };
584 } elsif ($decl_is == PML_CONTAINER_DECL) {
585 my ($content_decl) = grep {
586 0 ▶ (!defined($_->get_role) or ($_->get_role ne '#CHILDNODES' and $_->get_role ne '#TREES'))
Condition0%0/14
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
!ll&&!rl&&r
000
not defined $_->get_role or $_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
l!l&&r!l&&!r
000
$_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
!ll&&!rl&&r
000
$_->get_content_decl && $_->get_content_decl->get_role || ''
l!l
00
$_->get_content_decl and $_->get_content_decl->get_role
!ll&&!rl&&r
000
MC/DC0%0/5
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
not defined $_->get_role $_->get_role ne "#CHILDNODES" $_->get_role ne "#TREES" $_->get_content_decl $_->get_content_decl->get_role
Truth table0%0/8
not(A) or B and C && D and E
A= not defined $_->get_roleB= $_->get_role ne "#CHILDNODES"C= $_->get_role ne "#TREES"D= $_->get_content_declE= $_->get_content_decl->get_role
ABCDEresult
00XXX0
010XX0
1XX0X0
1XX100
0110X0
011100
1XX111
011111
587 and ((($_->get_content_decl && $_->get_content_decl->get_role) ||'') ne '#TREES')
588 } grep defined, $decl->get_knit_content_decl;
589 $desc = {
590 table=> $table,
591 colspec => [
592 0 ▶ ($is_node ? @{$node_schema{colspec}} : ['#idx', 'INT NOT NULL PRIMARY KEY']),
Branch: 2 branches
BranchTrueFalseTotal
$is_node ? : 0 0 0
$content_decl ? : 0 0 0
593 ($content_decl ? column_spec($table,"#content",$content_decl,$content_decl->get_role) : ()),
594 map column_spec($table,$_->get_name,$_->get_content_decl,$_->is_required,$_->get_role), $decl->get_attributes
595 ],
596 };
597 } elsif ($decl_is == PML_SEQUENCE_DECL) {
598 0 $desc = {
599 table=> $table,
600 colspec => [
601 ["#idx", 'INT NOT NULL PRIMARY KEY',0],
602 map [$_->get_name,'INT',1], $decl->get_elements
603 ],
604 };
605 } elsif ($decl_is == PML_ELEMENT_DECL) {
606 0 my $content_decl = $decl->get_knit_content_decl;
607 0 $table = '#e_'.table_name($content_decl);
608 0 $desc = {
609 table=> $table,
610 colspec => [
611 ["#idx",'INT'],
612 ["#pos",'INT'],
613 ["#elpos",'INT'],
614 column_spec($table,'#value',$content_decl,$content_decl->get_role)
615 ]
616 };
617 } elsif ($decl_is == PML_LIST_DECL) {
618 0 my $content_decl = $decl->get_knit_content_decl;
619 0 ▶ $desc = {
Branch: 1 branch
BranchTrueFalseTotal
$decl->is_ordered ? : 0 0 0
620 table=> $table,
621 colspec => [
622 ["#idx",'INT',1],
623 ($decl->is_ordered ? ["#pos",'INT'] : ()),
624 column_spec($table,'#value',$content_decl,$content_decl->get_role),
625 ]
626 };
627 } elsif ($decl_is == PML_ALT_DECL) {
628 0 my $content_decl = $decl->get_knit_content_decl;
629 0 $desc = {
630 table=> $table,
631 colspec => [
632 ["#idx",'INT',1],
633 column_spec($table,'#value',$content_decl,$content_decl->get_role),
634 ]
635 };
636 } elsif ($decl_is == PML_CHOICE_DECL) {
637 } elsif ($decl_is == PML_CONSTANT_DECL) {
638 } elsif ($decl_is == PML_CDATA_DECL) {
639 ▶ } elsif ($decl_is == PML_ATTRIBUTE_DECL
Condition0%0/6
$decl_is == 11 or $decl_is == 12 or $decl_is == 13
l!l&&r!l&&!r
000
$decl_is == 11 or $decl_is == 12
l!l&&r!l&&!r
000
MC/DC0%0/3
$decl_is == 11 or $decl_is == 12 or $decl_is == 13
$decl_is == 11 $decl_is == 12 $decl_is == 13
Truth table0%0/4
A or B or C
A= $decl_is == 11B= $decl_is == 12C= $decl_is == 13
ABCresult
1XX1
01X1
0011
0000
640 || $decl_is == PML_MEMBER_DECL
641 || $decl_is == PML_ELEMENT_DECL) {
642 # print $decl->get_parent_decl->get_decl_path,"/[".$decl->get_name,"]\n";
643 } else {
644 0 print STDERR "Unexpected decl: ",$decl->get_decl_type_str,"\n";
645 }
646 0 ▶ if ($desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc) 0 0 0
647 0 ▶ warn "couldn't determine table name for decl $decl\n" if !defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 0 0
648 0 $desc->{'#decl_order'}=$decl_order++;
649 0 $schema{$desc->{table}}=$desc;
650 0 ▶ unless ($opts{schema}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"schema"}) 0 0 0
651 0 my $fn = table2filename($desc->{table});
652 0 ▶ open $fh{$desc->{table}},'>',get_full_path($fn) or die "Cannot open '$fn' for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh{$desc->{"table"}}, ">", get_full_path($fn) or die "Cannot open '${fn}' for writing: $!" 0 0 0
653 }
654 }
655 0 });
656 0 ▶ if ($opts and ref $opts->{for_schema}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts and ref $opts->{"for_schema"}) 0 0 0
Condition0%0/3
$opts and ref $opts->{"for_schema"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts and ref $opts->{"for_schema"}
$opts ref $opts->{"for_schema"}
Truth table0%0/3
A and B
A= $optsB= ref $opts->{"for_schema"}
ABresult
0X0
100
111
657 0 $opts->{for_schema}->($schema,\%schema,\%fh);
658 }
659  
660 0 ▶ if ($opts{'load-idx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"load-idx"}) 0 0 0
661 0 ▶ if (open my $fh, '<:', $opts{'load-idx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<:', $PMLTQ::PML2BASE::opts{'load-idx'}) { } 0 0 0
662 0 $_ = <$fh>;
663 0 chomp;
664 0 ($idx, $node_idx) = split /\t/,$_,2;
665 0 close $fh;
666 } else {
667 0 warn "Cannot load idx info: $!\n";
668 }
669 }
670 0 ▶ if ($opts{'load-col-info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"load-col-info"}) 0 0 0
671 0 ▶ open my $fh, '<:utf8', $opts{'load-col-info'} or die "Cannot load rename map: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:utf8", $PMLTQ::PML2BASE::opts{"load-col-info"} or die "Cannot load rename map: $!\n" 0 0 0
672 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
673 0 chomp;
674 0 my ($table,$column,$length,$non_ascii)=split /\t/,$_;
675 0 ▶ my $l = $schema{$table}{col}{$column}||0;
Condition0%0/2
$schema{$table}{'col'}{$column} || 0
l!l
00
MC/DC0%0/1
$schema{$table}{'col'}{$column} || 0
$schema{$table}{'col'}{$column}
Truth table0%0/2
A
A= $schema{$table}{'col'}{$column}
Aresult
11
00
676 0 ▶ $schema{$table}{col}{$column} = $length if $length>$l;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $l 0 0 0
677 0 ▶ $schema{$table}{non_ascii}{$column} ||= $non_ascii;
Condition0%0/3
$schema{$table}{"non_ascii"}{$column} ||= $non_ascii
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema{$table}{"non_ascii"}{$column} ||= $non_ascii
$schema{$table}{"non_ascii"}{$column} $non_ascii
Truth table0%0/3
A ||= B
A= $schema{$table}{"non_ascii"}{$column}B= $non_ascii
ABresult
1X1
011
000
678 }
679 0 close $fh;
680 }
681 }
682  
683  
684 # this function creates a loader that loads a PML schema into the database
685 # and stores information about the schema in the #PML table
686 0 ▶sub dump_schema {
Subroutine dump_schema: not called CC=8 SCAR=42.8
Pod undocumented
687 0 my ($schema,$append)=@_;
688 0 ▶ return if $opts{'no-schema'};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"no-schema"} 0 0 0
689 0 my $root_name = $schema->get_root_name;
690 0 ▶ return if ($seen_ref_schema{$root_name});
Branch: 1 branch
BranchTrueFalseTotal
if $seen_ref_schema{$root_name} 0 0 0
691 0 $seen_ref_schema{$root_name}=1;
692 0 $root_name = $opts{prefix}.$root_name;
693  
694 0 my $data_dir = $opts{'data-dir'};
695 0 my $filename= _abs2rel($schema->get_url);
696 0 ▶ if ($filename=~/\.\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /\.\./) 0 0 0
697 0 $filename = "".$schema->get_url; # using absolute URL
698 }
699  
700 0 my $flags = MAX_MIN_ORD | TOP_TREE_FLAG;
701 0 ▶ $flags |= HYBRID if $opts{hybrid};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"hybrid"} 0 0 0
702 0 ▶ $flags |= NO_TREE_TABLE if $opts{no_tree_table};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"no_tree_table"} 0 0 0
703  
704 0 my $schema_dump = "${root_name}__schema.dump";
705 0 my $blob;
706 0 $schema->write({string=>\$blob});
707 0 open(my $fh, '>', get_full_path($schema_dump));
708 0 my $r=$root_name;
709  
710 0 s{(\\|\n|\r|\^)}{\\$1}g for $r,$filename,$data_dir,$blob;
711 0 print $fh ($r.'^',
712 $filename.'^',
713 $data_dir.'^',
714 $flags.'^',
715 $blob
716 );
717 0 close $fh;
718 0 my $ctl = "${root_name}__pml_init.ctl";
719 0 ▶ open $fh, ($append ? '>>' : '>'), get_full_path($ctl);
Branch: 1 branch
BranchTrueFalseTotal
$append ? : 0 0 0
720  
721 0 print $fh <<"EOF";
722 COPY "#PML" ("root", "schema_file", "data_dir", "flags", "schema") FROM '$schema_dump' DELIMITER '^'
723 EOF
724 0 close $fh;
725 0 $fh{'#INIT_LIST'}->print("$ctl\n");
726 }
727  
728 0 ▶sub analyze_string {
Subroutine analyze_string: not called CC=14 SCAR=53.5
Pod undocumented
729 0 my ($table,$column,$string)=@_;
730 0 ▶ return unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 0 0
731 0 ▶ my $l = length($string) || 0;
Condition0%0/2
length $string || 0
l!l
00
MC/DC0%0/1
length $string || 0
length $string
Truth table0%0/2
A
A= length $string
Aresult
11
00
732 0 ▶ if ($opts{'enforce-col-info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{'enforce-col-info'}) { } 0 0 0
733 0 ▶ for ($schema{$table}{col}{$column}||0) {
Condition0%0/2
$schema{$table}{'col'}{$column} || 0
l!l
00
MC/DC0%0/1
$schema{$table}{'col'}{$column} || 0
$schema{$table}{'col'}{$column}
Truth table0%0/2
A
A= $schema{$table}{'col'}{$column}
Aresult
11
00
734 0 ▶ if ($l > $_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l > $_) 0 0 0
735 0 warn "Truncating value in table $table, column $column from $l to $_ chars\n";
736 0 $_[2] = substr($string,0,$_);
737 }
738 }
739 0 ▶ warn "NON-ASCII value in table $table, column $column\n" if !$schema{$table}{non_ascii}{$column} and $string=~/[^[:ascii:]]/;
Branch: 1 branch
BranchTrueFalseTotal
if not $schema{$table}{"non_ascii"}{$column} and $string =~ /[^[:ascii:]]/ 0 0 0
Condition0%0/3
not $schema{$table}{"non_ascii"}{$column} and $string =~ /[^[:ascii:]]/
!ll&&!rl&&r
000
MC/DC0%0/2
not $schema{$table}{"non_ascii"}{$column} and $string =~ /[^[:ascii:]]/
not $schema{$table}{"non_ascii"}{$column} $string =~ /[^[:ascii:]]/
Truth table0%0/3
not(A) and B
A= not $schema{$table}{"non_ascii"}{$column}B= $string =~ /[^[:ascii:]]/
ABresult
0X0
100
111
740 } else {
741 0 for ($schema{$table}{col}{$column}) {
742 0 ▶ $l+=10 if $opts{incremental};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"incremental"} 0 0 0
743 0 ▶ $_=$l if $l > ($_||0)
Branch: 1 branch
BranchTrueFalseTotal
if $l > ($_ || 0) 0 0 0
Condition0%0/2
$_ || 0
l!l
00
MC/DC0%0/1
$_ || 0
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
744 }
745 0 ▶ $schema{$table}{non_ascii}{$column}=1 if $string=~/[^[:ascii:]]/;
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /[^[:ascii:]]/ 0 0 0
746 }
747 }
748  
749 0 ▶sub dump_typemap {
Subroutine dump_typemap: not called CC=4 SCAR=30.0
Pod undocumented
750 0 my $typemap = $opts{'rename-type'};
751 0 ▶ return unless ref $typemap;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $typemap 0 0 0
752 0 my ($type_name, $table_name);
753 0 ▶ while (($type_name,$table_name)=each %$typemap) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$typemap) 0 0 0
754 0 ▶ if (exists $schema{$table_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema{$table_name}) 0 0 0
755 # qq{DELETE FROM "#PMLTABLES" WHERE "type"='$type_name';\n}.
756 0 $fh{'#INIT_SQL'}->print(qq{INSERT INTO "#PMLTABLES" VALUES('$type_name','$table_name');\n\n});
757 0 $fh{'#DELETE_SQL'}->print(qq{DELETE FROM "#PMLTABLES" WHERE "type"='$type_name';\n\n});
758 }
759 }
760 }
761  
762 0 ▶sub convert_references {
Subroutine convert_references: not called CC=9 SCAR=45.0
Pod undocumented
763 0 my ($source,$schema,$references,$refnames,$refdata,$opts)=@_;
764 0 ▶ return unless keys %$references;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$references 0 0 0
765 0 $source = abs2rel($source);
766 0 analyze_string($references_table,source =>$source);
767 my %name = map {
768 0 my $name = $_;
769 0 my $ids = $refnames->{$name};
770 0 ▶ ref($ids) ? (map { $_ => $name } @$ids) : ( $ids => $name )
Branch: 1 branch
BranchTrueFalseTotal
ref $ids ? : 0 0 0
771 } keys %$refnames;
772 0 my ($id,$reffile,$name);
773 0 ▶ while (($id,$reffile)=each %$references) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$references) 0 0 0
774 0 $name = $name{$id};
775 0 my $r = $schema->get_named_reference_info($name);
776 0 ▶ next unless $r and $r->{readas}; # skip references that are not requried
Branch: 1 branch
BranchTrueFalseTotal
unless $r and $r->{"readas"} 0 0 0
Condition0%0/3
$r and $r->{"readas"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and $r->{"readas"}
$r $r->{"readas"}
Truth table0%0/3
A and B
A= $rB= $r->{"readas"}
ABresult
0X0
100
111
777 0 my $file = abs2rel($reffile);
778 0 analyze_string($references_table,name =>$name);
779 0 analyze_string($references_table,id =>$id);
780 0 analyze_string($references_table,file =>$file);
781 0 $fh{'#REFFILE_TABLE'}->print(mkdump($source,$name,$id,$file));
782 0 ▶ if ($r->{readas} eq 'pml' and ref($refdata)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"readas"} eq "pml" and ref $refdata) 0 0 0
Condition0%0/3
$r->{"readas"} eq "pml" and ref $refdata
!ll&&!rl&&r
000
MC/DC0%0/2
$r->{"readas"} eq "pml" and ref $refdata
$r->{"readas"} eq "pml" ref $refdata
Truth table0%0/3
A and B
A= $r->{"readas"} eq "pml"B= ref $refdata
ABresult
0X0
100
111
783 # we need to extract the schema
784 0 my $refpml = $refdata->{$id};
785 0 ▶ if (UNIVERSAL::DOES::does($refpml,'Treex::PML::Instance')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($refpml, "Treex::PML::Instance")) 0 0 0
786 0 my $ref_schema = $refpml->get_schema;
787 # dump_schema($ref_schema);
788 0 convert_references($reffile,
789 $ref_schema,
790 $refpml->get_references_hash,
791 $refpml->get_refname_hash,
792 $refpml->get_ref($id),
793 $opts);
794 }
795 }
796 }
797 }
798  
799 0 ▶sub col_val {
Subroutine col_val: not called CC=2 SCAR=17.9
Pod undocumented
800 0 my ($decl,$table,$col,$str)=@_;
801 0 ▶ if (get_pmlref_target_info($decl,$table,$col)) {
Branch: 1 branch
BranchTrueFalseTotal
if (get_pmlref_target_info($decl, $table, $col)) 0 0 0
802 # the column named "$col" will contain #idx pointers
803 # the culumn "$col~" will contain the original PMLREF
804 0 $col.='~';
805 }
806 0 return $col => val($decl,$table,$col,$str);
807 }
808  
809 0 ▶sub val {
Subroutine val: not called CC=11 SCAR=48.8
Pod undocumented
810 0 my ($decl,$table,$col,$str)=@_;
811 0 ▶ if (ref($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $str) 0 0 0
812 0 Carp::confess("Attempt to store a reference $str as vchar in table $table, column $col");
813 }
814 0 analyze_string($table,$col => $str);
815 0 ▶ if (defined($str) and $decl and $decl->get_decl_type == PML_CDATA_DECL and $decl->get_format eq 'PMLREF') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and $decl and $decl->get_decl_type == 8 and $decl->get_format eq "PMLREF") 0 0 0
Condition0%0/9
defined $str and $decl and $decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
!ll&&!rl&&r
000
defined $str and $decl and $decl->get_decl_type == 8
!ll&&!rl&&r
000
defined $str and $decl
!ll&&!rl&&r
000
MC/DC0%0/4
defined $str and $decl and $decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
defined $str $decl $decl->get_decl_type == 8 $decl->get_format eq "PMLREF"
Truth table0%0/5
A and B and C and D
A= defined $strB= $declC= $decl->get_decl_type == 8D= $decl->get_format eq "PMLREF"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
816 0 ▶ $str=~s/^.+?#// if defined $str;
Branch: 1 branch
BranchTrueFalseTotal
if defined $str 0 0 0
817 }
818 0 ▶ if ($decl and !(defined $str and length $str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl and not defined $str && length $str) 0 0 0
Condition0%0/6
$decl and not defined $str && length $str
!ll&&!rl&&r
000
defined $str && length $str
!ll&&!rl&&r
000
MC/DC0%0/3
$decl and not defined $str && length $str
$decl defined $str length $str
Truth table0%0/4
A and not(B && C)
A= $declB= defined $strC= length $str
ABCresult
0XX0
1110
10X1
1101
819 0 my $def = $opts{defaults}{ table_name($decl) };
820 0 ▶ $str=$def if defined $def;
Branch: 1 branch
BranchTrueFalseTotal
if defined $def 0 0 0
821 }
822 0 return $str;
823 }
824  
825 0 ▶sub table_name {
Subroutine table_name: not called CC=8 SCAR=42.8
Pod undocumented
826 0 my ($decl,$no_rename) = @_;
827 0 ▶ confess("missing decl") unless $decl;
Branch: 1 branch
BranchTrueFalseTotal
unless $decl 0 0 0
828 0 my $path = $decl->get_decl_path;
829 0 ▶ if (!$path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 0 0 0
830 0 my $parent_is = $decl->get_parent_decl->get_decl_type;
831 # warn("Couldn't determine table name for $decl with parent ".$decl->get_parent_decl."\n");
832 0 ▶ return rename_type('/'.$decl->get_parent_decl->get_name,$no_rename) if $parent_is==PML_ROOT_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $parent_is == 2 0 0 0
833 0 ▶ if ($parent_is==PML_STRUCTURE_DECL or
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_is == 3 or $parent_is == 5 or $parent_is == 4) 0 0 0
Condition0%0/6
$parent_is == 3 or $parent_is == 5 or $parent_is == 4
l!l&&r!l&&!r
000
$parent_is == 3 or $parent_is == 5
l!l&&r!l&&!r
000
MC/DC0%0/3
$parent_is == 3 or $parent_is == 5 or $parent_is == 4
$parent_is == 3 $parent_is == 5 $parent_is == 4
Truth table0%0/4
A or B or C
A= $parent_is == 3B= $parent_is == 5C= $parent_is == 4
ABCresult
1XX1
01X1
0011
0000
834 $parent_is==PML_SEQUENCE_DECL or
835 $parent_is==PML_CONTAINER_DECL) {
836 0 my $name = $decl->get_name;
837 0 $path = table_name($decl->get_parent_decl,1);
838 # print "result: $path/$name\n";
839 0 ▶ return rename_type($path.'/'.$name,$no_rename) if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 0 0 0
840 }
841 0 $decl->write({fh=>\*STDERR});
842 0 confess("Couldn't determine table name for $decl with parent ".$decl->get_parent_decl."\n");
843 }
844 0 $path=~s{^/}{ '/'.$decl->get_schema->get_root_name.'/' }e;
845 0 $path = PMLTQ::Common::DeclPathToQueryType($path);
846 0 return rename_type($path,$no_rename);
847 }
848  
849  
850 0 ▶sub rename_type {
Subroutine rename_type: not called CC=6 SCAR=37.4
Pod undocumented
851 0 my ($table_name,$no_rename)=@_;
852 0 ▶ return $table_name if $no_rename;
Branch: 1 branch
BranchTrueFalseTotal
if $no_rename 0 0 0
853 0 $table_name=$opts{prefix}.$table_name;
854 0 ▶ if ($opts{'rename-type'} and
Branch: 2 branches
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{'rename-type'} and $PMLTQ::PML2BASE::opts{'rename-type'}{$table_name}) { } 0 0 0
elsif (length $table_name > 16) { } 0 0 0
Condition0%0/3
$PMLTQ::PML2BASE::opts{"rename-type"} and $PMLTQ::PML2BASE::opts{"rename-type"}{$table_name}
!ll&&!rl&&r
000
MC/DC0%0/2
$PMLTQ::PML2BASE::opts{"rename-type"} and $PMLTQ::PML2BASE::opts{"rename-type"}{$table_name}
$PMLTQ::PML2BASE::opts{"rename-type"} $PMLTQ::PML2BASE::opts{"rename-type"}{$table_name}
Truth table0%0/3
A and B
A= $PMLTQ::PML2BASE::opts{"rename-type"}B= $PMLTQ::PML2BASE::opts{"rename-type"}{$table_name}
ABresult
0X0
100
111
855 $opts{'rename-type'}{$table_name}) {
856 0 $table_name=$opts{'rename-type'}{$table_name};
857 } elsif (length($table_name)>MAX_NAME_LENGTH) {
858 0 my $new_name = $opts{'rename-type'}{$table_name} = $root_name.'##'.($last_type_no++);
859 0 $orig_name{$new_name}=$table_name;
860 0 ▶ warn "renaming table for type '$table_name' to '$new_name'\n" if $opts{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"debug"} 0 0 0
861 0 $table_name = $new_name;
862 }
863 0 return $table_name;
864 }
865  
866  
867 0 ▶sub traverse_data {
Subroutine traverse_data: not called CC=56 SCAR=80.7
Pod undocumented
868 0 my ($decl,$value,$index,$opts)=@_;
869 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
870 0 ▶ my $table = delete($opts->{'#table'}) || table_name($decl);
Condition0%0/3
delete $opts->{'#table'} || table_name($decl)
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts->{'#table'} || table_name($decl)
delete $opts->{'#table'} table_name($decl)
Truth table0%0/3
A || B
A= delete $opts->{'#table'}B= table_name($decl)
ABresult
1X1
011
000
871 0 my $decl_is = $decl->get_decl_type;
872 0 ▶ $index=$idx++ unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 0 0
873 0 ▶ my $is_tree = UNIVERSAL::DOES::does($value,'Treex::PML::Node') && !$value->parent? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::DOES::does($value, 'Treex::PML::Node') && !$value->parent ? : 0 0 0
Condition0%0/3
UNIVERSAL::DOES::does($value, "Treex::PML::Node") and not $value->parent
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::DOES::does($value, "Treex::PML::Node") and not $value->parent
UNIVERSAL::DOES::does($value, "Treex::PML::Node") not $value->parent
Truth table0%0/3
A and not(B)
A= UNIVERSAL::DOES::does($value, "Treex::PML::Node")B= not $value->parent
ABresult
0X0
100
111
874 0 my $desc;
875 0 ▶ if ($decl_is == PML_STRUCTURE_DECL) {
Branch: 6 branches
BranchTrueFalseTotal
if ($decl_is == 3) { } 0 0 0
elsif ($decl_is == 4) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 13) { } 0 0 0
elsif ($decl_is == 6 or $decl_is == 7) { } 0 0 0
elsif ($decl_is == 9 or $decl_is == 10 or $decl_is == 8) { } 0 0 0
876 0 ▶ $is_tree = 1 if ($opts{is_treex} and ($decl->get_structure_name || '') =~ /[atn]-root/);
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"is_treex"} and ($decl->get_structure_name || "") =~ /[atn]-root/ 0 0 0
Condition0%0/5
$PMLTQ::PML2BASE::opts{"is_treex"} and ($decl->get_structure_name || "") =~ /[atn]-root/
!ll&&!rl&&r
000
$decl->get_structure_name || ''
l!l
00
MC/DC0%0/2
$PMLTQ::PML2BASE::opts{"is_treex"} and ($decl->get_structure_name || "") =~ /[atn]-root/
$PMLTQ::PML2BASE::opts{"is_treex"} $decl->get_structure_name
Truth table0%0/3
A and B
A= $PMLTQ::PML2BASE::opts{"is_treex"}B= $decl->get_structure_name
ABresult
0X0
100
111
877 0 my %midx;
878 my @members = grep {
879 0 ▶ (!defined($_->get_role) or ($_->get_role ne '#CHILDNODES' and $_->get_role ne '#TREES'))
Condition0%0/14
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
!ll&&!rl&&r
000
not defined $_->get_role or $_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
l!l&&r!l&&!r
000
$_->get_role ne "#CHILDNODES" and $_->get_role ne "#TREES"
!ll&&!rl&&r
000
$_->get_content_decl && $_->get_content_decl->get_role || ''
l!l
00
$_->get_content_decl and $_->get_content_decl->get_role
!ll&&!rl&&r
000
MC/DC0%0/5
(!defined($_->get_role) || $_->get_role ne '#CHILDNODES' && $_->get_role ne '#TREES') && ($_->get_content_decl && $_->get_content_decl->get_role || '') ne '#TREES'
not defined $_->get_role $_->get_role ne "#CHILDNODES" $_->get_role ne "#TREES" $_->get_content_decl $_->get_content_decl->get_role
Truth table0%0/8
not(A) or B and C && D and E
A= not defined $_->get_roleB= $_->get_role ne "#CHILDNODES"C= $_->get_role ne "#TREES"D= $_->get_content_declE= $_->get_content_decl->get_role
ABCDEresult
00XXX0
010XX0
1XX0X0
1XX100
0110X0
011100
1XX111
011111
880 and (($_->get_content_decl && $_->get_content_decl->get_role ||'') ne '#TREES')
881 } $decl->get_members;
882 0 ▶ $desc = {
Branch: 1 branch
BranchTrueFalseTotal
$is_tree ? : 0 0 0
883 '#table' => $table,
884 '#idx' => ($is_tree ? new_tree($value,$desc) : $index),
885 };
886 0 for (@members) {
887 0 my $n = $_->get_knit_name;
888 0 my $v = $value->{$n};
889 0 my $d = $_->get_knit_content_decl;
890 0 ▶ if (defined($v) and !$d->is_atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v and not $d->is_atomic) { } 0 0 0
Condition0%0/3
defined $v and not $d->is_atomic
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and not $d->is_atomic
defined $v not $d->is_atomic
Truth table0%0/3
A and not(B)
A= defined $vB= not $d->is_atomic
ABresult
0X0
100
111
891 0 my $mdump = traverse_data($d,$v);
892 0 $desc->{$n} = data_index($mdump);
893 } else {
894 # HACK for Interset structure
895 0 ▶ if (ref $v && UNIVERSAL::DOES::does($value, 'Lingua::Interset::FeatureStructure')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v and UNIVERSAL::DOES::does($value, "Lingua::Interset::FeatureStructure")) 0 0 0
Condition0%0/3
ref $v and UNIVERSAL::DOES::does($value, "Lingua::Interset::FeatureStructure")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v and UNIVERSAL::DOES::does($value, "Lingua::Interset::FeatureStructure")
ref $v UNIVERSAL::DOES::does($value, "Lingua::Interset::FeatureStructure")
Truth table0%0/3
A and B
A= ref $vB= UNIVERSAL::DOES::does($value, "Lingua::Interset::FeatureStructure")
ABresult
0X0
100
111
896 0 ▶ $v = [ map { $_ . '=' . $v->{$_} } keys %$v ] if ref $v eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "HASH" 0 0 0
897 0 ▶ $v = join ('|', @$v) if ref $v eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 0 0
898 }
899 0 my ($key,$value) = col_val($d,$table,$n,$v);
900 0 $desc->{$key} = $value;
901 }
902 }
903 0 ▶ $desc=traverse_subtree($value,$desc,$opts) if $is_tree;
Branch: 1 branch
BranchTrueFalseTotal
if $is_tree 0 0 0
904 } elsif ($decl_is == PML_CONTAINER_DECL) {
905 0 my $midx;
906 0 my @attrs = $decl->get_attributes;
907 $desc = {
908 '#table' => $table,
909 '#idx' => ($is_tree ? new_tree($value,$desc) : $index),
910 map {
911 0 ▶ my $n = $_->get_name;
Branch: 1 branch
BranchTrueFalseTotal
$is_tree ? : 0 0 0
912 0 my $v = $value->{$n};
913 0 col_val($_->get_content_decl,$table,$n,$v)
914 } @attrs
915 };
916 0 my $knit_content_decl = $decl->get_knit_content_decl;
917 0 my $content_decl = $decl->get_content_decl;
918 0 ▶ my $role = ($content_decl && $content_decl->get_role)||'';
Condition0%0/5
$content_decl && $content_decl->get_role || ''
l!l
00
$content_decl and $content_decl->get_role
!ll&&!rl&&r
000
MC/DC0%0/2
$content_decl && $content_decl->get_role || ''
$content_decl $content_decl->get_role
Truth table0%0/3
A and B
A= $content_declB= $content_decl->get_role
ABresult
111
0X0
100
919 0 ▶ if (defined($content_decl) and $role ne '#CHILDNODES' and $role ne '#TREES') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_decl and $role ne "#CHILDNODES" and $role ne "#TREES") 0 0 0
Condition0%0/6
defined $content_decl and $role ne "#CHILDNODES" and $role ne "#TREES"
!ll&&!rl&&r
000
defined $content_decl and $role ne "#CHILDNODES"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $content_decl and $role ne "#CHILDNODES" and $role ne "#TREES"
defined $content_decl $role ne "#CHILDNODES" $role ne "#TREES"
Truth table0%0/4
A and B and C
A= defined $content_declB= $role ne "#CHILDNODES"C= $role ne "#TREES"
ABCresult
0XX0
10X0
1100
1111
920 0 ▶ if ($knit_content_decl and defined($value->{'#content'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($knit_content_decl and defined $value->{'#content'}) { } 0 0 0
Condition0%0/3
$knit_content_decl and defined $value->{"#content"}
!ll&&!rl&&r
000
MC/DC0%0/2
$knit_content_decl and defined $value->{"#content"}
$knit_content_decl defined $value->{"#content"}
Truth table0%0/3
A and B
A= $knit_content_declB= defined $value->{"#content"}
ABresult
0X0
100
111
921 0 ▶ if ($knit_content_decl->is_atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($knit_content_decl->is_atomic) { } 0 0 0
922 0 my ($key,$value) = col_val($knit_content_decl,$table,'#content',$value->{'#content'});
923 0 $desc->{$key} = $value;
924 } else {
925 0 $desc->{'#content'} = data_index(traverse_data($knit_content_decl,$value->{'#content'}));
926 }
927 } else {
928 0 $desc->{'#content'} = undef;
929 }
930 }
931 0 ▶ $desc=traverse_subtree($value,$desc,$opts) if $is_tree;
Branch: 1 branch
BranchTrueFalseTotal
if $is_tree 0 0 0
932 } elsif ($decl_is == PML_SEQUENCE_DECL) {
933 0 my %midx;
934 0 my @elems = $decl->get_elements;
935 $desc = {
936 '#table' => $table,
937 '#idx' => $index,
938 map {
939 0 my $n = $_->get_name;
940 0 $n => ($midx{$n}=$idx++)
941 } @elems
942 };
943 0 my %epos;
944 0 my $i=0;
945 0 for (@{$value->elements_list}) {
946 0 my $n = $_->name;
947 0 my $v = $_->value;
948 0 my $e = $decl->get_element_by_name($n);
949 traverse_data($e,$v,$midx{$n},{
950 '#table'=>'#e_'.table_name($e->get_knit_content_decl),
951 '#pos'=>$i++,
952 0 ▶ '#elpos' => ($epos{$n}++||0),
Condition0%0/2
$epos{$n}++ || 0
l!l
00
MC/DC0%0/1
$epos{$n}++ || 0
$epos{$n}++
Truth table0%0/2
A
A= $epos{$n}++
Aresult
11
00
953 });
954 }
955 } elsif ($decl_is == PML_ELEMENT_DECL) {
956 0 my $content_decl=$decl->get_knit_content_decl;
957 0 ▶ my $compact = !defined($value) || $content_decl->is_atomic;
Condition0%0/3
!defined($value) || $content_decl->is_atomic
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($value) || $content_decl->is_atomic
!defined($value) $content_decl->is_atomic
Truth table0%0/3
not(A) || B
A= !defined($value)B= $content_decl->is_atomic
ABresult
1X1
011
000
958 0 $desc = {
959 '#table'=> $table,
960 '#idx', => $index,
961 %$opts,
962 };
963 0 ▶ if ($compact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact) { } 0 0 0
964 0 my ($key,$value) = col_val($content_decl,$table,'#value',$value);
965 0 $desc->{$key} = $value;
966 } else {
967 0 $desc->{'#value'} = data_index(traverse_data($content_decl,$value));
968 }
969 ▶ } elsif ($decl_is == PML_LIST_DECL || $decl_is == PML_ALT_DECL) {
Condition0%0/3
$decl_is == 6 or $decl_is == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 6 or $decl_is == 7
$decl_is == 6 $decl_is == 7
Truth table0%0/3
A or B
A= $decl_is == 6B= $decl_is == 7
ABresult
1X1
011
000
970 0 ▶ if ($decl_is == PML_ALT_DECL and !UNIVERSAL::DOES::does($value,'Treex::PML::Alt')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl_is == 7 and not UNIVERSAL::DOES::does($value, "Treex::PML::Alt")) 0 0 0
Condition0%0/3
$decl_is == 7 and not UNIVERSAL::DOES::does($value, "Treex::PML::Alt")
!ll&&!rl&&r
000
MC/DC0%0/2
$decl_is == 7 and not UNIVERSAL::DOES::does($value, "Treex::PML::Alt")
$decl_is == 7 not UNIVERSAL::DOES::does($value, "Treex::PML::Alt")
Truth table0%0/3
A and not(B)
A= $decl_is == 7B= not UNIVERSAL::DOES::does($value, "Treex::PML::Alt")
ABresult
0X0
100
111
971 0 $value=Treex::PML::Alt->new($value);
972 }
973 0 my $content_decl=$decl->get_knit_content_decl;
974 0 my $atomic = $content_decl->is_atomic;
975 0 ▶ my $ordered = ($decl_is == PML_LIST_DECL and $decl->is_ordered);
Condition0%0/3
$decl_is == 6 && $decl->is_ordered
!ll&&!rl&&r
000
MC/DC0%0/2
$decl_is == 6 && $decl->is_ordered
$decl_is == 6 $decl->is_ordered
Truth table0%0/3
A && B
A= $decl_is == 6B= $decl->is_ordered
ABresult
0X0
100
111
976 0 my $i=0;
977 0 $desc = [];
978 0 ▶ if ($atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($atomic) { } 0 0 0
979 0 for my $v ($value->values) {
980 0 ▶ push @$desc, {
Branch: 1 branch
BranchTrueFalseTotal
$ordered ? : 0 0 0
981 '#table'=>$table,
982 '#idx'=>$index,
983 col_val($content_decl,$table,'#value',$v),
984 ($ordered ? ('#pos'=>$i++) : ()),
985 };
986 }
987 } else {
988 0 for my $v ($value->values) {
989 0 ▶ push @$desc, {
Branch: 1 branch
BranchTrueFalseTotal
$ordered ? : 0 0 0
Condition0%0/3
defined $v && data_index(traverse_data($content_decl, $v))
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v && data_index(traverse_data($content_decl, $v))
defined $v data_index(traverse_data($content_decl, $v))
Truth table0%0/3
A && B
A= defined $vB= data_index(traverse_data($content_decl, $v))
ABresult
0X0
100
111
990 '#table'=>$table,
991 '#idx'=>$index,
992 '#value'=> defined($v) && data_index(traverse_data($content_decl,$v)),
993 ($ordered ? ('#pos'=>$i++) : ()),
994 };
995 }
996 }
997 ▶ } elsif ($decl_is == PML_CHOICE_DECL || $decl_is == PML_CONSTANT_DECL || $decl_is == PML_CDATA_DECL) {
Condition0%0/6
$decl_is == 9 or $decl_is == 10 or $decl_is == 8
l!l&&r!l&&!r
000
$decl_is == 9 or $decl_is == 10
l!l&&r!l&&!r
000
MC/DC0%0/3
$decl_is == 9 or $decl_is == 10 or $decl_is == 8
$decl_is == 9 $decl_is == 10 $decl_is == 8
Truth table0%0/4
A or B or C
A= $decl_is == 9B= $decl_is == 10C= $decl_is == 8
ABCresult
1XX1
01X1
0011
0000
998 0 confess("traversing atomic type\n");
999 } else {
1000 0 die "unhandled data type: $decl\n";
1001 }
1002 # print "$decl\n" unless defined $desc;
1003 # print Dumper($desc) if $desc;
1004 0 ▶ dump_data_desc($desc) unless $opts->{no_dump};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_dump"} 0 0 0
1005 0 return $desc;
1006 }
1007  
1008 0 ▶sub data_index {
Subroutine data_index: not called CC=3 SCAR=24.8
Pod undocumented
1009 0 my ($desc)=@_;
1010 0 ▶ $desc = $desc->[0] if ref($desc) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $desc eq "ARRAY" 0 0 0
1011 0 ▶ return defined($desc) ? $desc->{'#idx'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $desc ? : 0 0 0
1012 }
1013  
1014 0 ▶sub dump_data_desc {
Subroutine dump_data_desc: not called CC=6 SCAR=37.4
Pod undocumented
1015 0 my ($desc)=@_;
1016 0 ▶ for my $desc_item (ref($desc) eq 'ARRAY' ? @$desc : $desc) {
Branch: 1 branch
BranchTrueFalseTotal
ref $desc eq 'ARRAY' ? : 0 0 0
1017 0 my %d = (%$desc_item);
1018 0 my $table = delete $d{'#table'};
1019 0 ▶ confess( "no #table:".Dumper(\%d) ) unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 0 0
1020 0 my @columns = map $_->[0],@{$schema{$table}{colspec}};
1021 0 ▶ if (defined $fh{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh{$table}) { } 0 0 0
1022 0 $fh{$table}->print(mkdump(delete @d{@columns}));
1023 0 ▶ die "The following columns were left in a row for table $table: "
Branch: 1 branch
BranchTrueFalseTotal
if keys %d 0 0 0
1024 .join(',',keys %d)."\n"
1025 ."expected: ".join(',',@columns)."\n"
1026 if keys %d;
1027 } else {
1028 0 print join(" ",keys %fh),"\n";
1029 0 die "Error: didn't find any filehandle for table $table\n";
1030 }
1031 }
1032 }
1033  
1034 0 ▶sub new_tree {
Subroutine new_tree: not called CC=3 SCAR=24.8
Pod undocumented
1035 0 my ($node,$desc,$opts)=@_;
1036 0 my $idx = ++$node_idx;
1037 0 $node_idx=$idx + $node->descendants; # reserve a span in the node indexing sequence for this tree
1038 0 ▶ my $primary = (!defined($last_tree_no) || ($last_tree_no != $tree_no)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($last_tree_no) || $last_tree_no != $tree_no ? : 0 0 0
Condition0%0/3
not defined $last_tree_no or $last_tree_no != $tree_no
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $last_tree_no or $last_tree_no != $tree_no
not defined $last_tree_no $last_tree_no != $tree_no
Truth table0%0/3
not(A) or B
A= not defined $last_tree_noB= $last_tree_no != $tree_no
ABresult
1X1
011
000
1039 0 $fh{'#FILE_TABLE'}->print(mkdump($idx,$filename,$tree_no,$primary)); # FIXME: wont work for bundles
1040 0 $last_tree_no = $tree_no;
1041 0 return $idx;
1042 }
1043  
1044 0 ▶sub traverse_subtree {
Subroutine traverse_subtree: not called CC=24 SCAR=64.0
Pod undocumented
1045 0 my ($node,$desc,$opts)=@_;
1046 0 my $idx=$desc->{'#idx'};
1047 0 my $root_idx = $idx;
1048 0 my $lvl=0;
1049 0 my %hash;
1050 0 my $tree=$node;
1051 0 ▶ while ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
1052 0 my $parent = $node->parent;
1053 0 ▶ unless (defined $hash{$node}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hash{$node}) 0 0 0
1054 0 $hash{$node} = {};
1055 0 $hash{$node}{'#table'} = $node_table;
1056 0 ▶ $hash{$node}{'#data'} = $parent ?
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
1057 traverse_data($node->type,
1058 $node,
1059 ++$idx,
1060 {%$opts,
1061 no_dump => 1,
1062 root_idx=>$root_idx})
1063 : $desc;
1064 #$hash{$node}{'#ID'}=$node->get_id;
1065 0 $hash{$node}{'#idx'}=$hash{$node}{'#data'}{'#idx'};
1066 0 $hash{$node}{'#chld'} = 0;
1067 0 my $name = $node->{'#name'};
1068 0 my $type = $hash{$node}{'#data'}{'#table'};
1069 0 ▶ if (defined($name) and length($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and length $name) 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
1070 0 val(undef,$node_table,'#name',$name);
1071 0 $hash{$node}{'#name'} = val(undef,$type,'#name',$name);
1072 }
1073 0 val(undef,$node_table,'#type',table_name($node->type,1));
1074 0 $hash{$node}{'#type'} = val(undef,$type,'#type',table_name($node->type,1));
1075 0 ▶ $hash{$node}{'#chord'} = $parent ? $hash{$parent}{'#chld'}++ : 0;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
1076 0 ▶ $hash{$node}{'#lvl'} = $parent ? $hash{$parent}{'#lvl'}+1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
1077 0 ▶ $hash{$node}{'#parent_idx'} = $parent ? $hash{$parent}{'#idx'} : undef ;
Branch: 1 branch
BranchTrueFalseTotal
$parent ? : 0 0 0
1078 0 $hash{$node}{'#root_idx'} = $root_idx;
1079 0 $hash{$node}{'#min_ord'} = $hash{$node}{'#max_ord'} = $node->get_order;
1080 0 ▶ if ($node->firstson) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->firstson) 0 0 0
1081 0 $node = $node->firstson;
1082 0 next;
1083 }
1084 }
1085 0 $hash{$node}{'#r'} = $idx;
1086 0 my ($min_ord,$max_ord)=@{$hash{$node}}{'#min_ord', '#max_ord'};
1087 0 ▶ if ($parent and defined($min_ord) and !defined($parent->get_order)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and defined $min_ord and not defined $parent->get_order) 0 0 0
Condition0%0/6
$parent and defined $min_ord and not defined $parent->get_order
!ll&&!rl&&r
000
$parent and defined $min_ord
!ll&&!rl&&r
000
MC/DC0%0/3
$parent and defined $min_ord and not defined $parent->get_order
$parent defined $min_ord not defined $parent->get_order
Truth table0%0/4
A and B and not(C)
A= $parentB= defined $min_ordC= not defined $parent->get_order
ABCresult
0XX0
10X0
1100
1111
1088 0 my $hp=$hash{$parent};
1089 $hp->{'#min_ord'} = $min_ord
1090 0 ▶ if (!defined($hp->{'#min_ord'}) or $hp->{'#min_ord'} > $min_ord);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $hp->{"#min_ord"} or $hp->{"#min_ord"} > $min_ord 0 0 0
Condition0%0/3
not defined $hp->{"#min_ord"} or $hp->{"#min_ord"} > $min_ord
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $hp->{"#min_ord"} or $hp->{"#min_ord"} > $min_ord
not defined $hp->{"#min_ord"} $hp->{"#min_ord"} > $min_ord
Truth table0%0/3
not(A) or B
A= not defined $hp->{"#min_ord"}B= $hp->{"#min_ord"} > $min_ord
ABresult
1X1
011
000
1091 $hp->{'#max_ord'} = $max_ord
1092 0 ▶ if (!defined($hp->{'#max_ord'}) or $hp->{'#max_ord'} < $max_ord);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $hp->{"#max_ord"} or $hp->{"#max_ord"} < $max_ord 0 0 0
Condition0%0/3
not defined $hp->{"#max_ord"} or $hp->{"#max_ord"} < $max_ord
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $hp->{"#max_ord"} or $hp->{"#max_ord"} < $max_ord
not defined $hp->{"#max_ord"} $hp->{"#max_ord"} < $max_ord
Truth table0%0/3
not(A) or B
A= not defined $hp->{"#max_ord"}B= $hp->{"#max_ord"} < $max_ord
ABresult
1X1
011
000
1093 }
1094 0 ▶ if (ref $opts{for_each_node}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $PMLTQ::PML2BASE::opts{"for_each_node"}) 0 0 0
1095 0 $opts{for_each_node}->($node,\%hash,\%fh);
1096 }
1097 0 ▶ $node = $node->rbrother || $parent;
Condition0%0/3
$node->rbrother || $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->rbrother || $parent
$node->rbrother $parent
Truth table0%0/3
A || B
A= $node->rbrotherB= $parent
ABresult
1X1
011
000
1098 }
1099 0 ▶ if (ref $opts{for_each_tree}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $PMLTQ::PML2BASE::opts{"for_each_tree"}) 0 0 0
1100 0 $opts{for_each_tree}->($tree,\%hash,\%fh);
1101 }
1102 0 ▶ if (@dump_fns) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dump_fns) 0 0 0
1103 0 $_->($tree,\%hash) for @dump_fns;
1104 }
1105 return [ map {
1106 0 my $h = $_->[1];
1107 0 my $data = delete $h->{'#data'};
1108 $opts{no_tree_table} ? { %$h, %$data } :
1109 0 ▶ $opts{hybrid} ? ({ %$h, %$data }, $h)
Branch: 2 branches
BranchTrueFalseTotal
$PMLTQ::PML2BASE::opts{'no_tree_table'} ? : 0 0 0
$PMLTQ::PML2BASE::opts{'hybrid'} ? : 0 0 0
1110 : ($data, $h)
1111 0 } sort { $a->[0]<=>$b->[0] }
1112 0 map { [$_->{'#idx'},$_] } values %hash
1113 ];
1114 }
1115  
1116 0 ▶sub is_treex_document {
Subroutine is_treex_document: not called CC=3 SCAR=24.8
Pod undocumented
1117 0 my $fs = shift;
1118 0 ▶ return ($fs->metaData('schema') && $fs->metaData('schema')->get_root_name eq 'treex_document') ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$fs->metaData('schema') && $fs->metaData('schema')->get_root_name eq 'treex_document' ? : 0 0 0
Condition0%0/3
$fs->metaData("schema") and $fs->metaData("schema")->get_root_name eq "treex_document"
!ll&&!rl&&r
000
MC/DC0%0/2
$fs->metaData("schema") and $fs->metaData("schema")->get_root_name eq "treex_document"
$fs->metaData("schema") $fs->metaData("schema")->get_root_name eq "treex_document"
Truth table0%0/3
A and B
A= $fs->metaData("schema")B= $fs->metaData("schema")->get_root_name eq "treex_document"
ABresult
0X0
100
111
1119 }
1120  
1121 0 ▶sub fs2base {
Subroutine fs2base: not called CC=16 SCAR=56.1
Pod undocumented
1122 0 my ($fs,$opts)=@_;
1123 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1124  
1125 # prepare global option
1126 0 ▶ $opts{'data-dir'}=Cwd::abs_path($opts{'data-dir'}) if $opts{'data-dir'};
Branch: 1 branch
BranchTrueFalseTotal
if $PMLTQ::PML2BASE::opts{"data-dir"} 0 0 0
1127 0 $opts{for_each_tree} = $opts->{for_each_tree};
1128 0 $opts{for_each_node} = $opts->{for_each_node};
1129  
1130 ## little hack for treex files
1131 0 ▶ if (is_treex_document($fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_treex_document($fs)) 0 0 0
1132 0 require Treex::Core::Document;
1133 0 Treex::Core::Document->new({pmldoc => $fs}); ## rebless all nodes
1134 0 $opts{is_treex}=1;
1135 0 print "Converting to Treex document\n";
1136 }
1137  
1138 0 ▶ if (!$schema) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema) 0 0 0
1139 0 convert_schema($fs->metaData('schema'),$opts);
1140 0 $relations = PMLTQ::Relation->relations_for_schema($schema->get_root_name);
1141  
1142 0 for my $rel (@$relations) {
1143 0 ▶ next unless $rel->{table_name}; # if it doesn't have table we ignore it
Branch: 1 branch
BranchTrueFalseTotal
unless $rel->{"table_name"} 0 0 0
1144 0 my $reversed_relation = $rel->{reversed_relation};
1145 0 ▶ $reversed_relation =~ s/^implementation:// if $reversed_relation;
Branch: 1 branch
BranchTrueFalseTotal
if $reversed_relation 0 0 0
1146 0 my $spec = make_user_rel_table($rel->{table_name}, $rel->{name}, $reversed_relation, $rel->{start_node_type}, $rel->{target_node_type});
1147  
1148 0 my $init_sql = $rel->{iterator_class}->can('init_sql');
1149 0 ▶ $init_sql->($spec->{table}, $schema, $spec, \%fh) if $init_sql;
Branch: 1 branch
BranchTrueFalseTotal
if $init_sql 0 0 0
1150  
1151 0 my $dump_fn = $rel->{iterator_class}->can('dump_relation');
1152 0 ▶ push @dump_fns, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1153 0 my ($tree, $hash) = @_;
1154 0 ▶ return unless $tree->type->get_structure_name||'' eq $rel->{tree_root};
Branch: 1 branch
BranchTrueFalseTotal
unless $tree->type->get_structure_name or "" eq $rel->{"tree_root"} 0 0 0
Condition0%0/3
$tree->type->get_structure_name or "" eq $rel->{"tree_root"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tree->type->get_structure_name or "" eq $rel->{"tree_root"}
$tree->type->get_structure_name "" eq $rel->{"tree_root"}
Truth table0%0/3
A or B
A= $tree->type->get_structure_nameB= "" eq $rel->{"tree_root"}
ABresult
1X1
011
000
1155 $dump_fn->(@_, $fh{$spec->{table}})
1156 0 ▶ } if $dump_fn;
Branch: 1 branch
BranchTrueFalseTotal
if $dump_fn 0 0 0
1157 }
1158  
1159 0 ▶ dump_typemap() unless $opts{'no-schema'};
Branch: 1 branch
BranchTrueFalseTotal
unless $PMLTQ::PML2BASE::opts{"no-schema"} 0 0 0
1160 }
1161 0 my $f = $filename = $fs->filename;
1162 0 $filename = abs2rel($filename);
1163  
1164 0 convert_references($f,
1165 $schema,
1166 $fs->metaData('references'),
1167 $fs->metaData('refnames'),
1168 $fs->appData('ref'),
1169 $opts);
1170 0 analyze_string($file_table,file => $f);
1171 0 my $trees_type =$fs->metaData('pml_trees_type');
1172 0 ▶ if ($trees_type->get_decl_type == PML_MEMBER_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trees_type->get_decl_type == 12) 0 0 0
1173 0 $trees_type = $trees_type->get_content_decl;
1174 }
1175 traverse_data(
1176 0 ▶ $trees_type,
Branch: 1 branch
BranchTrueFalseTotal
if $fs->metaData("pml_prolog") 0 0 0
1177 $fs->metaData('pml_prolog'),
1178 ) if $fs->metaData('pml_prolog');
1179 0 ▶ traverse_data(
Branch: 1 branch
BranchTrueFalseTotal
if $fs->metaData("pml_root") 0 0 0
1180 $fs->metaData('schema')->get_root_type,
1181 $fs->metaData('pml_root'),
1182 ) if $fs->metaData('pml_root');
1183  
1184 0 $tree_no=0;
1185 0 for my $tree ($fs->trees) {
1186 0 traverse_data($tree->type, $tree,undef,$opts);
1187 0 $tree_no++;
1188 }
1189 traverse_data(
1190 0 ▶ $trees_type,
Branch: 1 branch
BranchTrueFalseTotal
if $fs->metaData("pml_epilog") 0 0 0
1191 $fs->metaData('pml_epilog'),
1192 ) if $fs->metaData('pml_epilog');
1193 }
1194  
1195 0 ▶sub finish {
Subroutine finish: not called CC=38 SCAR=73.0
Pod undocumented
1196 0 ▶ if (defined $opts{'max-node-idx'} and $node_idx>$opts{'max-node-idx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PMLTQ::PML2BASE::opts{"max-node-idx"} and $node_idx > $PMLTQ::PML2BASE::opts{"max-node-idx"}) 0 0 0
Condition0%0/3
defined $PMLTQ::PML2BASE::opts{"max-node-idx"} and $node_idx > $PMLTQ::PML2BASE::opts{"max-node-idx"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PMLTQ::PML2BASE::opts{"max-node-idx"} and $node_idx > $PMLTQ::PML2BASE::opts{"max-node-idx"}
defined $PMLTQ::PML2BASE::opts{"max-node-idx"} $node_idx > $PMLTQ::PML2BASE::opts{"max-node-idx"}
Truth table0%0/3
A and B
A= defined $PMLTQ::PML2BASE::opts{"max-node-idx"}B= $node_idx > $PMLTQ::PML2BASE::opts{"max-node-idx"}
ABresult
0X0
100
111
1197 0 warn("NODE_IDX EXCEEDED LIMIT: next $node_idx, limit $opts{'max-node-idx'}");
1198 }
1199 0 ▶ if (defined $opts{'max-idx'} and $idx>$opts{'max-idx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PMLTQ::PML2BASE::opts{"max-idx"} and $idx > $PMLTQ::PML2BASE::opts{"max-idx"}) 0 0 0
Condition0%0/3
defined $PMLTQ::PML2BASE::opts{"max-idx"} and $idx > $PMLTQ::PML2BASE::opts{"max-idx"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PMLTQ::PML2BASE::opts{"max-idx"} and $idx > $PMLTQ::PML2BASE::opts{"max-idx"}
defined $PMLTQ::PML2BASE::opts{"max-idx"} $idx > $PMLTQ::PML2BASE::opts{"max-idx"}
Truth table0%0/3
A and B
A= defined $PMLTQ::PML2BASE::opts{"max-idx"}B= $idx > $PMLTQ::PML2BASE::opts{"max-idx"}
ABresult
0X0
100
111
1200 0 warn("DATA_IDX EXCEEDED LIMIT: next $idx, limit $opts{'max-idx'}");
1201 }
1202 0 ▶ if ($opts{incremental}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
1203 0 $fh{'#POST_SQL'}->print(qq{UPDATE "#PML" SET ("last_idx","last_node_idx")=($idx,$node_idx)}.
1204 qq{ WHERE "root"='$root_name';\n\n});
1205 }
1206 0 ▶ if ($opts{'dump-rename-map'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"dump-rename-map"}) 0 0 0
1207 0 open my $fh, '>:utf8', $opts{'dump-rename-map'};
1208 0 my ($k,$v);
1209 0 ▶ while (($k,$v)=each %{$opts{'rename-type'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$PMLTQ::PML2BASE::opts{"rename-type"};}) 0 0 0
1210 0 print $fh "$k\t$v\n";
1211 }
1212 0 close $fh;
1213 }
1214  
1215 0 ▶ my @tables = sort {($a->{'#decl_order'}||0)<=>($b->{'#decl_order'}||0)} values %schema;
Condition0%0/4
$PMLTQ::PML2BASE::a->{'#decl_order'} || 0
l!l
00
$PMLTQ::PML2BASE::b->{'#decl_order'} || 0
l!l
00
MC/DC0%0/1
$PMLTQ::PML2BASE::a->{'#decl_order'} || 0
$PMLTQ::PML2BASE::a->{'#decl_order'}
MC/DC0%0/1
$PMLTQ::PML2BASE::b->{'#decl_order'} || 0
$PMLTQ::PML2BASE::b->{'#decl_order'}
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::a->{'#decl_order'}
Aresult
11
00
Truth table0%0/2
A
A= $PMLTQ::PML2BASE::b->{'#decl_order'}
Aresult
11
00
1216 0 ▶ unless ($opts{'no-schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"no-schema"}) 0 0 0
1217 0 for my $desc (reverse @tables) {
1218 $fh{'#INIT_SQL'}->print(qq{CREATE TABLE "$desc->{table}" (\n },
1219 join(",\n ",
1220 map {
1221 0 my ($c,$t)=@$_;
1222 0 ▶ if ($t=~/STRING\(\)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /STRING\(\)/i) 0 0 0
1223 0 ▶ my $l = $desc->{col}{$c}||=0;
Condition0%0/2
$desc->{"col"}{$c} ||= 0
l!l
00
MC/DC0%0/1
$desc->{"col"}{$c} ||= 0
$desc->{"col"}{$c}
Truth table0%0/2
A
A= $desc->{"col"}{$c}
Aresult
11
00
1224 0 ▶ my $non_ascii = $desc->{non_ascii}{$c}||=0;
Condition0%0/2
$desc->{"non_ascii"}{$c} ||= 0
l!l
00
MC/DC0%0/1
$desc->{"non_ascii"}{$c} ||= 0
$desc->{"non_ascii"}{$c}
Truth table0%0/2
A
A= $desc->{"non_ascii"}{$c}
Aresult
11
00
1225 0 ▶ warn ("length for $c in $desc->{table} is 0; changing to 1\n") if !$l;
Branch: 1 branch
BranchTrueFalseTotal
unless $l 0 0 0
1226 0 ▶ $l||=1;
Condition0%0/2
$l ||= 1
l!l
00
MC/DC0%0/1
$l ||= 1
$l
Truth table0%0/2
A
A= $l
Aresult
11
00
1227 0 $t=~s/STRING\(\)/varchar($l,$non_ascii)/ieg;
1228 }
1229 0 $t=~s/ FOREIGN KEY.*$//;
1230 0 qq{"$c" $t}
1231 0 } @{$desc->{colspec}}
1232 ), "\n);\n\n");
1233 0 for (@{$desc->{colspec}}) {
1234 0 ▶ if ($_->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[2]) 0 0 0
1235 0 $fh{'#INIT_SQL'}->print(qq{CREATE INDEX "#i_${root_name}_$index_id" ON "$desc->{table}" ("$_->[0]");\n\n});
1236 0 $index_id++;
1237 }
1238 }
1239 }
1240 0 for my $desc (@tables) {
1241 0 $fh{'#DELETE_SQL'}->print(qq{DROP TABLE IF EXISTS "$desc->{table}" CASCADE;\n\n});
1242 }
1243 }
1244 0 ▶ unless ($opts{'schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"schema"}) 0 0 0
1245 0 for my $desc (reverse @tables) {
1246 0 my $t = $desc->{table};
1247 0 my $dump = table2filename($t);
1248 0 my $ctl=table2filename($t,'ctl');
1249 0 open LOAD_SQL,'>',get_full_path($ctl);
1250 0 ▶ my $replace = $opts{'no-schema'} ? "APPEND" : "REPLACE";
Branch: 1 branch
BranchTrueFalseTotal
$PMLTQ::PML2BASE::opts{'no-schema'} ? : 0 0 0
1251 0 my $cols = join ',', map { qq{"$_->[0]"} } @{$desc->{colspec}};
1252 0 print LOAD_SQL qq{COPY "$t" ($cols) FROM '$dump'\n};
1253 0 close LOAD_SQL;
1254 0 $fh{'#INIT_LIST'}->print("$ctl\n");
1255 }
1256 }
1257 0 ▶ if ($opts{'no-schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{'no-schema'}) { } 0 0 0
1258 0 ▶ if ($opts{incremental}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
1259 0 $fh{'#INIT_LIST'}->print(to_filename("postprocess",'sql')."\n");
1260 }
1261 } else {
1262 0 $fh{'#INIT_LIST'}->print(to_filename("postprocess",'sql')."\n");
1263 0 ▶ unless ($opts{incremental}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"incremental"}) 0 0 0
1264 0 for my $desc (values %schema) {
1265 0 for my $col (@{$desc->{colspec}}) {
1266 0 my ($c,$t)=@$col;
1267 0 ▶ if ($t =~ m/ (FOREIGN KEY) (.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ / (FOREIGN KEY) (.*)$/) 0 0 0
1268 0 $fh{'#POST_SQL'}->print(qq{ALTER TABLE "$desc->{table}" ADD $1("$c") $2;\n\n});
1269 }
1270 }
1271 }
1272 }
1273 0 for my $desc (values %schema) {
1274 0 $fh{'#POST_SQL'}->print(qq{VACUUM FULL ANALYZE "$desc->{table}";\n\n});
1275 }
1276 }
1277  
1278 0 ▶ if ($opts{'dump-idx'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"dump-idx"}) 0 0 0
1279 0 open my $fh, '>', get_full_path($opts{'dump-idx'});
1280 0 print $fh "$idx\t$node_idx\n";
1281 0 close $fh;
1282 }
1283 0 ▶ if ($opts{'dump-col-info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::PML2BASE::opts{"dump-col-info"}) 0 0 0
1284 0 open my $fh, '>:utf8', get_full_path($opts{'dump-col-info'});
1285 0 foreach my $table (keys %schema) {
1286 0 ▶ if ($schema{$table}{col}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema{$table}{"col"}) 0 0 0
1287 0 foreach my $column (keys %{$schema{$table}{col}}) {
1288 0 ▶ my $length=$schema{$table}{col}{$column}||0;
Condition0%0/2
$schema{$table}{'col'}{$column} || 0
l!l
00
MC/DC0%0/1
$schema{$table}{'col'}{$column} || 0
$schema{$table}{'col'}{$column}
Truth table0%0/2
A
A= $schema{$table}{'col'}{$column}
Aresult
11
00
1289 0 ▶ my $non_ascii=$schema{$table}{non_ascii}{$column}||0;
Condition0%0/2
$schema{$table}{'non_ascii'}{$column} || 0
l!l
00
MC/DC0%0/1
$schema{$table}{'non_ascii'}{$column} || 0
$schema{$table}{'non_ascii'}{$column}
Truth table0%0/2
A
A= $schema{$table}{'non_ascii'}{$column}
Aresult
11
00
1290 0 print $fh "$table\t$column\t$length\t$non_ascii\n";
1291 }
1292 }
1293 }
1294 }
1295  
1296 0 close $_ for values %fh;
1297  
1298 }
1299  
1300  
1301 0 ▶sub get_full_path {
Subroutine get_full_path: not called CC=2 SCAR=17.9
Pod undocumented
1302 0 my $file = shift;
1303 0 ▶ return exists $opts{'output-dir'} ? File::Spec->catfile($opts{'output-dir'},$file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
exists $PMLTQ::PML2BASE::opts{'output-dir'} ? : 0 0 0
1304 }
1305  
1306 0 ▶sub make_user_rel_table {
Subroutine make_user_rel_table: not called CC=4 SCAR=30.0
Pod undocumented
1307 0 my ($table_name, $name, $reverse_name, $node_type, $target_node_type) = @_;
1308  
1309 0 ▶ $target_node_type = $node_type unless defined $target_node_type; # default target node to start node
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target_node_type 0 0 0
1310  
1311 0 my $table = rename_type($table_name);
1312 0 ▶ my $values = join(',', map { defined $_ ? "'$_'" : 'NULL' } ($name, $reverse_name, $node_type, $target_node_type, $table));
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
1313  
1314 0 ▶ unless ($opts{'no-schema'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($PMLTQ::PML2BASE::opts{"no-schema"}) 0 0 0
1315 0 $fh{'#INIT_SQL'}->print(<<"SQL");
1316 INSERT INTO "#PML_USR_REL" VALUES(${values});
1317  
1318 SQL
1319 0 $fh{'#DELETE_SQL'}->print(<<"SQL");
1320 DELETE FROM "#PML_USR_REL" WHERE "tbl"='${table}';
1321  
1322 SQL
1323 }
1324  
1325 0 my $spec = $schema{$table} = {
1326 table => $table,
1327 colspec => [
1328 ['#idx','INT'],
1329 ['#value','INT'],
1330 ],
1331 index => ['#idx','#value']
1332 };
1333  
1334 0 open $fh{$table}, '>', get_full_path(to_filename($table));
1335  
1336 0 return $spec;
1337 }
1338  
1339 6 1; # End of PMLTQ::PML2BASE
1340  
1341 __END__
↑ Summary PML2BASE/Relation/Treex/AEParentCIterator.pm »