File Coverage

blib/lib/Articulate/Sortation/MetaDelver.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition 1 2 50.0
subroutine 6 6 100.0
pod 1 2 50.0
total 27 29 93.1


line stmt bran cond sub pod time code
1             package Articulate::Sortation::MetaDelver;
2 2     2   647 use strict;
  2         4  
  2         77  
3 2     2   9 use warnings;
  2         3  
  2         60  
4              
5 2     2   9 use Moo;
  2         3  
  2         11  
6             with 'Articulate::Role::Sortation::AllYouNeedIsCmp';
7              
8 2     2   1210 use Articulate::Syntax qw(instantiate dpath_get);
  2         6  
  2         9  
9              
10             =head1 NAME
11              
12             Articulate::Sortation::MetaDelver - delve into the metadata and sort it
13              
14             =head1 ATTRIBUTES
15              
16             =head3 options
17              
18             A hashref defining what information to get and how to sort it.
19              
20             =over
21              
22             =item * C: . This field is mandatory. A C expression used to find the right field from the meta, e.g. 'schema/core/dateUpdated' Not that a '/' will be prepended if it does not already exist..
23              
24             =item * C - The type of comparison to apply - any class which provides a C method can be entered here. Defaults to C.
25              
26             =item * C - The direction in which to sort: C or C, defaults to C.
27              
28             =back
29              
30             =head1 METHODS
31              
32             =head3 sort
33              
34             Provided by L.
35              
36             =head3 schwartz
37              
38             Provided by L.
39              
40             =cut
41              
42             has options => (
43             is => 'rw',
44             default => sub { {} },
45             coerce => sub {
46             my $orig = shift;
47             $orig->{cmp} //= 'Articulate::Sortation::String';
48             $orig->{cmp} = instantiate( $orig->{cmp} );
49             $orig->{field} //= '/';
50             $orig->{field} =~ s~^([^/].*)$~/$1~;
51             $orig->{order} //= 'asc';
52             return $orig;
53             },
54             );
55              
56             sub decorate {
57 16     16 0 16 my $self = shift;
58 16         13 my $item = shift;
59 16   50     309 return ( dpath_get( $item->meta, $self->options->{field} ) // '' );
60             }
61              
62             sub cmp {
63 10     10 1 10 my $self = shift;
64 10         10 my $left = shift;
65 10         9 my $right = shift;
66 10         195 $self->options->{cmp}->cmp( $left, $right );
67             }
68              
69             1;