| 1 | package Valiant::Filter::Template; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Valiant::Util 'throw_exception'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | with 'Valiant::Filter::Each'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | has template => (is=>'ro', required=>1); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub normalize_shortcut { | ||||||||||||||||||||||||||
|
Subroutine
normalize_shortcut: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 1 | my ($class, $arg) = @_; | |||||||||||||||||||||||||||
| 12 | 1 | return +{ template => $arg }; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub filter_each { | ||||||||||||||||||||||||||
|
Subroutine
filter_each: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 1 | my ($self, $class, $attrs, $attribute_name) = @_; | |||||||||||||||||||||||||||
| 17 | 1 | my $value = $attrs->{$attribute_name}; | |||||||||||||||||||||||||||
| 18 | 1 | ▶ | return unless defined $value and ref($value) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and ref $value eq "HASH"
MC/DC0%0/2
defined $value and ref $value eq "HASH"
defined $value
ref $value eq "HASH"
Truth table33%1/3
A and B
A= defined $valueB= ref $value eq "HASH"
| |||||||||||||||||||||||||||||
| 19 | 1 | return my $template = process_template($self->template, %$value); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | 1; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Valiant::Filter::Template - Flatten a Hashref into a string via a template pattern | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | package Local::Test; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | use Moo; | ||||||||||||||||||||||||||||
| 33 | use Valiant::Filters; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has 'info' => (is=>'ro', required=>1); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | filters 'info', | ||||||||||||||||||||||||||||
| 38 | template => 'Hello {{name}}, you are {{age}} years old!'; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | my $object = Local::Test->new( | ||||||||||||||||||||||||||||
| 41 | info => +{ | ||||||||||||||||||||||||||||
| 42 | name => 'John', | ||||||||||||||||||||||||||||
| 43 | age => '52', | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $object->info; # Hello John you are 52 years old!' | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Given a hashref value, using a template create a string. This isn't a very sophisticated | ||||||||||||||||||||||||||||
| 52 | templating system, and it won't throw errors if hash keys are missing. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | This filter defines the following attributes | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 template | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | The template string | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | L<Valiant>, L<Valiant::Filter>, L<Valiant::Validator::Filter>. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | See L<Valiant> | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | See L<Valiant> | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||