blib/lib/Clustericious/RouteBuilder/Search.pm

filter: Statementstmt 31.1% 14 / 45 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 16.2% 18 / 111 CC 21 SCAR 54.8
CC
21
Cov
15%
__ANON__
342.0
_build_search
20.0
BEGIN
1.0
CRAP 240.0
« blib/lib/Clustericious/Client/Command.pm ↑ Summary blib/lib/Clustericious/Command/status.pm »
1 package Clustericious::RouteBuilder::Search;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Clustericious::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: build routes for searching for objects
8 1 our $VERSION = '1.29'; # VERSION
9  
10  
11 1 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 exports => [
13 "search" => \&_build_search,
14 ],
15 collectors => ['defaults'],
16 1 };
17  
18 0 ▶sub _build_search {
Subroutine _build_search: not called CC=4 SCAR=30.0
19 0 my ($class, $name, $arg, $defaults) = @_;
20 0 ▶ my $finder = $arg->{finder} || $defaults->{defaults}{finder} || die "no finder defined";
Condition0%0/5
$arg->{'finder'} || $defaults->{'defaults'}{'finder'} || die('no finder defined')
l!l
00
$arg->{"finder"} or $defaults->{"defaults"}{"finder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg->{'finder'} || $defaults->{'defaults'}{'finder'} || die('no finder defined')
$arg->{"finder"} $defaults->{"defaults"}{"finder"}
Truth table0%0/3
A or B
A= $arg->{"finder"}B= $defaults->{"defaults"}{"finder"}
ABresult
1X1
011
000
21 0 ▶ $finder->can("find_class") or die "$finder must be able to find_class";
Branch: 1 branch
BranchTrueFalseTotal
$finder->can("find_class") or die "$finder must be able to find_class" 0 0 0
22 0 ▶ sub {
Subroutine __ANON__: not called CC=18 SCAR=58.3
23 0 my $self = shift;
24  
25 0 ▶ my $items = $self->stash("items") or LOGDIE "no items in request";
Branch: 1 branch
BranchTrueFalseTotal
my $items = $self->stash("items") or LOGDIE("no items in request") 0 0 0
26  
27 0 ▶ my $manager = $finder->find_class($items) or LOGDIE "no class for $items";
Branch: 1 branch
BranchTrueFalseTotal
my $manager = $finder->find_class($items) or LOGDIE("no class for $items") 0 0 0
28 0 ▶ unless ($manager->can("object_class")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($manager->can("object_class")) 0 0 0
29 # Allow tables names in addition to plurals
30 0 $manager .= "::Manager";
31 }
32 0 $self->parse_autodata;
33  
34 0 my $p = $self->stash->{autodata};
35  
36 0 ▶ if (my $mode = $p->{mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mode = $p->{"mode"}) 0 0 0
37 0 DEBUG "Called search mode $mode";
38 # A search "mode" indicates that we use a pre-canned
39 # query stored in the manager class. This query is
40 # run by calling a method named "search_$mode" on the
41 # manager class. This method should return a count
42 # and a resultset (array ref of hashrefs).
43 0 my $method = "search_$mode";
44 0 my $got = $manager->$method($p);
45 ERROR "search_$mode did not return count/resultset"
46 0 ▶ unless ref($got) eq 'HASH' && exists($got->{count}) && exists($got->{resultset});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $got eq "HASH" and exists $got->{"count"} and exists $got->{"resultset"} 0 0 0
Condition0%0/6
ref $got eq "HASH" and exists $got->{"count"} and exists $got->{"resultset"}
!ll&&!rl&&r
000
ref $got eq "HASH" and exists $got->{"count"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $got eq "HASH" and exists $got->{"count"} and exists $got->{"resultset"}
ref $got eq "HASH" exists $got->{"count"} exists $got->{"resultset"}
Truth table0%0/4
A and B and C
A= ref $got eq "HASH"B= exists $got->{"count"}C= exists $got->{"resultset"}
ABCresult
0XX0
10X0
1100
1111
47 0 $self->stash(autodata => $got);
48 0 return;
49 }
50  
51  
52 #TRACE "searching for $items : ".Dumper($p);
53  
54 # maybe restrict, by first calling $manager->normalize_get_objects_args(%$p)
55  
56 0 my $all = delete $p->{query_all};
57 # "If the first argument is a hash it is treated as 'query'" -- RDBOM docs
58 0 ▶ my @args = $all || exists( $p->{query} ) ? %$p
Branch: 2 branches
BranchTrueFalseTotal
$all || exists $p->{'query'} ? : 0 0 0
keys %$p > 0 ? : 0 0 0
Condition0%0/3
$all or exists $p->{"query"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$all or exists $p->{"query"}
$all exists $p->{"query"}
Truth table0%0/3
A or B
A= $allB= exists $p->{"query"}
ABresult
1X1
011
000
59 : ( keys %$p > 0 ) ? $p
60 : ();
61 0 TRACE "args are @args";
62 0 push @args, object_class => $manager->object_class;
63 0 my %a = @args;
64 0 ▶ if (!$a{limit} && !$a{page}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $a{'limit'} || $a{'page'}) { } 0 0 0
elsif (($a{'limit'} || $a{'per_page'} || 0) > 1000) { } 0 0 0
Condition0%0/3
$a{'limit'} || $a{'page'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$a{'limit'} || $a{'page'}
$a{'limit'} $a{'page'}
Truth table0%0/3
A || B
A= $a{'limit'}B= $a{'page'}
ABresult
1X1
011
000
65 0 DEBUG "Adding limit 100 to query";
66 0 push @args, ( limit => 100 );
67 ▶ } elsif ( ($a{limit} || $a{per_page} || 0) > 1000) {
Condition0%0/5
$a{'limit'} || $a{'per_page'} || 0
l!l
00
$a{"limit"} or $a{"per_page"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$a{'limit'} || $a{'per_page'} || 0
$a{"limit"} $a{"per_page"}
Truth table0%0/3
A or B
A= $a{"limit"}B= $a{"per_page"}
ABresult
1X1
011
000
68 0 ▶ WARN "Very large limit : ".($a{limit} || $a{per_page});
Condition0%0/3
$a{'limit'} || $a{'per_page'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$a{'limit'} || $a{'per_page'}
$a{'limit'} $a{'per_page'}
Truth table0%0/3
A || B
A= $a{'limit'}B= $a{'per_page'}
ABresult
1X1
011
000
69 }
70  
71 0 my $count = $manager->get_objects_count( @args );
72 0 my @key = $manager->object_class->meta->primary_key_column_names;
73 $self->stash(autodata => {
74 count => $count,
75 key => (@key > 1 ? \@key : $key[0]),
76 0 ▶ resultset => [ map $_->as_hash, @{ $manager->get_objects( @args ) } ]
Branch: 1 branch
BranchTrueFalseTotal
@key > 1 ? : 0 0 0
77 });
78 0 };
79 }
80  
81 1 1;
82  
83 __END__
« blib/lib/Clustericious/Client/Command.pm ↑ Summary blib/lib/Clustericious/Command/status.pm »