package Articulate::Sortation::MetaDelver; use strict; use warnings; use Moo; with 'Articulate::Role::Sortation::AllYouNeedIsCmp'; use Articulate::Syntax qw(instantiate dpath_get); =head1 NAME Articulate::Sortation::MetaDelver - delve into the metadata and sort it =head1 ATTRIBUTES =head3 options A hashref defining what information to get and how to sort it. =over =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.. =item * C - The type of comparison to apply - any class which provides a C method can be entered here. Defaults to C. =item * C - The direction in which to sort: C or C, defaults to C. =back =head1 METHODS =head3 sort Provided by L. =head3 schwartz Provided by L. =cut has options => ( is => 'rw', default => sub { {} }, coerce => sub { my $orig = shift; $orig->{cmp} //= 'Articulate::Sortation::String'; $orig->{cmp} = instantiate( $orig->{cmp} ); $orig->{field} //= '/'; $orig->{field} =~ s~^([^/].*)$~/$1~; $orig->{order} //= 'asc'; return $orig; }, ); sub decorate { my $self = shift; my $item = shift; return ( dpath_get( $item->meta, $self->options->{field} ) // '' ); } sub cmp { my $self = shift; my $left = shift; my $right = shift; $self->options->{cmp}->cmp( $left, $right ); } 1;