« blib/lib/Dist/Zilla/Plugin/PruneFiles.pm
↑ Summary
blib/lib/Dist/Zilla/MintingProfile/Default.pm »
| 1 | package Dist::Zilla::Role::TextTemplate 6.040; | ||||||||||
| 2 | # ABSTRACT: something that renders a Text::Template template string | ||||||||||
| 3 | |||||||||||
| 4 | 16 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 16 | ▶ | use Dist::Zilla::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 16 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | #pod =head1 DESCRIPTION | ||||||||||
| 11 | #pod | ||||||||||
| 12 | #pod Plugins implementing TextTemplate may call their own C<L</fill_in_string>> | ||||||||||
| 13 | #pod method to render templates using L<Text::Template|Text::Template>. | ||||||||||
| 14 | #pod | ||||||||||
| 15 | #pod =cut | ||||||||||
| 16 | |||||||||||
| 17 | 16 | ▶ | use Text::Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | #pod =attr delim | ||||||||||
| 20 | #pod | ||||||||||
| 21 | #pod This attribute (which can't easily be set!) is a two-element array reference | ||||||||||
| 22 | #pod returning the Text::Template delimiters to use. It defaults to C<{{> and | ||||||||||
| 23 | #pod C<}}>. | ||||||||||
| 24 | #pod | ||||||||||
| 25 | #pod =cut | ||||||||||
| 26 | |||||||||||
| 27 | # XXX: Later, add a way to set this in config. -- rjbs, 2008-06-02 | ||||||||||
| 28 | has delim => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => 'ArrayRef', | ||||||||||
| 31 | lazy => 1, | ||||||||||
| 32 | init_arg => undef, | ||||||||||
| 33 | 64 | ▶ | default => sub { [ qw( {{ }} ) ] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 16 | ); | |||||||||
| 35 | |||||||||||
| 36 | #pod =method fill_in_string | ||||||||||
| 37 | #pod | ||||||||||
| 38 | #pod my $rendered = $plugin->fill_in_string($template, \%stash, \%arg); | ||||||||||
| 39 | #pod | ||||||||||
| 40 | #pod This uses Text::Template to fill in the given template using the variables | ||||||||||
| 41 | #pod given in the C<%stash>. The stash becomes the HASH argument to Text::Template, | ||||||||||
| 42 | #pod so scalars must be scalar references rather than plain scalars. | ||||||||||
| 43 | #pod | ||||||||||
| 44 | #pod C<%arg> is dereferenced and passed in as extra arguments to Text::Template's | ||||||||||
| 45 | #pod C<new> routine. | ||||||||||
| 46 | #pod | ||||||||||
| 47 | #pod =cut | ||||||||||
| 48 | |||||||||||
| 49 | 65 | ▶ | sub fill_in_string { | ||||||||
|
Subroutine
fill_in_string: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||
| 50 | 65 | my ($self, $string, $stash, $arg) = @_; | |||||||||
| 51 | |||||||||||
| 52 | 65 | ▶ | $self->log_fatal("Cannot use undef as a template string") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | unless defined $string; | ||||||||||
| 54 | |||||||||||
| 55 | my $tmpl = Text::Template->new( | ||||||||||
| 56 | TYPE => 'STRING', | ||||||||||
| 57 | SOURCE => $string, | ||||||||||
| 58 | DELIMITERS => $self->delim, | ||||||||||
| 59 | 0 | ▶ | BROKEN => sub { my %hash = @_; die $hash{error}; }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 65 | %$arg, | |||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | 65 | ▶ | $self->log_fatal("Could not create a Text::Template object from:\n$string") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | unless $tmpl; | ||||||||||
| 65 | |||||||||||
| 66 | 65 | my $content = $tmpl->fill_in(%$arg, HASH => $stash); | |||||||||
| 67 | |||||||||||
| 68 | 65 | ▶ | $self->log_fatal("Filling in the template returned undef for:\n$string") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | unless defined $content; | ||||||||||
| 70 | |||||||||||
| 71 | 65 | return $content; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 16 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||