Smooth/ResultSetBase.pm

filter: Statementstmt 47.0% 32 / 68 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 10 / 15 Podpod 0.0% 0 / 3 totaltotal 36.2% 42 / 116 CC 15 SCAR 44.2
CC
15
Cov
34%
_smooth__prepare_for_filter
182.0
annotate
12.0
__ANON__
2.0
CRAP 83.4
« Smooth/ResultBase.pm ↑ Summary Smooth/Lookup/Util.pm »
1 23 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DBIx::Class::Smooth::ResultSetBase;
6  
7 # ABSTRACT: Short intro
8 23 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 23 our $VERSION = '0.0108';
10  
11 23 ▶use parent 'DBIx::Class::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 23 ▶use List::SomeUtils qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 23 ▶use Safe::Isa qw/$_isa/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 23 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 23 ▶use DBIx::Class::Smooth::Q;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 23 ▶use DBIx::Class::Smooth::FilterItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 23 ▶use experimental qw/signatures postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub _smooth__prepare_for_filter($self, @args) {
Subroutine _smooth__prepare_for_filter: not called CC=13 SCAR=52.0
20 0 my @qobjs = grep { $_->$_isa('DBIx::Class::Smooth::Q') } @args;
21 0 ▶ if(scalar @qobjs) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @qobjs) 0 0 0
22 0 ▶ if(scalar @args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 1) { } 0 0 0
23 0 die "Don't mix Q() and normal args";
24 }
25 else {
26 0 @args = $args[0]->value->@*;
27 }
28 }
29  
30 0 my $i = undef;
31 0 my $prepared_args = [];
32  
33 ARG:
34 0 for my $fori (0..scalar @args - 1) {
35 # We do it this way since not all search args are key => value pairs (such as \[] searches)
36 # meaning that sometimes we need to $i += 1 and sometimes $i += 2
37 0 ▶ $i = $fori if !defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 0 0
38  
39 0 my $possible_key = $args[$i];
40 0 ▶ my $possible_value = $i + 1 <= scalar @args - 1 ? $args[$i + 1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$i + 1 <= scalar @args - 1 ? : 0 0 0
41  
42 # Dig deeper into the search structure
43 0 ▶ if($possible_value && any { $possible_key eq $_ } (qw/-and -or -not_bool/)) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_value and &any(sub { $possible_key eq $_; } , '-and', '-or', '-not_bool')) { } 0 0 0
Condition0%0/3
$possible_value and &any(sub { $possible_key eq $_; } , "-and", "-or", "-not_bool")
!ll&&!rl&&r
000
MC/DC0%0/2
$possible_value and &any(sub { $possible_key eq $_; } , "-and", "-or", "-not_bool")
$possible_value &any(sub { $possible_key eq $_; } , "-and", "-or", "-not_bool")
Truth table0%0/3
A and B
A= $possible_valueB= &any(sub { $possible_key eq $_; } , "-and", "-or", "-not_bool")
ABresult
0X0
100
111
44 0 ▶ if(ref $possible_value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $possible_value eq "ARRAY") 0 0 0
45 0 push $prepared_args->@* => ($possible_key => $self->_smooth__prepare_for_filter($possible_value->@*));
46 0 $i += 2;
47 }
48 }
49 else {
50 # There is no $possible_value for \[] searches, the value is already in the arrayrefref
51 0 ▶ if(ref $possible_key eq 'REF') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $possible_key eq 'REF') { } 0 0 0
elsif (defined $possible_key and defined $possible_value) { } 0 0 0
52 0 push $prepared_args->@* => $possible_key;
53 0 $i++;
54 }
55 ▶ elsif(defined $possible_key && defined $possible_value) {
Condition0%0/3
defined $possible_key and defined $possible_value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $possible_key and defined $possible_value
defined $possible_key defined $possible_value
Truth table0%0/3
A and B
A= defined $possible_keyB= defined $possible_value
ABresult
0X0
100
111
56  
57 0 my @key_parts = split /__/ => $possible_key;
58  
59 0 my $item = DBIx::Class::Smooth::FilterItem->new(resultset => $self, parts => \@key_parts, value => $possible_value);
60 0 ($possible_key, $possible_value) = $item->parse;
61  
62 0 ▶ if($possible_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_key) { } 0 0 0
63 0 push $prepared_args->@* => ($possible_key, $possible_value);
64 }
65 else {
66 0 push $prepared_args->@* => $possible_value;
67 }
68 0 $i += 2;
69 }
70 }
71 }
72 0 return $prepared_args;
73 }
74  
75 0 ▶sub filter($self, @args) {
Subroutine filter: not called CC=1 SCAR=6.9
Pod undocumented
76 # only compatible with array and Q
77 0 my $args = $self->_smooth__prepare_for_filter(-and => \@args);
78 0 return $self->search($args);
79 }
80  
81 0 ▶sub filterattr($self, %args) {
Subroutine filterattr: not called CC=1 SCAR=6.9
Pod undocumented
82 0 return $self->search({}, \%args);
83 }
84  
85 # $rs->annotate(point_x => X('location'));
86 0 ▶sub annotate($self, $getter_name, $function_structure, $as = undef) {
Subroutine annotate: not called CC=3 SCAR=24.8
Pod undocumented
87 0 ▶ if ($as) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as) 0 0 0
88 0 $function_structure->{'-as'} = $as;
89 }
90 0 my $structure = {
91 '+select' => [$function_structure],
92 '+as' => [$getter_name],
93 };
94 0 return $self->search({}, $structure);
95 }
96  
97 23 1;
98  
99 __END__
« Smooth/ResultBase.pm ↑ Summary Smooth/Lookup/Util.pm »