| 1 | package Template::Plugin::SortNatural; | ||
| 2 | |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use base qw( Template::Plugin::VMethods ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Sort::Naturally; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | our $VERSION = '0.001'; | ||
| 10 | |||
| 11 | our @LIST_OPS = qw( sortn ); | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | Template::Plugin::SortNatural - Sort lists natural with Sort::Naturally | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | [% USE SortNatural; | ||
| 20 | foo.nsort; | ||
| 21 | %] | ||
| 22 | |||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | sort lexically, but sort numeral parts numerically | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | =head2 sortn( ) | ||
| 31 | |||
| 32 | Returns a new sorted arrayref. | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | sub sortn { | ||
| 37 | my $list = shift; | ||
| 38 | if ( ref $list eq 'ARRAY' ) { | ||
| 39 | return nsort(@{$list}); | ||
| 40 | } else { | ||
| 41 | croak "sort_by only works with ARRAY references"; | ||
| 42 | } | ||
| 43 | |||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | |||
| 48 | __END__ | ||