| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
&looks_like_number($val1) and &looks_like_number($val2)
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)
| |||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||