Qgoda/Site.pm

filter: Statementstmt 35.0% 89 / 254 Branchbran 20.5% 14 / 68 Conditioncond 5.7% 2 / 35 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 35.7% 20 / 56 Podpod 0.0% 0 / 21 totaltotal 27.3% 125 / 457 CC 65 SCAR 38.3
CC
65
Cov
29%
computeRelations
133.2
filter
102.4
getTaxonomyValues
90.0
CRAP 46.1
« Qgoda/Command/Po.pm ↑ Summary Qgoda/Init/node.pm »
1 #! /bin/false
2  
3 # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15  
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18  
19 package Qgoda::Site;
20 6 $Qgoda::Site::VERSION = 'v0.9.2';
21 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # FIXME! This is only needed for debugging the filter cache. Remove it,
24 # once the filter cache is stable.
25 6 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use List::Util qw(pairs any);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 6 ▶use Qgoda::Util qw(canonical empty);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use Qgoda::Artefact;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 sub new {
33 2 ▶ my ($class, $config) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34  
35 2 my $self = {
36 config => $config,
37 assets => {},
38 artefacts => {},
39 __filter_cache => {},
40 __modified => {},
41 __relpaths => {},
42 __errors => 0,
43 };
44  
45 2 bless $self, $class;
46 }
47  
48 sub addAsset {
49 3 ▶ my ($self, $asset) = @_;
Subroutine addAsset: called CC=1 SCAR=0.0
Pod undocumented
50  
51 3 my $path = $asset->getPath;
52 3 $self->{assets}->{$path} = $asset;
53 3 $self->{__relpaths}->{$asset->getRelpath} = $asset;
54  
55 3 return $self;
56 }
57  
58 sub removeAsset {
59 0 ▶ my ($self, $asset) = @_;
Subroutine removeAsset: not called CC=1 SCAR=6.9
Pod undocumented
60  
61 0 delete $self->{assets}->{$asset->getPath};
62 0 delete $self->{__relpaths}->{$asset->getRelpath};
63  
64 0 return $self;
65 }
66  
67 sub purgeAsset {
68 0 ▶ my ($self, $asset) = @_;
Subroutine purgeAsset: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 0 $self->removeAsset($asset);
71  
72 0 ++$self->{__errors};
73  
74 0 return $self;
75 }
76  
77 sub getErrors {
78 2 ▶ shift->{__errors};
Subroutine getErrors: called CC=1 SCAR=0.0
Pod undocumented
79 }
80  
81 sub getAssets {
82 8 ▶ sort { $a->{priority} <=> $b->{priority} } values %{shift->{assets}};
Subroutine getAssets: called CC=1 SCAR=0.0
Pod undocumented
83 }
84  
85 sub addArtefact {
86 3 ▶ my ($self, $path, $origin) = @_;
Subroutine addArtefact: called CC=1 SCAR=0.0
Pod undocumented
87  
88 3 my $artefact = Qgoda::Artefact->new($path, $origin);
89 3 $self->{artefacts}->{$path} = $artefact;
90  
91 3 return $self;
92 }
93  
94 sub getArtefact {
95 3 ▶ my ($self, $name) = @_;
Subroutine getArtefact: called CC=2 SCAR=8.1
Pod undocumented
96  
97 3 ▶ return if !exists $self->{artefacts}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"artefacts"}{$name} 3 0 3
98  
99 0 return $self->{artefacts}->{$name};
100 }
101  
102 sub getArtefacts {
103 2 ▶ values %{shift->{artefacts}};
Subroutine getArtefacts: called CC=1 SCAR=0.0
Pod undocumented
104 }
105  
106 sub addModified {
107 3 ▶ my ($self, $path, $asset) = @_;
Subroutine addModified: called CC=1 SCAR=0.0
Pod undocumented
108  
109 3 $self->{__modified}->{$path} = $asset;
110  
111 3 return $self;
112 }
113  
114 sub getModified {
115 2 ▶ shift->{__modified};
Subroutine getModified: called CC=1 SCAR=0.0
Pod undocumented
116 }
117  
118 # Only works for top-level keys!
119 sub getMetaValue {
120 15 ▶ my ($self, $key, $asset) = @_;
Subroutine getMetaValue: called CC=3 SCAR=11.0
Pod undocumented
121  
122 15 ▶ if (exists $asset->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $asset->{$key}) 3 12 15
123 3 return $asset->{$key};
124 }
125  
126 12 my $config = $self->{config};
127 12 ▶ if (exists $config->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{$key}) 9 3 12
128 9 return $config->{$key};
129 }
130  
131 3 return;
132 }
133  
134 sub getTrigger {
135 3 ▶ my ($self, @suffixes) = @_;
Subroutine getTrigger: called CC=3 SCAR=12.0
Pod undocumented
136  
137 3 my $triggers = $self->{config}->{processors}->{triggers};
138 3 ▶ for (my $i = $#suffixes; $i >= 0; --$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 3 0 3
139 return $suffixes[$i]
140 3 ▶ if exists $triggers->{$suffixes[$i]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$triggers{$suffixes[$i]} 3 0 3
141 }
142  
143 0 return;
144 }
145  
146 sub getChainByTrigger {
147 3 ▶ my ($self, $trigger) = @_;
Subroutine getChainByTrigger: called CC=4 SCAR=14.5
Pod undocumented
148  
149 3 my $config = $self->{config}->{processors};
150 3 my $name = $config->{triggers}->{$trigger};
151 3 ▶ return if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 3 3
152 3 ▶ my $chain = $config->{chains}->{$name} || return;
Condition50%1/2
$config->{'chains'}{$name} || (return)
l!l
30
MC/DC0%0/1
$config->{'chains'}{$name} || (return)
$config->{'chains'}{$name}
Truth table50%1/2
A
A= $config->{'chains'}{$name}
Aresult
11
00
153  
154 3 ▶ return wantarray ? ($chain, $name) : $chain;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
155 }
156  
157 sub getChain {
158 0 ▶ my ($self, $asset) = @_;
Subroutine getChain: not called CC=4 SCAR=30.0
Pod undocumented
159  
160 0 ▶ my $suffixes = $asset->{suffixes} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $suffixes = $asset->{"suffixes"} or return 0 0 0
161 0 my $trigger = $self->getTrigger(@$suffixes);
162 0 ▶ return unless defined $trigger;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trigger 0 0 0
163 0 ▶ my $chain = $self->getChainByTrigger($trigger) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $chain = $self->getChainByTrigger($trigger) or return 0 0 0
164  
165 0 return $chain;
166 }
167  
168 sub searchAssets {
169 0 ▶ my ($self, %filters) = @_;
Subroutine searchAssets: not called CC=6 SCAR=37.4
Pod undocumented
170  
171 # Sort the filters, so that we can canonicalize them.
172 0 my @_filters;
173 0 foreach my $key (sort keys %filters) {
174 0 push @_filters, $key, $filters{$key};
175 }
176  
177 0 my $canonical = encode_base64 canonical \@_filters;
178 0 ▶ if (exists $self->{__filter_cache}->{$canonical}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"__filter_cache"}{$canonical}) 0 0 0
179 0 my @copy;
180 0 foreach my $path (@{$self->{__filter_cache}->{$canonical}}) {
181 push @copy, $self->{assets}->{$path}
182 0 ▶ if $self->{assets}->{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"assets"}{$path} 0 0 0
183 }
184 0 return \@copy;
185 }
186  
187 0 my $found = $self->filter([values %{$self->{assets}}], %filters);
188  
189 0 my @paths;
190 0 foreach my $found (@$found) {
191 0 push @paths, $found->{path};
192 }
193 0 $self->{__filter_cache}->{$canonical} = \@paths;
194  
195 0 return $found;
196 }
197  
198 sub filter {
199 0 ▶ my ($self, $set, %filters) = @_;
Subroutine filter: not called CC=10 SCAR=46.3
Pod undocumented
200  
201 # Preprocess the filters.
202 0 my @_filters;
203 0 foreach my $key (sort keys %filters) {
204 0 push @_filters, $key, $filters{$key};
205 }
206
207 my $visualize = sub {
208 0 ▶ my ($index) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
209  
210 0 $_filters[$index] = ">>>$_filters[$index]<<<";
211 0 join ', ', @_filters;
212 0 };
213  
214 0 my @filters;
215 my %operators = (
216 0 ▶ eq => sub { $_[0] eq $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 0 ▶ ne => sub { $_[0] ne $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
218 0 ▶ ge => sub { warn "'$_[0]' ge '$_[1]'?\n"; $_[0] ge $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
219 0 ▶ gt => sub { $_[0] gt $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 0 ▶ le => sub { $_[0] le $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
221 0 ▶ lt => sub { $_[0] lt $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 0 ▶ ieq => sub { (lc $_[0]) eq (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 0 ▶ ine => sub { (lc $_[0]) ne (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
224 0 ▶ ige => sub { (lc $_[0]) ge (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
225 0 ▶ igt => sub { (lc $_[0]) gt (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 ▶ ile => sub { (lc $_[0]) le (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
227 0 ▶ ilt => sub { (lc $_[0]) lt (lc $_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
228 0 ▶ '==' => sub { $_[0] == $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
229 0 ▶ '!=' => sub { $_[0] != $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
230 0 ▶ '>=' => sub { $_[0] >= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
231 0 ▶ '>' => sub { $_[0] > $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 0 ▶ '<=' => sub { $_[0] <= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
233 0 ▶ '<' => sub { $_[0] < $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
234 0 ▶ '=~' => sub { $_[0] =~ $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
235 0 ▶ '!~' => sub { $_[0] !~ $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
236 0 ▶ '&' => sub { $_[0] & $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
237 0 ▶ '|' => sub { $_[0] | $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
238 0 ▶ '^' => sub { $_[0] ^ $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
239 'contains' => sub {
240 0 ▶ my @haystack;
Subroutine __ANON__: not called CC=5 SCAR=34.0
241 0 ▶ if (ref $_[0] && 'ARRAY' eq reftype $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] and 'ARRAY' eq builtin::reftype($_[0])) { } 0 0 0
elsif (ref $_[0] and 'HASH' eq builtin::reftype($_[0])) { } 0 0 0
Condition0%0/3
ref $_[0] and "ARRAY" eq builtin::reftype($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and "ARRAY" eq builtin::reftype($_[0])
ref $_[0] "ARRAY" eq builtin::reftype($_[0])
Truth table0%0/3
A and B
A= ref $_[0]B= "ARRAY" eq builtin::reftype($_[0])
ABresult
0X0
100
111
242 0 @haystack = @{$_[0]};
243 ▶ } elsif (ref $_[0] && 'HASH' eq reftype $_[0]) {
Condition0%0/3
ref $_[0] and "HASH" eq builtin::reftype($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and "HASH" eq builtin::reftype($_[0])
ref $_[0] "HASH" eq builtin::reftype($_[0])
Truth table0%0/3
A and B
A= ref $_[0]B= "HASH" eq builtin::reftype($_[0])
ABresult
0X0
100
111
244 0 @haystack = keys %{$_[0]};
245 } else {
246 0 @haystack = ($_[0]);
247 }
248 0 ▶ any { $_[1] eq $_ } @haystack;
Subroutine __ANON__: not called CC=1 SCAR=6.9
249 },
250 'icontains' => sub {
251 0 ▶ my @haystack;
Subroutine __ANON__: not called CC=5 SCAR=34.0
252 0 ▶ if (ref $_[0] && 'ARRAY' eq reftype $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] and 'ARRAY' eq builtin::reftype($_[0])) { } 0 0 0
elsif (ref $_[0] and 'HASH' eq builtin::reftype($_[0])) { } 0 0 0
Condition0%0/3
ref $_[0] and "ARRAY" eq builtin::reftype($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and "ARRAY" eq builtin::reftype($_[0])
ref $_[0] "ARRAY" eq builtin::reftype($_[0])
Truth table0%0/3
A and B
A= ref $_[0]B= "ARRAY" eq builtin::reftype($_[0])
ABresult
0X0
100
111
253 0 @haystack = @{$_[0]};
254 ▶ } elsif (ref $_[0] && 'HASH' eq reftype $_[0]) {
Condition0%0/3
ref $_[0] and "HASH" eq builtin::reftype($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and "HASH" eq builtin::reftype($_[0])
ref $_[0] "HASH" eq builtin::reftype($_[0])
Truth table0%0/3
A and B
A= ref $_[0]B= "HASH" eq builtin::reftype($_[0])
ABresult
0X0
100
111
255 0 @haystack = keys %{$_[0]};
256 } else {
257 0 @haystack = ($_[0]);
258 }
259 0 my $needle = lc $_[1];
260 0 ▶ any { $needle eq lc $_ } @haystack;
Subroutine __ANON__: not called CC=1 SCAR=6.9
261 },
262 0 );
263  
264 # FIXME! Simplyfy this! We always expect a key, the value is either a
265 # scalar or an array ref, containg the operator and the value.
266 0 foreach my $kv (pairs @_filters) {
267 0 my ($key, $value, $op) = @$kv;
268  
269 0 ▶ if (ref $value && 'ARRAY' eq reftype $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and 'ARRAY' eq builtin::reftype($value)) { } 0 0 0
Condition0%0/3
ref $value and "ARRAY" eq builtin::reftype($value)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and "ARRAY" eq builtin::reftype($value)
ref $value "ARRAY" eq builtin::reftype($value)
Truth table0%0/3
A and B
A= ref $valueB= "ARRAY" eq builtin::reftype($value)
ABresult
0X0
100
111
270 0 ($op, $value) = @$value;
271 } else {
272 0 $op = 'eq';
273 }
274  
275 0 push @filters, [$op, $key, $value];
276 }
277  
278 0 foreach my $filter (@filters) {
279 0 my ($op, $key, $value) = @$filter;
280 0 ▶ my $sub = $operators{$op} || $operators{eq};
Condition0%0/3
$operators{$op} || $operators{'eq'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$operators{$op} || $operators{'eq'}
$operators{$op} $operators{'eq'}
Truth table0%0/3
A || B
A= $operators{$op}B= $operators{'eq'}
ABresult
1X1
011
000
281  
282 0 ▶ if ('=~' eq $op || '!~' eq $op) {
Branch: 1 branch
BranchTrueFalseTotal
if ("=~" eq $op or "!~" eq $op) 0 0 0
Condition0%0/3
"=~" eq $op or "!~" eq $op
l!l&&r!l&&!r
000
MC/DC0%0/2
"=~" eq $op or "!~" eq $op
"=~" eq $op "!~" eq $op
Truth table0%0/3
A or B
A= "=~" eq $opB= "!~" eq $op
ABresult
1X1
011
000
283 0 $value = eval { qr/$value/ };
284 0 die __x("invalid regular expression in filter: {error}",
285 error => $@);
286 }
287 0 $filter->[0] = $sub;
288 0 $filter->[2] = $value;
289 }
290  
291 0 my @found = @$set;
292  
293 {
294 6 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.2
295  
296 0 foreach my $filter (@filters) {
297 0 my $stash = Template::Stash->new({found => \@found});
298 0 my $idx = 0;
299 @found = grep {
300 0 my $asset = $_;
301 0 my ($sub, $key, $value) = @$filter;
302 0 my $got_value = $stash->get("found.$idx.$key");
303 0 ++$idx;
304 0 $sub->($got_value, $value);
305 } @found;
306 }
307 }
308  
309 0 return \@found;
310 }
311  
312 sub computeRelations {
313 2 ▶ my ($self) = @_;
Subroutine computeRelations: called CC=22 SCAR=48.9
Pod undocumented
314  
315 2 my $config = Qgoda->new->{taxonomies};
316  
317 # First pass. Get permalinks.
318 2 my %locations;
319 my %permalinks;
320 2 my $taxonomies = Qgoda->new->config->{taxonomies};
321 2 my %taxonomies;
322 my %links;
323  
324 2 my %related;
325  
326 2 foreach my $asset (values %{$self->{assets}}) {
327 3 ▶ next if $asset->{virtual};
Branch: 1 branch
BranchTrueFalseTotal
if $asset->{"virtual"} 0 3 3
328  
329 3 my $permalink = $asset->{permalink};
330 3 $locations{$asset->{location}} = $asset;
331 3 $permalinks{$permalink} = $asset;
332  
333 3 foreach my $link (@{$asset->{links}}) {
334 0 $links{$link}->{$permalink} = $asset;
335 }
336  
337 3 foreach my $key (keys %$taxonomies) {
338 9 ▶ next if !exists $asset->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $asset->{$key} 6 3 9
339 3 my @values = $asset->{$key};
340 3 ▶ @values = @{$values[0]}
Branch: 1 branch
BranchTrueFalseTotal
if ref $values[0] and "ARRAY" eq builtin::reftype($values[0]) 3 0 3
Condition33%1/3
ref $values[0] and "ARRAY" eq builtin::reftype($values[0])
!ll&&!rl&&r
003
MC/DC0%0/2
ref $values[0] and "ARRAY" eq builtin::reftype($values[0])
ref $values[0] "ARRAY" eq builtin::reftype($values[0])
Truth table33%1/3
A and B
A= ref $values[0]B= "ARRAY" eq builtin::reftype($values[0])
ABresult
0X0
100
111
341 if ref $values[0] && 'ARRAY' eq reftype $values[0];
342 3 foreach my $value (@values) {
343 0 $taxonomies{$key}->{$value}->{$permalink} = 1;
344 }
345 }
346 }
347  
348 # Second pass. Add values for links between assets.
349 2 my $link_score = $config->{link_score};
350 2 ▶ if ($link_score) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link_score) 0 2 2
351 0 foreach my $permalink (keys %permalinks) {
352 0 my $asset = $permalinks{$permalink};
353 0 my $links = $asset->{links};
354 0 foreach my $link (@$links) {
355 0 my $target;
356 0 ▶ if (exists $permalinks{$link}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $permalinks{$link}) { } 0 0 0
elsif (exists $locations{$link}) { } 0 0 0
357 0 $target = $permalinks{$link}
358 } elsif (exists $locations{$link}) {
359 0 $target = $locations{$link};
360 }
361  
362 0 ▶ if ($target && $target != $asset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target and $target != $asset) 0 0 0
Condition0%0/3
$target and $target != $asset
!ll&&!rl&&r
000
MC/DC0%0/2
$target and $target != $asset
$target $target != $asset
Truth table0%0/3
A and B
A= $targetB= $target != $asset
ABresult
0X0
100
111
363 0 $related{$permalink}->{$target->{permalink}} += $link_score;
364 0 $related{$target->{permalink}}->{$permalink} += $link_score;
365 }
366 }
367 }
368 }
369  
370 # Third passs. Evaluate common taxonmy values.
371 2 foreach my $name (keys %taxonomies) {
372 0 my $taxonomy = $taxonomies{$name};
373 0 ▶ my $score = $taxonomies->{$name} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $score = $taxonomies->{$name} or next 0 0 0
374 0 foreach my $value (keys %$taxonomy) {
375 0 my $permalinks = $taxonomy->{$value};
376 0 my @permalinks = keys %$permalinks;
377 0 my $current = shift @permalinks;
378 0 ▶ while (@permalinks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@permalinks) 0 0 0
379 0 foreach my $permalink (@permalinks) {
380 0 $related{$current}->{$permalink} += $score;
381 0 $related{$permalink}->{$current} += $score;
382 }
383 0 $current = shift @permalinks;
384 }
385 }
386 }
387  
388 2 foreach my $permalink (keys %related) {
389 0 my $peers = $related{$permalink};
390  
391 # Delete relation with itself.
392 0 delete $peers->{$permalink};
393  
394 # Sort by relevance and replace score with asset-score pair.
395 # FIXME! Turn that into a hash instead?
396 my @related =
397 0 map { [$permalinks{$_}, $peers->{$_}] }
398 0 sort { $peers->{$a} <=> $peers->{$b} } keys %{$peers};
399
400 0 $permalinks{$permalink}->{related} = \@related;
401 }
402  
403 2 return $self
404 }
405  
406 # FIXME! Do we need this method?
407 sub getTaxonomyValues {
408 0 ▶ my ($self, $taxonomy, %filters) = @_;
Subroutine getTaxonomyValues: not called CC=9 SCAR=45.0
Pod undocumented
409  
410 0 my $assets = $self->searchAssets(%filters);
411 0 my %values;
412 0 foreach my $asset (@$assets) {
413 0 ▶ next if !exists $asset->{$taxonomy};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $asset->{$taxonomy} 0 0 0
414  
415 0 my $value = $asset->{$taxonomy};
416 0 ▶ if (ref $value && 'ARRAY' eq reftype $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value and 'ARRAY' eq builtin::reftype($value)) { } 0 0 0
elsif (ref $value and 'HASH' eq builtin::reftype($value)) { } 0 0 0
Condition0%0/3
ref $value and "ARRAY" eq builtin::reftype($value)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and "ARRAY" eq builtin::reftype($value)
ref $value "ARRAY" eq builtin::reftype($value)
Truth table0%0/3
A and B
A= ref $valueB= "ARRAY" eq builtin::reftype($value)
ABresult
0X0
100
111
417 0 map { $values{$_} = 1 } grep { !empty $_ } @$value;
418 ▶ } elsif (ref $value && 'HASH' eq reftype $value) {
Condition0%0/3
ref $value and "HASH" eq builtin::reftype($value)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and "HASH" eq builtin::reftype($value)
ref $value "HASH" eq builtin::reftype($value)
Truth table0%0/3
A and B
A= ref $valueB= "HASH" eq builtin::reftype($value)
ABresult
0X0
100
111
419 0 ▶ map { $values{$_} = 1 if !empty $_ } keys %$value;
Branch: 1 branch
BranchTrueFalseTotal
if not &empty($_) 0 0 0
420 } else {
421 0 ▶ $values{$value} = 1 if !empty $value;
Branch: 1 branch
BranchTrueFalseTotal
unless &empty($value) 0 0 0
422 }
423 }
424  
425 0 return keys %values;
426 }
427  
428 sub getAssetByPath {
429 0 ▶ my ($self, $path) = @_;
Subroutine getAssetByPath: not called CC=2 SCAR=17.9
Pod undocumented
430  
431 0 ▶ return if !exists $self->{assets}->{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"assets"}{$path} 0 0 0
432  
433 0 return $self->{assets}->{$path};
434 }
435  
436 sub getAssetByRelpath {
437 0 ▶ my ($self, $relpath) = @_;
Subroutine getAssetByRelpath: not called CC=2 SCAR=17.9
Pod undocumented
438  
439 0 ▶ return if !exists $self->{__relpaths}->{$relpath};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"__relpaths"}{$relpath} 0 0 0
440  
441 0 return $self->{__relpaths}->{$relpath};
442 }
443  
444 6 1;
« Qgoda/Command/Po.pm ↑ Summary Qgoda/Init/node.pm »