Abstract/Driver/ArrayOfHashes.pm

filter: Statementstmt 86.7% 59 / 68 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 65.3% 17 / 26 Podpod 0.0% 0 / 3 totaltotal 76.4% 81 / 106 CC 7 SCAR 6.4
CC
7
Cov
84%
convert_sort
4.1
__ANON__
3.0
__ANON__
2.0
CRAP 1.9
« Abstract/Driver/SQL.pm ↑ Summary Abstract/Driver/Base.pm »
1 package Query::Abstract::Driver::ArrayOfHashes;
2  
3 1 our $VERSION = '0.01';
4  
5 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use base 'Query::Abstract::Driver::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 my %TESTERS = (
14 15 ▶ 'eq' => sub { lc($_[0]) eq lc($_[1]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 0 ▶ 'ne' => sub { lc($_[0]) ne lc($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 0 ▶ 'lt' => sub { lc($_[0]) lt lc($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 ▶ 'le' => sub { lc($_[0]) le lc($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 ▶ 'gt' => sub { lc($_[0]) gt lc($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 0 ▶ 'ge' => sub { lc($_[0]) ge lc($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 5 ▶ '<' => sub { $_[0] < $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 0 ▶ '>' => sub { $_[0] > $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ '<=' => sub { $_[0] <= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 ▶ '>=' => sub { $_[0] >= $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 5 ▶ 'in' => sub { scalar( grep { lc($_[0]) eq lc($_)} @{$_[1]} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 5 ▶ 'like' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 5 my ($value, $pattern) = @_;
27 5 $pattern = join( '%', map { quotemeta($_) } split('\%', $pattern, -1 ) );
28 5 $pattern =~ s/\%/.*/;
29 5 return $value =~ m/^$pattern$/i;
30 },
31  
32 1 );
33  
34 4 ▶sub convert_query {
Subroutine convert_query: called CC=1 SCAR=0.0
Pod undocumented
35 4 my ($self, %query) = @_;
36  
37 4 my $tester_sub = $self->convert_filter( $query{where} );
38 4 my $sort_sub = $self->convert_sort( $query{sort_by} );
39  
40 4 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 4 my $array = shift;
42 4 return [ sort $sort_sub grep {$tester_sub->($_)} @$array];
43 }
44 4 }
45  
46  
47 4 ▶sub convert_filter {
Subroutine convert_filter: called CC=2 SCAR=6.9
Pod undocumented
48 4 my ( $self, $where ) = @_;
49  
50 4 my @field_testers;
51 4 ▶ for ( my $i = 0; $i < @$where; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$where) 6 4 10
52 6 my $field = $where->[$i];
53 6 my $condition = $where->[$i+1];
54 6 my ($oper, $restriction) = %$condition;
55  
56 30 ▶ push @field_testers, sub { $TESTERS{$oper}->( $_[0]->{$field}, $restriction ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
57 6 }
58  
59 20 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 20 my $hash = shift;
61 20 @field_testers == grep { $_->($hash) } @field_testers
62 4 };
63 }
64  
65 4 ▶sub convert_sort {
Subroutine convert_sort: called CC=4 SCAR=14.2
Pod undocumented
66 4 my ( $self, $sort_by ) = @_;
67 4 my @comparators;
68 4 foreach my $sort_rule ( @$sort_by ) {
69 1 my ($field, $order) = split(/\s+/, $sort_rule, 2);
70 1 ▶ $order ||='ASC';
Condition50%1/2
$order ||= "ASC"
l!l
10
MC/DC0%0/1
$order ||= "ASC"
$order
Truth table50%1/2
A
A= $order
Aresult
11
00
71  
72 my $field_comparator = uc($order) eq 'DESC'
73 1 ▶ ? sub { $_[1]->{$field} cmp $_[0]->{$field} }
Subroutine __ANON__: called CC=1 SCAR=0.0
74 0 ▶ : sub { $_[0]->{$field} cmp $_[1]->{$field} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
uc $order eq 'DESC' ? : 1 0 1
75  
76 1 push @comparators, $field_comparator;
77 }
78  
79 2 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
80 2 foreach my $compar (@comparators) {
81 1 my $res = $compar->($a, $b);
82 1 ▶ return $res if $res != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $res != 0 1 0 1
83 }
84 1 return 0;
85 }
86 4 }
87  
88 1 1;
« Abstract/Driver/SQL.pm ↑ Summary Abstract/Driver/Base.pm »