| 1 | package Articulate::Enrichment; | ||
| 2 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 4 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 4 | with 'Articulate::Role::Component'; | |
| 8 | |||
| 9 | 4 | ▶ | use Articulate::Syntax qw(instantiate_array); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | 0 | ▶ | default => sub { [] }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 39 | 3 | ▶ | coerce => sub { instantiate_array(@_) }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 40 | |||
| 41 | =head1 METHODS | ||
| 42 | |||
| 43 | =head3 enrich | ||
| 44 | |||
| 45 | Passes the item and request objects to a series of enrichment objects, and returns the item after each has done their bit. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub enrich { | ||
| 50 | 2 | ▶ | my $self = shift; |
|
Subroutine
enrich: called CC=2 SCAR=6.9
Pod
documented
| |||
| 51 | 2 | my $item = shift; | |
| 52 | 2 | my $request = shift; | |
| 53 | 2 | foreach my $enrichment ( @{ $self->enrichments } ) { | |
| 54 | 4 | $request = $enrichment->enrich($item, $request); | |
| 55 | } | ||
| 56 | 2 | return $item; | |
| 57 | } | ||
| 58 | |||
| 59 | 4 | 1; | |