| 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
| |||||||||||||||||||||
| 15 | 0 | confess "query required"; | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | 53 | ▶ | if ( !ref($q) ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||