line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Sortation; |
2
|
1
|
|
|
1
|
|
5076
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
353
|
use Articulate::Syntax qw(instantiate_array); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
167
|
use Exporter::Declare; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
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
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head3 sort |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Passes the item and request objects to a series of Sortation objects, and returns the item after each has done their bit. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub sort { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my $items = shift; |
65
|
0
|
|
|
|
|
|
foreach my $sortation ( @{ $self->sortations } ) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$items = $sortation->sort($items); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
return $items; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |