File Coverage

blib/lib/Articulate/Sortation.pm
Criterion Covered Total %
statement 15 22 68.1
branch 0 2 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 33 66.6


line stmt bran cond sub pod time code
1             package Articulate::Sortation;
2 1     1   9143 use strict;
  1         2  
  1         55  
3 1     1   8 use warnings;
  1         2  
  1         45  
4              
5 1     1   8 use Moo;
  1         2  
  1         9  
6 1     1   453 use Articulate::Syntax qw(instantiate_array);
  1         3  
  1         18  
7              
8 1     1   316 use Exporter::Declare;
  1         3  
  1         8  
9             default_exports qw(sortation);
10              
11             =head1 NAME
12              
13             Articulate::Sortation - Sort content items
14              
15             =head1 DESCRIPTION
16              
17             use Articulate::Sortation;
18             $request = sortation->sort( [ $item1, $item2 ], {} );
19              
20             This accepts an array of items. pass the item and the request to a series of Sortation objects.
21              
22             Sortations should not mutate the items, however there is no technical barrier to them doing so.
23              
24             =head1 CONFIGuRATION
25              
26             This can be set up to perform default sorts, however it's fully anticipated that you will need to configure sorts on a per-item basis (e.g. the user may request items with a different sort order).
27              
28             =head1 FUNCTION
29              
30             =head3 sortation
31              
32             This is a functional constructor: it returns an Articulate::Sortation object.
33              
34             =cut
35              
36             sub sortation {
37 0 0   0 1   return __PACKAGE__->new(@_) if @_;
38             };
39              
40             =head1 ATTRIBUTES
41              
42             =head3 sortations
43              
44             An array of the Sortation classes which will be used.
45              
46             =cut
47              
48             has sortations =>
49             is => 'rw',
50             default => sub { [] },
51             coerce => sub { instantiate_array(@_) };
52              
53             =head1 METHODS
54              
55             =head3 sort
56              
57             Passes the item and request objects to a series of Sortation objects, and returns the item after each has done their bit.
58              
59             =cut
60              
61             sub sort {
62 0     0 1   my $self = shift;
63 0           my $items = shift;
64 0           foreach my $sortation ( @{ $self->sortations } ) {
  0            
65 0           $items = $sortation->sort($items);
66             }
67 0           return $items;
68             }
69              
70             1;