Articulate/Flow/LocationSwitch.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 76.3% 42 / 55 CC 7 SCAR 11.9
CC
7
Cov
77%
process_method
6.3
__ANON__
3.0
__ANON__
2.0
CRAP 3.3
« Articulate/Credentials.pm ↑ Summary Articulate/Routes/Login.pm »
1 package Articulate::Flow::LocationSwitch;
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 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 with 'Articulate::Role::Flow';
6 2 ▶use Articulate::Syntax qw (locspec instantiate instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Articulate::Flow::LocationSwitch - case switching for location
11  
12 =head1 CONFIGURATION
13  
14 - class: Articulate::Flow::LocationSwitch
15 args:
16 where:
17 '/assets/*/*/*':
18 - Enrich::Asset
19 otherwise:
20 - Enrich::Content
21  
22 =head1 DESCRIPTION
23  
24 This provides a convenient interface to a common branching pattern. When performing actions like C<enrich> and C<augment>, a developer will typically want to make some processes dependant on the location of the content being stored.
25  
26 Rather than having to write a 'black box' provider every time, this class provides a standard way of doing it.
27  
28 =head1 METHODS
29  
30 =head3 enrich
31  
32 $self->enrich( $item, $request );
33 $self->process_method( enrich => $item, $request );
34  
35 =head3 augment
36  
37 $self->augment( $item, $request );
38 $self->process_method( augment => $item, $request );
39  
40 =head3 process_method
41  
42 $self->process_method( $verb, $item, $request );
43  
44 Goes through each of the keys of C<< $self->where >>; if the location of C<$item> matches location specification given (see L<Articulate::LocationSpecification>), then instantiates the value of that key and performs the same verb on the arguments.
45  
46 If none of the where clauses matched, the otherwise provider, if one is specified, will be used.
47  
48 =cut
49  
50 has where => (
51 is => 'rw',
52 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 coerce => sub {
54 2 ▶ my $orig = shift // {};
Subroutine __ANON__: called CC=3 SCAR=11.1
Condition50%1/2
shift() // {}
l!l
20
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
55 2 foreach my $type ( keys %$orig ) {
56 2 $orig->{$type} = instantiate_array( $orig->{$type} );
57 }
58 2 return $orig;
59 },
60 2 );
61  
62 has otherwise => (
63 is => 'rw',
64 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 coerce => sub {
66 2 ▶ instantiate_array(@_);
Subroutine __ANON__: called CC=1 SCAR=0.0
67 },
68 2 );
69  
70 sub process_method {
71 2 ▶ my $self = shift;
Subroutine process_method: called CC=5 SCAR=18.3
Pod documented
72 2 my $method = shift;
73 2 my $item = shift;
74 2 my $location = $item->location;
75 2 ▶ if ( defined $location ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $location) 2 0 2
76 2 foreach my $locspec_string ( keys %{ $self->where } ) {
77 2 my $locspec = locspec $locspec_string;
78 2 ▶ if ( $locspec->matches($location) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locspec->matches($location)) 2 0 2
79 return $self->_delegate(
80 2 $method => $self->where->{$locspec_string},
81 [ $item, @_ ]
82 );
83 }
84 }
85 }
86 0 ▶ if ( defined $self->otherwise ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->otherwise) 0 0 0
87 0 return $self->_delegate( $method => $self->otherwise, [ $item, @_ ] );
88 }
89 0 return $item;
90 }
91  
92 2 1;
« Articulate/Credentials.pm ↑ Summary Articulate/Routes/Login.pm »