File Coverage

blib/lib/DDC/PP/CQueryOptions.pm
Criterion Covered Total %
statement 35 57 61.4
branch 22 42 52.3
condition 8 17 47.0
subroutine 12 17 70.5
pod 0 11 0.0
total 77 144 53.4


line stmt bran cond sub pod time code
1             ##-*- Mode: CPerl -*-
2              
3             ##======================================================================
4             ## top-level
5             package DDC::PP::CQueryOptions;
6 20     20   136 use DDC::PP::Constants;
  20         40  
  20         1509  
7 20     20   95 use DDC::PP::Object;
  20         37  
  20         380  
8 20     20   91 use DDC::Utils qw();
  20         34  
  20         343  
9 20     20   92 use Carp qw(carp confess);
  20         38  
  20         1030  
10 20     20   130 use strict;
  20         37  
  20         582  
11              
12             ##======================================================================
13             ## CQueryOptions
14             package DDC::PP::CQueryOptions;
15 20     20   106 use strict;
  20         34  
  20         17060  
16             our @ISA = qw(DDC::PP::Object);
17              
18             __PACKAGE__->defprop($_)
19             foreach (qw(ContextSentencesCount EnableBibliography DebugRank SeparateHits Filters Subcorpora Comments LexerComments)); #Within
20 4     4 0 12 sub getWithin { return $_[0]{Within}; }
21 2 50   2 0 26 sub setWithin { return $_[0]{Within} = UNIVERSAL::isa($_[1],'ARRAY') ? $_[1] : [$_[1]]; }
22             __PACKAGE__->defalias('ContextCount'=>'ContextSentencesCount',0,1);
23              
24             sub new {
25 428     428 0 753 my ($that,%opts) = @_;
26 428         1415 return $that->SUPER::new(EnableBibliography=>1,Filters=>[],Subcorpora=>[],Within=>[],Comments=>[],LexerComments=>[],%opts);
27             }
28              
29             sub swap {
30 0     0 0 0 my ($a,$b) = @_;
31 0         0 my %tmp = %$b;
32 0         0 %$b = %$a;
33 0         0 %$a = %tmp;
34 0         0 return $a;
35             }
36              
37             sub Clear {
38 0     0 0 0 @{$_[0]{Filters}} = @{$_[0]{Subcorpora}} = @{$_[0]{Comments}} = @{$_[0]{LexerComments}} = qw();
  0         0  
  0         0  
  0         0  
  0         0  
39             }
40             sub ClearComments {
41 0     0 0 0 @{$_[0]{Comments}} = @{$_[0]{LexerComments}} = qw();
  0         0  
  0         0  
42             }
43              
44             __PACKAGE__->nomethod('CanFilterByFile');
45              
46 0 0   0 0 0 sub Children { return [ @{$_[0]{Filters}||[]} ]; }
  0         0  
47              
48 0 0   0 0 0 sub sqString { return DDC::Utils::escapeq(defined($_[1]) ? $_[1] : ''); }
49             sub toString {
50 2     2 0 5 my $qo = shift;
51             return (
52 0         0 ($qo->{Within} ? join('', map {" #WITHIN ".$qo->sqString($_)} @{$qo->{Within}}) : '')
  2         20  
53             .($qo->{ContextSentencesCount} ? " #CNTXT $qo->{ContextSentencesCount}" : '')
54             .($qo->{SeparateHits} ? " #SEPARATE" : '')
55             .(!$qo->{EnableBibliography} ? " #FILENAMES" : '')
56             .($qo->{DebugRank} ? " #DEBUG_RANK" : '')
57 0 50       0 .join('', map {" ".$_->toString} @{$qo->{Filters}||[]})
  2         10  
58 0 50       0 .join('', map {" #CMT ".$qo->sqString($_)} @{$qo->{Comments}||[]})
  2         9  
59 0   50     0 .join('', map {" $_"} @{$qo->{LexerComments}//[]})
  2         15  
60 2 50 33     7 .($qo->{Subcorpora} && @{$qo->{Subcorpora}} ? (" :".join(',', map {$qo->sqString($_)} @{$qo->{Subcorpora}})) : '')
  0 50       0  
  0 50       0  
    50          
    50          
    50          
61             );
62             }
63              
64             ##-- ddc-compatible hash-conversion (for toJson())
65             sub toHash {
66 186     186 0 361 my ($obj,%opts) = @_;
67 186 100       448 return $obj->SUPER::toHash(%opts) if (!$opts{json});
68 184         433 return { class=>$obj->jsonClass, $obj->jsonData };
69             }
70             sub jsonData {
71 184     184 0 278 my $qo = shift;
72             return (($qo->{Within} && $qo->{Within} ? (Within=>$qo->{Within}) : qw()),
73             ($qo->{ContextSentencesCount} ? (ContextCount=>$qo->{ContextSentencesCount}) : qw()),
74             ($qo->{SeparateHits} ? (SeparateHits=>$qo->{SeparateHits}) : qw()),
75             ($qo->{EnableBibliography} ? (EnableBibliography=>$qo->{EnableBibliography}) : qw()),
76             ($qo->{DebugRank} ? (DebugRank=>$qo->{DebugRank}) : qw()),
77 12 50       62 (Filters=>[map {($_->toHash(json=>1))} @{$qo->{Filters}||[]}]),
  184         631  
78             ($qo->{Subcorpora} && @{$qo->{Subcorpora}} ? (Subcorpora=>$qo->{Subcorpora}) : qw()),
79             ($qo->{Comments} && @{$qo->{Comments}} ? (Comments=>$qo->{Comments}) : qw()),
80 184 50 33     1217 ($qo->{LexerComments} && @{$qo->{LexerComments}} ? (LexerComments=>$qo->{LexerComments}) : qw()),
    50 66        
    50 66        
    50 33        
    50          
    100          
    100          
    50          
81             );
82             }
83              
84              
85             1; ##-- be happy
86              
87             =pod
88              
89             =head1 NAME
90              
91             DDC::PP::CQueryOptions - pure-perl implementation of DDC::XS::CQueryOptions
92              
93             =head1 SYNOPSIS
94              
95             use DDC::PP::CQueryOptions;
96             #... stuff happens ...
97              
98              
99             =head1 DESCRIPTION
100              
101             The DDC::PP::CQueryOptions class is a pure-perl fork of the L class,
102             which see for details.
103              
104             =head1 SEE ALSO
105              
106             perl(1),
107             DDC::PP(3perl),
108             DDC::XS::CQueryOptions(3perl).
109              
110             =head1 AUTHOR
111              
112             Bryan Jurish Emoocow@cpan.orgE
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             Copyright (C) 2016-2020 by Bryan Jurish
117              
118             This library is free software; you can redistribute it and/or modify
119             it under the same terms as Perl itself, either Perl version 5.14.2 or,
120             at your option, any later version of Perl 5 you may have available.
121              
122             =cut
123