File Coverage

blib/lib/App/TestOnTap/OrderStrategy.pm
Criterion Covered Total %
statement 28 29 96.5
branch 12 16 75.0
condition 2 2 100.0
subroutine 7 7 100.0
pod 0 3 0.0
total 49 57 85.9


line stmt bran cond sub pod time code
1             package App::TestOnTap::OrderStrategy;
2              
3 19     19   130 use strict;
  19         39  
  19         553  
4 19     19   97 use warnings;
  19         30  
  19         533  
5              
6 19     19   107 use List::Util qw(shuffle);
  19         45  
  19         2344  
7 19     19   10358 use Sort::Naturally qw(nsort);
  19         82815  
  19         6873  
8              
9             # CTOR
10             #
11             sub new
12             {
13 33     33 0 111 my $class = shift;
14 33   100     294 my $strategy = shift || 'none';
15              
16 33 50       364 die("Unknown order strategy: $strategy\n") unless $strategy =~ /^(?:none|(r?)(?:alphabetic|natural)|random)$/i;
17              
18 33 100       384 my $self = bless( { strategy => $strategy, reverse => ($1 ? 1 : 0) }, $class);
19            
20 33         242 return $self;
21             }
22              
23             # order a list according to the desired strategy
24             #
25             sub orderList
26             {
27 110     110 0 275 my $self = shift;
28 110         15076 my @l = @_;
29              
30 110 100       428 if ($self->{strategy} ne 'none')
31             {
32 36 100       433 if ($self->{strategy} =~ /^r?alphabetic$/)
    50          
    0          
33             {
34 12         73 @l = sort(@l);
35 12 100       50 @l = reverse(@l) if $self->{reverse};
36             }
37             elsif ($self->{strategy} =~ /^(r?)natural$/)
38             {
39 24         1728 @l = nsort(@l);
40 24 100       1643 @l = reverse(@l) if $self->{reverse};
41             }
42             elsif ($self->{strategy} eq 'random')
43             {
44 0         0 @l = shuffle(@l);
45             }
46             }
47              
48 110         376 return @l;
49             }
50              
51             sub getStrategyName
52             {
53 23     23 0 145 my $self = shift;
54            
55 23         1287 return $self->{strategy};
56             }
57              
58             1;