| 1 | ## no critic: Modules::ProhibitAutomaticExportation | ||||||||||
| 2 | |||||||||||
| 3 | package Test::Sort::Sub; | ||||||||||
| 4 | |||||||||||
| 5 | 16 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 16 | ▶ | use strict 'subs', 'vars'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 16 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 16 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 16 | ▶ | use Sort::Sub (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 16 | ▶ | use Test::More 0.98; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 16 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 14 | 16 | our $DATE = '2024-07-17'; # DATE | |||||||||
| 15 | 16 | our $DIST = 'Sort-Sub'; # DIST | |||||||||
| 16 | 16 | our $VERSION = '0.121'; # VERSION | |||||||||
| 17 | |||||||||||
| 18 | 16 | our @EXPORT = qw(sort_sub_ok); | |||||||||
| 19 | |||||||||||
| 20 | 39 | ▶ | sub _sort { | ||||||||
|
Subroutine
_sort: called CC=4 SCAR=13.9
| |||||||||||
| 21 | 39 | my ($args, $extras, $output_name) = @_; | |||||||||
| 22 | |||||||||||
| 23 | 39 | my $subname = $args->{subname}; | |||||||||
| 24 | 39 | ▶ | Sort::Sub->import("$subname$extras", ($args->{args} ? $args->{args} : ())); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 39 | my $res; | |||||||||
| 26 | 39 | ▶ | if ($args->{compares_record}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 24 | $res = [map {$_->[0]} sort {&{$subname}($a,$b)} | |||||||||
| 28 | 6 | (map { [$args->{input}[$_], $_] } 0..$#{ $args->{input} })]; | |||||||||
| 29 | } else { | ||||||||||
| 30 | 33 | $res = [sort {&{$subname}($a,$b)} @{ $args->{input} }]; | |||||||||
| 31 | } | ||||||||||
| 32 | 39 | ▶ | is_deeply($args->{$output_name}, $res) or diag explain $res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 16 | ▶ | sub sort_sub_ok { | ||||||||
|
Subroutine
sort_sub_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 16 | my %args = @_; | |||||||||
| 37 | |||||||||||
| 38 | 16 | my $subname = $args{subname}; | |||||||||
| 39 | 16 | ▶ | subtest "sort_sub_ok $subname" => sub { | ||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||
| 40 | 16 | my $res; | |||||||||
| 41 | |||||||||||
| 42 | 16 | ▶ | if ($args{output}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 15 | _sort(\%args, '', 'output'); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 16 | ▶ | if ($args{output_i}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 10 | _sort(\%args, '<i>', 'output_i'); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 16 | ▶ | if ($args{output_r}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 2 | _sort(\%args, '<r>', 'output_r'); | |||||||||
| 52 | }; | ||||||||||
| 53 | |||||||||||
| 54 | 16 | ▶ | if ($args{output_ir}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 12 | _sort(\%args, '<ir>', 'output_ir'); | |||||||||
| 56 | }; | ||||||||||
| 57 | 16 | }; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 16 | 1; | |||||||||
| 61 | # ABSTRACT: Test Sort::Sub::* subroutine | ||||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||