| 1 | package Articulate::Sortation::MetaDelver; | ||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | with 'Articulate::Role::Sortation::AllYouNeedIsCmp'; | |||||||||||
| 7 | |||||||||||||
| 8 | 2 | ▶ | use Articulate::Syntax qw(instantiate dpath_get); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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<field>: . This field is mandatory. A C<Data::DPath> 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<cmp> - The type of comparison to apply - any class which provides a C<cmp> method can be entered here. Defaults to C<Articulate::Sortation::String>. | ||||||||||||
| 25 | |||||||||||||
| 26 | =item * C<order> - The direction in which to sort: C<asc> or C<desc>, defaults to C<asc>. | ||||||||||||
| 27 | |||||||||||||
| 28 | =back | ||||||||||||
| 29 | |||||||||||||
| 30 | =head1 METHODS | ||||||||||||
| 31 | |||||||||||||
| 32 | =head3 sort | ||||||||||||
| 33 | |||||||||||||
| 34 | Provided by L<Articulate::Role::Sortation::AllYouNeedIsCmp>. | ||||||||||||
| 35 | |||||||||||||
| 36 | =head3 schwartz | ||||||||||||
| 37 | |||||||||||||
| 38 | Provided by L<Articulate::Role::Sortation::AllYouNeedIsCmp>. | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | has options => ( | ||||||||||||
| 43 | is => 'rw', | ||||||||||||
| 44 | 0 | ▶ | default => sub { {} }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 45 | coerce => sub { | ||||||||||||
| 46 | 2 | ▶ | my $orig = shift; | ||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||
| 47 | 2 | ▶ | $orig->{cmp} //= 'Articulate::Sortation::String'; | ||||||||||
|
Condition50%1/2
$orig->{"cmp"} //= "Articulate::Sortation::String"
MC/DC0%0/1
$orig->{"cmp"} //= "Articulate::Sortation::String"
$orig->{"cmp"}
Truth table50%1/2
A
A= $orig->{"cmp"}
| |||||||||||||
| 48 | 2 | $orig->{cmp} = instantiate ( $orig->{cmp} ); | |||||||||||
| 49 | 2 | ▶ | $orig->{field} //= '/'; | ||||||||||
|
Condition50%1/2
$orig->{"field"} //= "/"
MC/DC0%0/1
$orig->{"field"} //= "/"
$orig->{"field"}
Truth table50%1/2
A
A= $orig->{"field"}
| |||||||||||||
| 50 | 2 | $orig->{field} =~ s~^([^/].*)$~/$1~; | |||||||||||
| 51 | 2 | ▶ | $orig->{order} //= 'asc'; | ||||||||||
|
Condition50%1/2
$orig->{"order"} //= "asc"
MC/DC0%0/1
$orig->{"order"} //= "asc"
$orig->{"order"}
Truth table50%1/2
A
A= $orig->{"order"}
| |||||||||||||
| 52 | 2 | return $orig; | |||||||||||
| 53 | }, | ||||||||||||
| 54 | 2 | ); | |||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | sub decorate { | ||||||||||||
| 58 | 16 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
decorate: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 59 | 16 | my $item = shift; | |||||||||||
| 60 | 16 | ▶ | return ( dpath_get( $item->meta, $self->options->{field} ) // '' ) | ||||||||||
|
Condition50%1/2
dpath_get($item->meta, $self->options->{"field"}) // ""
MC/DC0%0/1
dpath_get($item->meta, $self->options->{"field"}) // ""
dpath_get($item->meta, $self->options->{"field"})
Truth table50%1/2
A
A= dpath_get($item->meta, $self->options->{"field"})
| |||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | sub cmp { | ||||||||||||
| 64 | 10 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
cmp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 65 | 10 | my $left = shift; | |||||||||||
| 66 | 10 | my $right = shift; | |||||||||||
| 67 | 10 | $self->options->{cmp}->cmp( $left, $right ) | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 2 | 1; | |||||||||||