| 1 | package Catmandu::Fix::sort_field; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '1.2025'; | |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use List::SomeUtils qw(uniq); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Catmandu::Util::Path qw(as_path); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Catmandu::Fix::Has; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 1 | with 'Catmandu::Fix::Builder'; | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | has path => (fix_arg => 1); | |||||||||||||||||||||||||||||||||||
| 16 | 1 | has uniq => (fix_opt => 1); | |||||||||||||||||||||||||||||||||||
| 17 | 1 | has reverse => (fix_opt => 1); | |||||||||||||||||||||||||||||||||||
| 18 | 1 | has numeric => (fix_opt => 1); | |||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | has undef_position => (fix_opt => 1, default => sub {'last'}); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 12 | ▶ | sub _build_fixer { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_build_fixer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 23 | 12 | my $uniq = $self->uniq; | |||||||||||||||||||||||||||||||||||
| 24 | 12 | my $reverse = $self->reverse; | |||||||||||||||||||||||||||||||||||
| 25 | 12 | my $numeric = $self->numeric; | |||||||||||||||||||||||||||||||||||
| 26 | 12 | my $undef_position = $self->undef_position; | |||||||||||||||||||||||||||||||||||
| 27 | as_path($self->path)->updater( | ||||||||||||||||||||||||||||||||||||
| 28 | 12 | ▶ | if_array_ref => sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||
| 29 | 12 | my $val = $_[0]; | |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | #filter out undef | ||||||||||||||||||||||||||||||||||||
| 32 | 12 | my $undefs = [grep {!defined($_)} @$val]; | |||||||||||||||||||||||||||||||||||
| 33 | 12 | $val = [grep {defined($_)} @$val]; | |||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||
| 35 | #uniq | ||||||||||||||||||||||||||||||||||||
| 36 | 12 | ▶ | if ($uniq) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 37 | 6 | $val = [uniq(@$val)]; | |||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | #sort | ||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | if ($reverse && $numeric) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$reverse and $numeric
MC/DC0%0/2
$reverse and $numeric
$reverse
$numeric
Truth table66%2/3
A and B
A= $reverseB= $numeric
| |||||||||||||||||||||||||||||||||||||
| 42 | 0 | $val = [sort {$b <=> $a} @$val]; | |||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | elsif ($numeric) { | ||||||||||||||||||||||||||||||||||||
| 45 | 1 | $val = [sort {$a <=> $b} @$val]; | |||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||
| 47 | elsif ($reverse) { | ||||||||||||||||||||||||||||||||||||
| 48 | 1 | $val = [sort {$b cmp $a} @$val]; | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||
| 51 | 10 | $val = [sort {$a cmp $b} @$val]; | |||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | #insert undef at the end | ||||||||||||||||||||||||||||||||||||
| 55 | 12 | ▶ | if ($undef_position eq 'first') { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | if ($uniq) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | unshift @$val, undef if @$undefs; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||
| 60 | 1 | unshift @$val, @$undefs; | |||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||
| 63 | elsif ($undef_position eq 'last') { | ||||||||||||||||||||||||||||||||||||
| 64 | 8 | ▶ | if ($uniq) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | push @$val, undef if @$undefs; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||
| 68 | 4 | push @$val, @$undefs; | |||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | 12 | $val; | |||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||
| 74 | 12 | ); | |||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||