blib/lib/PMLTQ/Suggest.pm

filter: Statementstmt 7.2% 15 / 206 Branchbran 0.0% 0 / 120 Conditioncond 0.0% 0 / 70 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 30.7% 4 / 13 Podpod 0.0% 0 / 7 totaltotal 4.1% 19 / 459 CC 97 SCAR 66.2
CC
97
Cov
4%
member_to_pmltq
1560.0
node_to_pmltq
650.0
nodes_to_pmltq
240.0
CRAP 751.0
↑ Summary blib/lib/PMLTQ/Suggest/Utils.pm »
1 package PMLTQ::Suggest;
2 2 our $AUTHORITY = 'cpan:MATY';
3 2 $PMLTQ::Suggest::VERSION = '0.0.1';
4 # ABSTRACT: Tool for generating simple PMLTQ query based on given nodes
5  
6 =head1 DESCRIPTION
7  
8 This is an implementation of a Suggest server and a plugin for PML-TQ command-line client.
9  
10 =cut
11  
12 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use PMLTQ::Common qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Treex::PML::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use PMLTQ::Suggest::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub make_pmltq {
18 0 ▶ my ($positions,%opts)=@_;
Subroutine make_pmltq: not called CC=8 SCAR=42.8
Pod undocumented
19 0 my @open_files;
20 0 my %cur_fsfiles; @cur_fsfiles{@open_files}=();
21 # my $keep_cur;
22 0 my %fsfiles;
23 my @new_fsfiles;
24 0 foreach my $f (map $_->[0], @$positions) {
25 0 ▶ next if exists $fsfiles{$f};
Branch: 1 branch
BranchTrueFalseTotal
if exists $fsfiles{$f} 0 0 0
26 0 my $fsfile = PMLTQ::Suggest::Utils::open_file($f);
27 0 my @new = ($fsfile, PMLTQ::Suggest::Utils::GetSecondaryFiles($fsfile));
28 0 push @new_fsfiles, @new;
29 0 push @open_files, @new;
30 0 $fsfiles{$_->filename}=$_ for @new; # including $fsfile
31 0 $fsfiles{$f}=$fsfile; # $f may be different from $fsfile->filename
32 }
33 0 my @nodes;
34 0 for my $pos (@$positions) {
35 0 my $win = { FSFile => $fsfiles{$pos->[0]} };
36 0 ▶ unless (PMLTQ::Suggest::Utils::apply_file_suffix($win,$pos->[1]) and $win->{currentNode}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (PMLTQ::Suggest::Utils::apply_file_suffix($win, $pos->[1]) and $win->{"currentNode"}) 0 0 0
Condition0%0/3
PMLTQ::Suggest::Utils::apply_file_suffix($win, $pos->[1]) and $win->{"currentNode"}
!ll&&!rl&&r
000
MC/DC0%0/2
PMLTQ::Suggest::Utils::apply_file_suffix($win, $pos->[1]) and $win->{"currentNode"}
PMLTQ::Suggest::Utils::apply_file_suffix($win, $pos->[1]) $win->{"currentNode"}
Truth table0%0/3
A and B
A= PMLTQ::Suggest::Utils::apply_file_suffix($win, $pos->[1])B= $win->{"currentNode"}
ABresult
0X0
100
111
37 0 warn "Didn't find node [@$pos, @{[%$win]}]\n";
38 0 return;
39 }
40 0 push @nodes, [ $win->{currentNode}, $win->{FSFile} ];
41 }
42 0 ▶ print STDERR "generating query\n" if $opts{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"verbose"} 0 0 0
43 0 return nodes_to_pmltq(\@nodes,\%opts);
44 }
45  
46  
47  
48  
49 sub nodes_to_pmltq {
50 0 ▶ my ($nodes,$opts)=@_;
Subroutine nodes_to_pmltq: not called CC=15 SCAR=54.8
Pod undocumented
51 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
52 0 my %id_member;
53 0 my $name = 'a';
54 0 ▶ $name++ while $opts->{reserved_names} && exists($opts->{reserved_names}{$name});
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name} and do { ++$name } 0 0 0
Condition0%0/3
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name}
$opts->{"reserved_names"} exists $opts->{"reserved_names"}{$name}
Truth table0%0/3
A and B
A= $opts->{"reserved_names"}B= exists $opts->{"reserved_names"}{$name}
ABresult
0X0
100
111
55 0 my %node2name;
56 $opts->{id2name} = { map {
57 0 my $n = $_->[0];
58 0 my $t = $n->type;
59 0 ▶ my $id_member = ( $id_member{$t}||=_id_member_name($t) );
Condition0%0/3
$id_member{$t} ||= _id_member_name($t)
l!l&&r!l&&!r
000
MC/DC0%0/2
$id_member{$t} ||= _id_member_name($t)
$id_member{$t} _id_member_name($t)
Truth table0%0/3
A ||= B
A= $id_member{$t}B= _id_member_name($t)
ABresult
1X1
011
000
60 0 my $var = $node2name{$n} = $name++;
61 0 ▶ $name++ while $opts->{reserved_names} && exists($opts->{reserved_names}{$name});
Branch: 1 branch
BranchTrueFalseTotal
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name} and do { ++$name } 0 0 0
Condition0%0/3
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"reserved_names"} and exists $opts->{"reserved_names"}{$name}
$opts->{"reserved_names"} exists $opts->{"reserved_names"}{$name}
Truth table0%0/3
A and B
A= $opts->{"reserved_names"}B= exists $opts->{"reserved_names"}{$name}
ABresult
0X0
100
111
62 0 ($n->{$id_member} => $var)
63 } @$nodes };
64  
65 # discover relations;
66 0 my %marked;
67 0 @marked{map $_->[0], @$nodes}=(); # undef by default, 1 if connected
68 0 my %parents=();
69 0 my %connect;
70 0 for my $m (@$nodes) {
71 0 my ($n,$fsfile)=@$m;
72 0 my $parent = $n->parent;
73 0 ▶ $parents{$parent}||=$n;
Condition0%0/3
$parents{$parent} ||= $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$parents{$parent} ||= $n
$parents{$parent} $n
Truth table0%0/3
A ||= B
A= $parents{$parent}B= $n
ABresult
1X1
011
000
74 0 ▶ if ($parent and exists($marked{$parent})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($parent and exists $marked{$parent}) { } 0 0 0
elsif ($parents{$parent} != $n) { } 0 0 0
Condition0%0/3
$parent and exists $marked{$parent}
!ll&&!rl&&r
000
MC/DC0%0/2
$parent and exists $marked{$parent}
$parent exists $marked{$parent}
Truth table0%0/3
A and B
A= $parentB= exists $marked{$parent}
ABresult
0X0
100
111
75 0 push @{$connect{$n->parent}{child}}, $n;
76 # print STDERR "$node2name{$n->parent} has child $node2name{$n}\n";
77 0 $marked{$n}=1;
78 } elsif ($parents{$parent}!=$n) {
79 0 push @{$connect{$parents{$parent}}{sibling}}, $n;
80 # print STDERR "$node2name{$parents{$parent}} has sibling $node2name{$n}\n";
81 0 $marked{$n}=1;
82 } else {
83 0 ▶ $parent = $parent && $parent->parent;
Condition0%0/3
$parent && $parent->parent
!ll&&!rl&&r
000
MC/DC0%0/2
$parent && $parent->parent
$parent $parent->parent
Truth table0%0/3
A && B
A= $parentB= $parent->parent
ABresult
0X0
100
111
84 0 ▶ while ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 0 0 0
85 0 ▶ if (exists $marked{$parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $marked{$parent}) 0 0 0
86 # print STDERR "$node2name{$parent} has descendant $node2name{$n}\n";
87 0 push @{$connect{$parent}{descendant}}, $n;
88 0 $marked{$n}=1;
89 0 last;
90 }
91 0 $parent = $parent->parent;
92 }
93 }
94 }
95 0 $opts->{connect}=\%connect;
96 return join(";\n\n", map {
97 0 node_to_pmltq($_->[0],$_->[1],$opts)}
98 0 grep { !$marked{$_->[0]} } @$nodes);
99 }
100  
101 sub node_to_pmltq {
102 0 ▶ my ($node,$fsfile,$opts)=@_;
Subroutine node_to_pmltq: not called CC=25 SCAR=64.8
Pod undocumented
103 0 ▶ return unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 0 0
104 0 my $type = $node->type;
105 0 ▶ return unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
106 0 my $out='';
107 0 ▶ my $indent = $opts->{indent} || '';
Condition0%0/2
$opts->{'indent'} || ''
l!l
00
MC/DC0%0/1
$opts->{'indent'} || ''
$opts->{'indent'}
Truth table0%0/2
A
A= $opts->{'indent'}
Aresult
11
00
108  
109 0 ▶ my $var = $opts->{id2name} && $opts->{id2name}{$node->{_id_member_name($node->type)}};
Condition0%0/3
$opts->{'id2name'} && $opts->{'id2name'}{$$node{_id_member_name($node->type)}}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{'id2name'} && $opts->{'id2name'}{$$node{_id_member_name($node->type)}}
$opts->{'id2name'} $opts->{'id2name'}{$$node{_id_member_name($node->type)}}
Truth table0%0/3
A && B
A= $opts->{'id2name'}B= $opts->{'id2name'}{$$node{_id_member_name($node->type)}}
ABresult
0X0
100
111
110 0 ▶ $var = ' $'.$var.' := ' if $var;
Branch: 1 branch
BranchTrueFalseTotal
if $var 0 0 0
111 0 $out .= PMLTQ::Common::DeclToQueryType($type).$var." [\n";
112 0 foreach my $attr ('#name',$type->get_normal_fields) {
113 0 my $m = $type->get_member_by_name($attr);
114 # next if $m and $m->get_role() eq '#ID';
115 0 my $val = $node->{$attr};
116 0 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
117 0 ▶ $m = $type->get_member_by_name($attr.'.rf') unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 0 0
118 0 ▶ if ($attr eq '#name') {
Branch: 2 branches
BranchTrueFalseTotal
if ($attr eq '#name') { } 0 0 0
elsif (not $m) { } 0 0 0
119 0 $out .= $indent.qq{ name() = }._pmltq_string($val).qq{,\n};
120 0 next;
121 } elsif (!$m) {
122 0 ▶ $out .= $indent." # $attr ???;" unless $opts->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_comments"} 0 0 0
123 0 next;
124 }
125 0 ▶ my $name = $attr eq '#content' ? 'content()' : $attr;
Branch: 1 branch
BranchTrueFalseTotal
$attr eq '#content' ? : 0 0 0
126 0 ▶ next if $opts->{exclude} and $opts->{exclude}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"exclude"} and $opts->{"exclude"}{$name} 0 0 0
Condition0%0/3
$opts->{"exclude"} and $opts->{"exclude"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"exclude"} and $opts->{"exclude"}{$name}
$opts->{"exclude"} $opts->{"exclude"}{$name}
Truth table0%0/3
A and B
A= $opts->{"exclude"}B= $opts->{"exclude"}{$name}
ABresult
0X0
100
111
127 0 $out.=member_to_pmltq($name,$val,$m,$indent.' ',$fsfile,$opts);
128 }
129 0 ▶ if (defined $opts->{rbrothers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"rbrothers"}) 0 0 0
130 0 ▶ $out .= $indent.qq{ # rbrothers()=$opts->{rbrothers},\n} unless $opts->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_comments"} 0 0 0
131 }
132 0 ▶ if ($opts->{connect}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'connect'}) { } 0 0 0
elsif ($opts->{'children'} or $opts->{'descendants'}) { } 0 0 0
133 0 my $rels = $opts->{connect}{$node};
134 0 ▶ if ($rels) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rels) 0 0 0
135 0 foreach my $rel (sort keys %$rels) {
136 0 foreach my $n (@{$rels->{$rel}}) {
137 0 $out.=' '.$indent.$rel.' '.node_to_pmltq($n,$fsfile,{
138 %$opts,
139 indent=>$indent.' ',
140 }).",\n";
141 }
142 }
143 }
144 ▶ } elsif ($opts->{children} or $opts->{descendants}) {
Condition0%0/3
$opts->{"children"} or $opts->{"descendants"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"children"} or $opts->{"descendants"}
$opts->{"children"} $opts->{"descendants"}
Truth table0%0/3
A or B
A= $opts->{"children"}B= $opts->{"descendants"}
ABresult
1X1
011
000
145 0 my $i = 0;
146 0 my $son = $node->firstson;
147 0 ▶ while ($son) {
Branch: 1 branch
BranchTrueFalseTotal
if ($son) 0 0 0
148 0 $out.=' '.$indent.'child '.node_to_pmltq($son,$fsfile,{
149 %$opts,
150 indent=>$indent.' ',
151 children => 0,
152 rbrothers=>$i,
153 }).",\n";
154 0 $i++;
155 0 $son=$son->rbrother;
156 }
157 0 ▶ $out .= $indent.qq{ # sons()=$i,\n} unless $opts->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_comments"} 0 0 0
158 }
159 0 $out.=$indent.']';
160 0 return $out;
161  
162 }
163  
164 sub _id_member_name {
165 0 ▶ my ($type)=@_;
Subroutine _id_member_name: not called CC=4 SCAR=30.0
166 0 ▶ return undef unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
167 0 ▶ if ($type->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->get_decl_type == 13) 0 0 0
168 0 $type = $type->get_content_decl;
169 }
170 0 my ($omember) = $type->find_members_by_role('#ID');
171 0 ▶ if ($omember) {
Branch: 1 branch
BranchTrueFalseTotal
if ($omember) 0 0 0
172 0 return ($omember->get_name);
173 }
174 0 return undef; # we want this undef
175 }
176  
177 sub _pmltq_string {
178 0 ▶ my ($string)=@_;
Subroutine _pmltq_string: not called CC=1 SCAR=6.9
179 0 $string=~s/([\\'])/\\$1/g;
180 0 $string=~s/(\n)/\\n/g;
181 0 return qq{'$string'};
182 }
183  
184 sub resolve_pmlref {
185 0 ▶ my ($ref,$fsfile)=@_;
Subroutine resolve_pmlref: not called CC=6 SCAR=37.4
Pod undocumented
186 0 ▶ if ($ref=~m{^(.+?)\#(.+)$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref =~ /^(.+?)\#(.+)$/) { } 0 0 0
elsif ($ref =~ /\#?([^#]+)/) { } 0 0 0
187 0 my ($file_id,$id)=($1,$2);
188 0 my $refs = $fsfile->appData('ref');
189 0 ▶ my $reffile = $refs && $refs->{$file_id};
Condition0%0/3
$refs && $refs->{$file_id}
!ll&&!rl&&r
000
MC/DC0%0/2
$refs && $refs->{$file_id}
$refs $refs->{$file_id}
Truth table0%0/3
A && B
A= $refsB= $refs->{$file_id}
ABresult
0X0
100
111
190 0 ▶ if (UNIVERSAL::DOES::does($reffile,'Treex::PML::Document')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::DOES::does($reffile, 'Treex::PML::Document')) { } 0 0 0
elsif (UNIVERSAL::DOES::does($reffile, 'Treex::PML::Instance')) { } 0 0 0
191 0 return GetNodeByID($id,$reffile);
192 } elsif (UNIVERSAL::DOES::does($reffile,'Treex::PML::Instance')) {
193 0 return $reffile->lookup_id($id);
194 }
195 } elsif ($ref=~m{\#?([^#]+)}) {
196 0 return GetNodeByID($1, $fsfile);
197 # return GetNodeByID($1);
198 }
199 0 return undef;
200 }
201  
202 sub member_to_pmltq {
203 0 ▶ my ($name, $val, $type, $indent, $fsfile, $opts)=@_;
Subroutine member_to_pmltq: not called CC=39 SCAR=73.5
Pod undocumented
204 0 my $out;
205 0 ▶ my $mtype = $name eq 'content()' ? $type : $type->get_knit_content_decl;
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'content()' ? : 0 0 0
206 0 ▶ if ($mtype->get_decl_type == PML_ALT_DECL and !UNIVERSAL::DOES::does($val,'Treex::PML::Alt')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtype->get_decl_type == 7 and not UNIVERSAL::DOES::does($val, "Treex::PML::Alt")) 0 0 0
Condition0%0/3
$mtype->get_decl_type == 7 and not UNIVERSAL::DOES::does($val, "Treex::PML::Alt")
!ll&&!rl&&r
000
MC/DC0%0/2
$mtype->get_decl_type == 7 and not UNIVERSAL::DOES::does($val, "Treex::PML::Alt")
$mtype->get_decl_type == 7 not UNIVERSAL::DOES::does($val, "Treex::PML::Alt")
Truth table0%0/3
A and not(B)
A= $mtype->get_decl_type == 7B= not UNIVERSAL::DOES::does($val, "Treex::PML::Alt")
ABresult
0X0
100
111
207 0 $mtype = $mtype->get_knit_content_decl;
208 }
209 0 ▶ if (not ref($val)) {
Branch: 5 branches
BranchTrueFalseTotal
if (not ref $val) { } 0 0 0
elsif (UNIVERSAL::DOES::does($val, 'Treex::PML::List')) { } 0 0 0
elsif (UNIVERSAL::DOES::does($val, 'Treex::PML::Alt')) { } 0 0 0
elsif (UNIVERSAL::DOES::does($val, 'Treex::PML::Struct') or UNIVERSAL::DOES::does($val, 'Treex::PML::Container')) { } 0 0 0
elsif (UNIVERSAL::DOES::does($val, 'Treex::PML::Seq')) { } 0 0 0
210 0 ▶ if (!$mtype->is_atomic) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $mtype->is_atomic) { } 0 0 0
211 0 $out.=$indent."# ignoring $name\n",
212 } else {
213 0 ▶ my $is_pmlref = (($mtype->get_decl_type == PML_CDATA_DECL) and ($mtype->get_format eq 'PMLREF')) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mtype->get_decl_type == 8 && $mtype->get_format eq 'PMLREF' ? : 0 0 0
Condition0%0/3
$mtype->get_decl_type == 8 and $mtype->get_format eq "PMLREF"
!ll&&!rl&&r
000
MC/DC0%0/2
$mtype->get_decl_type == 8 and $mtype->get_format eq "PMLREF"
$mtype->get_decl_type == 8 $mtype->get_format eq "PMLREF"
Truth table0%0/3
A and B
A= $mtype->get_decl_type == 8B= $mtype->get_format eq "PMLREF"
ABresult
0X0
100
111
214 0 ▶ if ($type and ($type->get_role() =~ /^#(ID|ORDER)$/ or $is_pmlref)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type->get_role =~ /^#(ID|ORDER)$/ || $is_pmlref) { } 0 0 0
Condition0%0/6
$type and $type->get_role =~ /^#(ID|ORDER)$/ || $is_pmlref
!ll&&!rl&&r
000
$type->get_role =~ /^#(ID|ORDER)$/ or $is_pmlref
l!l&&r!l&&!r
000
MC/DC0%0/3
$type and $type->get_role =~ /^#(ID|ORDER)$/ || $is_pmlref
$type $type->get_role =~ /^#(ID|ORDER)$/ $is_pmlref
Truth table0%0/4
A and B or C
A= $typeB= $type->get_role =~ /^#(ID|ORDER)$/C= $is_pmlref
ABCresult
0XX0
1000
11X1
1011
215 0 ▶ if ($is_pmlref and $opts->{id2name} and $val=~/(?:^.*?\#)?(.+)$/ and $opts->{id2name}{$1}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($is_pmlref and $opts->{'id2name'} and $val =~ /(?:^.*?\#)?(.+)$/ and $opts->{'id2name'}{$1}) { } 0 0 0
elsif ($is_pmlref) { } 0 0 0
elsif ($opts->{'no_comments'}) { } 0 0 0
Condition0%0/9
$is_pmlref and $opts->{"id2name"} and $val =~ /(?:^.*?\#)?(.+)$/ and $opts->{"id2name"}{$1}
!ll&&!rl&&r
000
$is_pmlref and $opts->{"id2name"} and $val =~ /(?:^.*?\#)?(.+)$/
!ll&&!rl&&r
000
$is_pmlref and $opts->{"id2name"}
!ll&&!rl&&r
000
MC/DC0%0/4
$is_pmlref and $opts->{"id2name"} and $val =~ /(?:^.*?\#)?(.+)$/ and $opts->{"id2name"}{$1}
$is_pmlref $opts->{"id2name"} $val =~ /(?:^.*?\#)?(.+)$/ $opts->{"id2name"}{$1}
Truth table0%0/5
A and B and C and D
A= $is_pmlrefB= $opts->{"id2name"}C= $val =~ /(?:^.*?\#)?(.+)$/D= $opts->{"id2name"}{$1}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
216 0 $out .= $indent.qq{$name \$}.$opts->{id2name}{$1}.qq{,\n};
217 } elsif ($is_pmlref) {
218 0 my $target = resolve_pmlref($val,$fsfile);
219 0 ▶ if ($target && $target->type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target and $target->type) { } 0 0 0
Condition0%0/3
$target and $target->type
!ll&&!rl&&r
000
MC/DC0%0/2
$target and $target->type
$target $target->type
Truth table0%0/3
A and B
A= $targetB= $target->type
ABresult
0X0
100
111
220 0 $out.=$indent.'# '.$name.' '.PMLTQ::Common::DeclToQueryType( $target->type ).qq{ [ ],\n};
221 } else {
222 0 $out.=$indent.'# '.$name.qq{->[ ],\n};
223 }
224 } elsif ($opts->{no_comments}) {
225 0 return;
226 } else {
227 0 $out.=$indent.'# '.qq{$name = }._pmltq_string($val).qq{,\n};
228 }
229 } else {
230 0 $out.=$indent;
231 0 $out.=qq{$name = }._pmltq_string($val).qq{,\n};
232 }
233 }
234 } elsif (UNIVERSAL::DOES::does($val,'Treex::PML::List')) {
235 0 ▶ if ($mtype->is_ordered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mtype->is_ordered) { } 0 0 0
236 0 my $i=1;
237 0 foreach my $v (@$val) {
238 0 $out.=member_to_pmltq("$name/[$i]",$v,$mtype,$indent,$fsfile,$opts);
239 0 $i++;
240 }
241 } else {
242 0 foreach my $v (@$val) {
243 0 $out.=member_to_pmltq($name,$v,$mtype,$indent,$fsfile,$opts);
244 }
245 }
246 } elsif (UNIVERSAL::DOES::does($val,'Treex::PML::Alt')) {
247 0 foreach my $v (@$val) {
248 0 $out.=member_to_pmltq($name,$v,$mtype,$indent,$fsfile,$opts);
249 }
250 ▶ } elsif (UNIVERSAL::DOES::does($val,'Treex::PML::Struct') or UNIVERSAL::DOES::does($val,'Treex::PML::Container')) {
Condition0%0/3
UNIVERSAL::DOES::does($val, "Treex::PML::Struct") or UNIVERSAL::DOES::does($val, "Treex::PML::Container")
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::DOES::does($val, "Treex::PML::Struct") or UNIVERSAL::DOES::does($val, "Treex::PML::Container")
UNIVERSAL::DOES::does($val, "Treex::PML::Struct") UNIVERSAL::DOES::does($val, "Treex::PML::Container")
Truth table0%0/3
A or B
A= UNIVERSAL::DOES::does($val, "Treex::PML::Struct")B= UNIVERSAL::DOES::does($val, "Treex::PML::Container")
ABresult
1X1
011
000
251 0 $out.=$indent.qq{member $name \[\n};
252 0 foreach my $attr ($mtype->get_normal_fields) {
253 0 my $m = $mtype->get_member_by_name($attr);
254 # next if $m and $m->get_role() eq '#ID';
255 0 my $v = $val->{$attr};
256 0 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
257 0 ▶ $m = $mtype->get_member_by_name($attr.'.rf') unless $m;
Branch: 1 branch
BranchTrueFalseTotal
unless $m 0 0 0
258 0 ▶ if (!$m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m) 0 0 0
259 0 ▶ $out .= " # $attr ???;" unless $opts->{no_comments};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"no_comments"} 0 0 0
260 0 next;
261 }
262 0 ▶ my $n = $attr eq '#content' ? 'content()' : $attr;
Branch: 1 branch
BranchTrueFalseTotal
$attr eq '#content' ? : 0 0 0
263 0 ▶ next if $opts->{exclude} and $opts->{exclude}{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"exclude"} and $opts->{"exclude"}{$n} 0 0 0
Condition0%0/3
$opts->{"exclude"} and $opts->{"exclude"}{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"exclude"} and $opts->{"exclude"}{$n}
$opts->{"exclude"} $opts->{"exclude"}{$n}
Truth table0%0/3
A and B
A= $opts->{"exclude"}B= $opts->{"exclude"}{$n}
ABresult
0X0
100
111
264 0 $out.=member_to_pmltq($n,$v,$m,$indent.' ',$fsfile,$opts);
265 }
266 0 $out.=$indent.qq{],\n}
267 } elsif (UNIVERSAL::DOES::does($val,'Treex::PML::Seq')) {
268 0 my $i=1;
269 0 foreach my $v ($val->elements) {
270 0 my $n = $v->name;
271 0 ▶ next if $opts->{exclude} and $opts->{exclude}{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"exclude"} and $opts->{"exclude"}{$n} 0 0 0
Condition0%0/3
$opts->{"exclude"} and $opts->{"exclude"}{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"exclude"} and $opts->{"exclude"}{$n}
$opts->{"exclude"} $opts->{"exclude"}{$n}
Truth table0%0/3
A and B
A= $opts->{"exclude"}B= $opts->{"exclude"}{$n}
ABresult
0X0
100
111
272 0 $out.=member_to_pmltq("$name/[$i]$n",$v->value,$mtype->get_element_by_name($n),$indent,$fsfile,$opts);
273 0 $i++;
274 }
275 }
276 0 return $out;
277 }
278  
279  
280 #=item PML::GetNodeByID($id_or_ref,$fsfile?)
281  
282 #Looks up a node from the current file (or given fsfile) by its ID (or
283 #PMLREF - i.e. the ID preceded by a file prefix of the form C<xy#>).
284  
285 #=cut
286  
287 sub GetNodeByID {
288 0 ▶ my ( $rf, $fsfile ) = @_;
Subroutine GetNodeByID: not called CC=1 SCAR=6.9
Pod undocumented
289 # if (!defined $fsfile) {
290 # warn("GetNodeByID TODO: FIX THIS !!!");
291 #$fsfile = $grp->{FSFile};
292 # }
293 0 $rf =~ s/^.*#//;
294 0 return GetNodeHash($fsfile)->{$rf};
295 }
296  
297 #=item PML::GetNodeHash($fsfile?)
298  
299 #Return a reference to a hash indexing nodes in a given file (or the
300 #current file if no argument is given). If such a hash was not yet
301 #created, it is built upon the first call to this function (or other
302 #functions calling it, such as C<GetNodeByID>. Use C<clearNodeHash> to
303 #clear the hash.
304  
305 #=cut
306  
307 sub GetNodeHash {
308 0 ▶ if (!ref $_[0]) {
Subroutine GetNodeHash: not called CC=6 SCAR=37.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0]) 0 0 0
309 0 shift;
310 }
311 #warn("GetNodeHash TODO: fix this:");
312 #my $fsfile = $_[0] || $grp->{FSFile};
313 0 my $fsfile = $_[0];
314 0 ▶ return {} if !ref $fsfile;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fsfile 0 0 0
315 0 ▶ if ( !ref $fsfile->appData('id-hash') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fsfile->appData("id-hash")) 0 0 0
316 0 my %ids;
317 0 my $trees = $fsfile->treeList();
318 0 ▶ for ( my $i = 0; $i <= $#{$trees}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$trees;}) 0 0 0
319 0 my $node = $trees->[$i];
320 0 ▶ while ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
321 0 weaken( $ids{ $node->{id} } = $node );
322 }
323 continue {
324 0 $node = $node->following;
325 }
326 }
327 0 $fsfile->changeAppData( 'id-hash', \%ids );
328 }
329 0 return $fsfile->appData('id-hash');
330 }
331  
332  
333 2 1;
↑ Summary blib/lib/PMLTQ/Suggest/Utils.pm »