blib/lib/DTL/Fast/Filter/Dictsort.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 62.5% 5 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 88.5% 54 / 61 SCAR 18.0
CC
6
Cov
91%
sort_function
4.0
filter
2.0
parse_parameters
2.0
CRAP 6.0
« blib/lib/DTL/Fast/Tag.pm ↑ Summary blib/lib/DTL/Fast/Cache/Memcached.pm »
1 package DTL::Fast::Filter::Dictsort;
2 3 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use parent 'DTL::Fast::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 $DTL::Fast::FILTER_HANDLERS{'dictsort'} = __PACKAGE__;
6  
7 3 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #@Override
11 sub parse_parameters
12 {
13 4 ▶ my $self = shift;
Subroutine parse_parameters: called CC=2 SCAR=7.0
Pod undocumented
14 die $self->get_parse_error("no sorting key specified")
15 4 ▶ if not scalar @{$self->{'parameter'}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"parameter"};} 0 4 4
16 4 $self->{'key'} = [split /\./, $self->{'parameter'}->[0]->render()]; # do we need to backup strings here ?
17 4 return $self;
18 }
19  
20 #@Override
21 sub filter
22 {
23 4 ▶ my ($self, $filter_manager, $value, $context) = @_;
Subroutine filter: called CC=2 SCAR=7.0
Pod undocumented
24  
25 4 ▶ die $self->get_render_error("dictsort works only with array of hashes")
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "ARRAY" 0 4 4
26 if ref $value ne 'ARRAY';
27  
28 return [(
29 sort{
30 4 $self->sort_function(
31 $context->traverse($a, $self->{'key'}, $self)
32 10 , $context->traverse($b, $self->{'key'}, $self)
33 )
34 } @$value
35 )];
36 }
37  
38 sub sort_function
39 {
40 10 ▶ my ($self, $val1, $val2) = @_;
Subroutine sort_function: called CC=4 SCAR=14.0
Pod undocumented
41 10 my $result;
42  
43 10 ▶ if( looks_like_number($val1) and looks_like_number($val2))
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($val1) and &looks_like_number($val2)) { } 5 5 10
elsif (UNIVERSAL::can($val1, 'compare')) { } 0 5 5
Condition100%3/3
&looks_like_number($val1) and &looks_like_number($val2)
!ll&&!rl&&r
325
MC/DC100%2/2
&looks_like_number($val1) and &looks_like_number($val2)
&looks_like_number($val1) &looks_like_number($val2)
Truth table100%3/3
A and B
A= &looks_like_number($val1)B= &looks_like_number($val2)
ABresult
0X0
100
111
44 {
45 5 $result = ($val1 <=> $val2);
46 }
47 elsif( UNIVERSAL::can($val1, 'compare'))
48 {
49 0 $result = $val1->compare($val2);
50 }
51 else
52 {
53 5 $result = ($val1 cmp $val2);
54 }
55  
56 10 return $result;
57 }
58  
59 3 1;
« blib/lib/DTL/Fast/Tag.pm ↑ Summary blib/lib/DTL/Fast/Cache/Memcached.pm »