Articulate/Flow/ContentType.pm

filter: Statementstmt 45.7% 16 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod 100% 1 / 1 totaltotal 38.8% 21 / 54 CC 7 SCAR 25.7
CC
7
Cov
37%
process_method
30.0
__ANON__
12.0
__ANON__
2.0
CRAP 13.1
« Articulate/Authentication/Preconfigured.pm ↑ Summary Articulate/Serialisation/StatusSetter.pm »
1 package Articulate::Flow::ContentType;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with 'Articulate::Role::Flow';
6 1 ▶use Articulate::Syntax qw (instantiate instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Articulate::Flow::ContentType - case switching for content_type
11  
12 =head1 CONFIGURATION
13  
14 - class: Articulate::Flow::ContentType
15 args:
16 where:
17 'text/markdown':
18 - Articulate::Enrichment::Markdown
19 otherwise:
20 - SomeOther::Enrichment
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 what type of content is stored in the item.
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 key is equal to the C<content_type> of C<$item>, 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 An item's C<content_type> is retrieved from C<meta.schema.core.content_type>.
49  
50 =cut
51  
52 has where => (
53 is => 'rw',
54 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 ▶ coerce => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
56 0 ▶ my $orig = shift // {};
Condition0%0/2
shift() // {}
l!l
00
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
57 0 foreach my $type ( keys %$orig ) {
58 0 $orig->{$type} = instantiate_array( $orig->{$type} );
59 }
60 0 return $orig;
61 },
62 1 );
63  
64 has otherwise => (
65 is => 'rw',
66 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 ▶ coerce => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 instantiate_array(@_);
69 },
70 1 );
71  
72 0 ▶sub process_method {
Subroutine process_method: not called CC=5 SCAR=34.0
Pod documented
73 0 my $self = shift;
74 0 my $method = shift;
75 0 my $item = shift;
76 0 my $content_type = $item->meta->{schema}->{core}->{content_type};
77 0 ▶ if ( defined $content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_type) 0 0 0
78 0 foreach my $type ( keys %{ $self->where } ) {
79 0 ▶ if ( $type eq $content_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $content_type) 0 0 0
80 0 return $self->_delegate( $method => $self->where->{$type},
81 [ $item, @_ ] );
82 }
83 }
84 }
85 0 ▶ if ( defined $self->otherwise ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->otherwise) 0 0 0
86 0 return $self->_delegate( $method => $self->otherwise, [ $item, @_ ] );
87 }
88 0 return $item;
89 }
90  
91 1 1;
« Articulate/Authentication/Preconfigured.pm ↑ Summary Articulate/Serialisation/StatusSetter.pm »