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   137 use strict;
  19         41  
  19         549  
4 19     19   91 use warnings;
  19         34  
  19         530  
5              
6 19     19   106 use List::Util qw(shuffle);
  19         36  
  19         2253  
7 19     19   10397 use Sort::Naturally qw(nsort);
  19         82058  
  19         6938  
8              
9             # CTOR
10             #
11             sub new
12             {
13 33     33 0 109 my $class = shift;
14 33   100     265 my $strategy = shift || 'none';
15              
16 33 50       363 die("Unknown order strategy: $strategy\n") unless $strategy =~ /^(?:none|(r?)(?:alphabetic|natural)|random)$/i;
17              
18 33 100       373 my $self = bless( { strategy => $strategy, reverse => ($1 ? 1 : 0) }, $class);
19            
20 33         218 return $self;
21             }
22              
23             # order a list according to the desired strategy
24             #
25             sub orderList
26             {
27 110     110 0 253 my $self = shift;
28 110         335 my @l = @_;
29              
30 110 100       387 if ($self->{strategy} ne 'none')
31             {
32 36 100       399 if ($self->{strategy} =~ /^r?alphabetic$/)
    50          
    0          
33             {
34 12         48 @l = sort(@l);
35 12 100       37 @l = reverse(@l) if $self->{reverse};
36             }
37             elsif ($self->{strategy} =~ /^(r?)natural$/)
38             {
39 24         1174 @l = nsort(@l);
40 24 100       1655 @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         364 return @l;
49             }
50              
51             sub getStrategyName
52             {
53 23     23 0 150 my $self = shift;
54            
55 23         1458 return $self->{strategy};
56             }
57              
58             1;