blib/lib/DDC/Hit.pm

filter: Statementstmt 19.0% 4 / 21 Branchbran n/a Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 1 / 4 Podpod 33.3% 1 / 3 totaltotal 13.0% 6 / 46 CC 8 SCAR 36.1
CC
8
Cov
12%
expandFields
56.0
new
6.0
TO_JSON
2.0
CRAP 37.0
« blib/lib/DDC/Format/Text.pm ↑ Summary blib/lib/DDC/PP/CQCount.pm »
1 ##-*- Mode: CPerl -*-
2  
3 ## File: DDC::Hit.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description:
6 ## + DDC Query utilities: Hit
7 ##======================================================================
8  
9 package DDC::Hit;
10 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ##======================================================================
13 ## Globals
14  
15 ##======================================================================
16 ## Constructors, etc.
17  
18 ## $hit = $CLASS_OR_OBJ->new(%args)
19 ## + %$hit = %args =
20 ## (
21 ## raw_ => $raw_data, ##-- hit data (raw buffer)
22 ## meta_ => \%meta, ##-- bibliographic metadata (parsed)
23 ## ctx_ => \@context, ##-- hit context (parsed)
24 ## )
25 ## where \%meta =
26 ## {
27 ## file_ => $ddcFile,
28 ## scan_ => $ddcScanStr,
29 ## orig_ => $ddcOrigStr,
30 ## date_ => $ddcDate,
31 ## page_ => $ddcPage,
32 ## rank_ => $ddcRank,
33 ## rank_debug_ => $ddcRankDebug,
34 ## indices_ => \@indexNames,
35 ## $biblField => $biblValue, ##-- free bibliographic field fata
36 ## }
37 ## and @context =
38 ## [
39 ## \@leftContext, ##-- [$w1,$w2,...,$wN] : pre-hit context: word strings <ddc-v2.0.38 (parsed if array)
40 ## \@hitTokens, ##-- [$t1,$t2,...\$tN] : hit tokens: parsed (without expandFields)
41 ## \@leftContext, ##-- [$w1,$w2,...,$wN] : post-hit context: word strings <ddc-v2.0.38 (parsed if array)
42 ## ]
43 ## and each $ti = $hitTokens[$i] =
44 ## [$hl,$f1val,$f2val,...,$fNval] ##-- without expandFields
45 ## {hl_=>$matchId, $f1name=>$f1val, ...} ##-- with expandFields
46 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
47 0 my $that = shift;
48 0 ▶ return bless { @_ }, ref($that)||$that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
49 }
50  
51 ## $hit = $hit->expandFields()
52 ## $hit = $hit->expandFields(\@fieldNames)
53 ## + expand hit data tokens from arrays to hashes
54 ## + initial field is always implicitly 'hl_' (highlighting match-id, can be treated as bool)
55 0 ▶sub expandFields {
Subroutine expandFields: not called CC=7 SCAR=40.3
Pod undocumented
56 0 my ($hit,$names) = @_;
57 0 ▶ my @names = ('hl_', @{$names||$hit->{meta_}{indices_}||[]});
Condition0%0/5
$names || $hit->{'meta_'}{'indices_'} || []
l!l
00
$names or $hit->{"meta_"}{"indices_"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$names || $hit->{'meta_'}{'indices_'} || []
$names $hit->{"meta_"}{"indices_"}
Truth table0%0/3
A or B
A= $namesB= $hit->{"meta_"}{"indices_"}
ABresult
1X1
011
000
58 0 my ($w);
59 0 ▶ foreach (grep {defined $_} @{$hit->{ctx_}||[]}) { ##-- expand deep-encoded json context tokens if available (ddc >= v2.0.38)
Condition0%0/2
$hit->{'ctx_'} || []
l!l
00
MC/DC0%0/1
$hit->{'ctx_'} || []
$hit->{'ctx_'}
Truth table0%0/2
A
A= $hit->{'ctx_'}
Aresult
11
00
60 0 foreach (grep {UNIVERSAL::isa($_,'ARRAY')} @$_) {
61 0 $w = $_;
62 0 ▶ $_ = { map {(($names[$_]||"${_}_")=>$w->[$_])} (0..$#$w) };
Condition0%0/2
$names[$_] || "${_}_"
l!l
00
MC/DC0%0/1
$names[$_] || "${_}_"
$names[$_]
Truth table0%0/2
A
A= $names[$_]
Aresult
11
00
63 }
64 }
65 0 return $hit;
66 }
67  
68 ## $thingy = $obj->TO_JSON()
69 ## + annoying wrapper for JSON
70 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
71 0 return { %{$_[0]} };
72 }
73  
74  
75 26 1; ##-- be happy
76  
77 __END__
« blib/lib/DDC/Format/Text.pm ↑ Summary blib/lib/DDC/PP/CQCount.pm »