| 1 | package Articulate::Sortation; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Articulate::Syntax qw(instantiate_array); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Exporter::Declare; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | 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 | ▶ | return __PACKAGE__->new(@_) if @_; | ||||||||
|
Subroutine
sortation: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | ▶ | coerce => sub { instantiate_array(@_) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
sort: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 63 | 0 | my $items = shift; | |||||||||
| 64 | 0 | foreach my $sortation ( @{ $self->sortations } ) { | |||||||||
| 65 | 0 | $items = $sortation->sort($items); | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | return $items; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 1 | 1; | |||||||||