Articulate/Sortation/MetaDelver.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran n/a Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod 50.0% 1 / 2 totaltotal 78.8% 41 / 52 CC 5 SCAR 8.4
CC
5
Cov
87%
__ANON__
4.2
decorate
2.0
__ANON__
2.0
CRAP 2.3
« Articulate/Construction/LocationBased.pm ↑ Summary Articulate/Request.pm »
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"
l!l
02
MC/DC0%0/1
$orig->{"cmp"} //= "Articulate::Sortation::String"
$orig->{"cmp"}
Truth table50%1/2
A
A= $orig->{"cmp"}
Aresult
11
00
48 2 $orig->{cmp} = instantiate( $orig->{cmp} );
49 2 ▶ $orig->{field} //= '/';
Condition50%1/2
$orig->{"field"} //= "/"
l!l
20
MC/DC0%0/1
$orig->{"field"} //= "/"
$orig->{"field"}
Truth table50%1/2
A
A= $orig->{"field"}
Aresult
11
00
50 2 $orig->{field} =~ s~^([^/].*)$~/$1~;
51 2 ▶ $orig->{order} //= 'asc';
Condition50%1/2
$orig->{"order"} //= "asc"
l!l
02
MC/DC0%0/1
$orig->{"order"} //= "asc"
$orig->{"order"}
Truth table50%1/2
A
A= $orig->{"order"}
Aresult
11
00
52 2 return $orig;
53 },
54 2 );
55  
56 sub decorate {
57 16 ▶ my $self = shift;
Subroutine decorate: called CC=2 SCAR=7.1
Pod undocumented
58 16 my $item = shift;
59 16 ▶ return ( dpath_get( $item->meta, $self->options->{field} ) // '' );
Condition50%1/2
dpath_get($item->meta, $self->options->{"field"}) // ""
l!l
160
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"})
Aresult
11
00
60 }
61  
62 sub cmp {
63 10 ▶ my $self = shift;
Subroutine cmp: called CC=1 SCAR=0.0
Pod documented
64 10 my $left = shift;
65 10 my $right = shift;
66 10 $self->options->{cmp}->cmp( $left, $right );
67 }
68  
69 2 1;
« Articulate/Construction/LocationBased.pm ↑ Summary Articulate/Request.pm »