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