File Coverage

blib/lib/Acme/Rautavistic/Sort.pm
Criterion Covered Total %
statement 41 41 100.0
branch 4 4 100.0
condition n/a
subroutine 12 12 100.0
pod 2 2 100.0
total 59 59 100.0


line stmt bran cond sub pod time code
1             package Acme::Rautavistic::Sort;
2             BEGIN {
3 1     1   21545 $Acme::Rautavistic::Sort::AUTHORITY = 'cpan:SCHWIGON';
4             }
5             # ABSTRACT: Rautavistic sort functions
6              
7 1     1   8 use warnings;
  1         3  
  1         26  
8 1     1   5 use strict;
  1         2  
  1         19  
9 1     1   21 use 5.006;
  1         3  
10              
11             our $VERSION = '0.02';
12              
13 1     1   5 use Scalar::Util 'reftype';
  1         1  
  1         102  
14             require Exporter;
15              
16 1     1   6 use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
  1         2  
  1         94  
17              
18             @ISA = qw(Exporter);
19              
20             @EXPORT_OK = qw(dropsort dropsortx);
21             %EXPORT_TAGS = (all => [ qw(dropsort dropsortx) ]);
22              
23             sub dropsort {
24 1     1   4 no warnings 'uninitialized';
  1         2  
  1         94  
25 25     25 1 816 my $last;
26 25 100       49 map { $_ ge $last ? $last = $_ : () } @_;
  96         436  
27             }
28              
29             sub dropsortx(&@)
30             {
31             # magic variables $a and $b
32 1     1   5 use vars qw($a $b);
  1         3  
  1         35  
33 1     1   5 no strict 'refs';
  1         1  
  1         30  
34 1     1   4 no warnings 'uninitialized';
  1         2  
  1         158  
35 2     2 1 747 my $caller = caller;
36 2         3 local(*{$caller."::a"}) = \my $a;
  2         11  
37 2         4 local(*{$caller."::b"}) = \my $b;
  2         7  
38              
39 2         4 my $comparator = shift;
40 2         4 my $last;
41             map {
42 2         6 $a = $_;
  6         27  
43 6         8 $b = $last;
44 6 100       18 $comparator->() >= 0 ? $last = $_ : ()
45             } @_;
46             }
47              
48             1; # End of Acme::Rautavistic::Sort
49              
50             # TODOs / Ideas:
51             # Attribute : Rautavistic(dropsort)
52             # an Arrays, always keep dropsort sort order, after each change on array
53              
54             __END__