blib/lib/Search/Tools/ArgNormalizer.pm

filter: Statementstmt 81.5% 31 / 38 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 75.4% 46 / 61 CC 7 SCAR 15.5
CC
7
Cov
75%
BUILDARGS
8.1
queryparser_can
2.0
BEGIN
1.0
CRAP 4.7
« blib/lib/Search/Tools/Transliterate.pm ↑ Summary blib/lib/Search/Tools.pm »
1 package Search::Tools::ArgNormalizer;
2 22 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Data::Dump qw( dump );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 our $VERSION = '1.007';
8  
9 53 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=6 SCAR=20.9
Pod documented
10 53 my $self = shift;
11 53 my %args = @_;
12 53 my $q = delete $args{query};
13 53 my $debug = delete $args{debug};
14 53 ▶ if ( !defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $q) 0 53 53
15 0 confess "query required";
16 }
17 53 ▶ if ( !ref($q) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $q) { } 25 28 53
elsif (ref $q eq 'ARRAY') { } 0 28 28
elsif (builtin::blessed($q) and $q->isa('Search::Tools::Query')) { } 28 0 28
18 25 require Search::Tools::QueryParser;
19 $args{query} = Search::Tools::QueryParser->new(
20 debug => $debug,
21 9 map { $_ => delete $args{$_} }
22 25 grep { $self->queryparser_can($_) } keys %args
23 )->parse($q);
24 }
25 elsif ( ref($q) eq 'ARRAY' ) {
26 0 carp "query ARRAY ref deprecated as of version 0.24";
27 0 require Search::Tools::QueryParser;
28 $args{query} = Search::Tools::QueryParser->new(
29 debug => $debug,
30 0 map { $_ => delete $args{$_} }
31 0 grep { $self->queryparser_can($_) } keys %args
32 )->parse( join( ' ', @$q ) );
33 }
34 ▶ elsif ( blessed($q) and $q->isa('Search::Tools::Query') ) {
Condition33%1/3
builtin::blessed($q) and $q->isa("Search::Tools::Query")
!ll&&!rl&&r
0028
MC/DC0%0/2
builtin::blessed($q) and $q->isa("Search::Tools::Query")
builtin::blessed($q) $q->isa("Search::Tools::Query")
Truth table33%1/3
A and B
A= builtin::blessed($q)B= $q->isa("Search::Tools::Query")
ABresult
0X0
100
111
35 28 $args{query} = $q;
36 }
37 else {
38 0 confess
39 "query param required to be a scalar string or Search::Tools::Query object";
40 }
41 53 $args{debug} = $debug; # restore so it can be passed on
42 #dump \%args;
43 53 return \%args;
44 }
45  
46 91 ▶sub queryparser_can {
Subroutine queryparser_can: called CC=2 SCAR=7.0
Pod documented
47 91 my $self = shift;
48 91 ▶ my $attr = shift or confess "attr required";
Branch: 1 branch
BranchTrueFalseTotal
my $attr = shift() or confess("attr required") 91 0 91
49 91 my $can = Search::Tools::QueryParser->can($attr);
50  
51 #warn
52 # sprintf( "QueryParser->can(%s)==%s\n", $attr, ( $can || '[undef]' ) );
53  
54 91 return $can;
55 }
56  
57 22 1;
58  
59 __END__
« blib/lib/Search/Tools/Transliterate.pm ↑ Summary blib/lib/Search/Tools.pm »