File Coverage

blib/lib/Articulate/Enrichment.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 25 25 100.0


line stmt bran cond sub pod time code
1             package Articulate::Enrichment;
2 5     5   3363 use strict;
  5         9  
  5         168  
3 5     5   20 use warnings;
  5         7  
  5         107  
4              
5 5     5   16 use Moo;
  5         6  
  5         23  
6              
7             with 'Articulate::Role::Component';
8              
9 5     5   1336 use Articulate::Syntax qw(instantiate_array);
  5         8  
  5         30  
10              
11             =head1 NAME
12              
13             Articulate::Enrichment - tidy up your content before it goes into the database
14              
15             =head1 DESCRIPTION
16              
17             use Articulate::Enrichment;
18             $request = enrichment->enrich($item, $request);
19              
20             This will pass the item and the request to a series of enrichment objects, each of which has the opportunity to alter the item according to their own rules, for instance, to add an 'updated on' date to the meta or to fix minor errors in the content.
21              
22             Services should typically invoke enrichment when they create or update content, after validation but before storage.
23              
24             Note: the item passed in is not cloned so this will typically mutate the item.
25              
26             Enrichments should not mutate the request, however there is no technical barrier to them doing so.
27              
28             =head1 ATTRIBUTES
29              
30             =head3 enrichments
31              
32             An array of the enrichment classes which will be used.
33              
34             =cut
35              
36             has enrichments => (
37             is => 'rw',
38             default => sub { [] },
39             coerce => sub { instantiate_array(@_) }
40             );
41              
42             =head1 METHODS
43              
44             =head3 enrich
45              
46             Passes the item and request objects to a series of enrichment objects, and returns the item after each has done their bit.
47              
48             =cut
49              
50             sub enrich {
51 2     2 1 78 my $self = shift;
52 2         3 my $item = shift;
53 2         3 my $request = shift;
54 2         2 foreach my $enrichment ( @{ $self->enrichments } ) {
  2         19  
55 4         427 $request = $enrichment->enrich( $item, $request );
56             }
57 2         5 return $item;
58             }
59              
60             1;