| 1 | package Articulate::Augmentation; | ||
| 2 | 5 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 5 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 5 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 5 | with 'Articulate::Role::Component'; | |
| 8 | |||
| 9 | 5 | ▶ | use Articulate::Syntax qw(instantiate_array); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Articulate::Augmentaton - add bells and whistles to your response | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | use Articulate::Augmentation; | ||
| 18 | $response = augmentation->augment($response); | ||
| 19 | |||
| 20 | This will pass the response to a series of augmentation objects, each of which has the opportunity to alter the response according to their own rules, for instance, to retrieve additional related content (e.g. article comments). | ||
| 21 | |||
| 22 | Note: the response passed in is not cloned so this will typically mutate the response. | ||
| 23 | |||
| 24 | =head1 ATTRIBUTES | ||
| 25 | |||
| 26 | =head3 augmentations | ||
| 27 | |||
| 28 | An array of the augmentation classes which will be used. | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | has augmentations => ( | ||
| 33 | is => 'rw', | ||
| 34 | 4 | ▶ | default => sub { [] }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 35 | 4 | ▶ | coerce => sub { instantiate_array(@_) } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 36 | 5 | ); | |
| 37 | |||
| 38 | =head1 METHODS | ||
| 39 | |||
| 40 | =head3 augment | ||
| 41 | |||
| 42 | Passes the response object to a series of augmentation objects, and returns the response after each has done their bit. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | sub augment { | ||
| 47 | 3 | ▶ | my $self = shift; |
|
Subroutine
augment: called CC=2 SCAR=7.0
Pod
documented
| |||
| 48 | 3 | my $item = shift; | |
| 49 | 3 | foreach my $aug ( @{ $self->augmentations } ) { | |
| 50 | 0 | $item = $aug->augment($item); | |
| 51 | } | ||
| 52 | 3 | return $item; | |
| 53 | } | ||
| 54 | |||
| 55 | 5 | 1; | |