Starter/Plugin/Template.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 99 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
templates
2.0
renderer
2.0
CRAP 2.0
1 package Module::Starter::Plugin::Template;
2  
3 use warnings;
4 use strict;
5 use Carp qw( confess );
6  
7 =head1 NAME
8  
9 Module::Starter::Plugin::Template - module starter with templates
10  
11 =head1 VERSION
12  
13 version 1.82
14  
15 =cut
16  
17 our $VERSION = '1.82';
18  
19 =head1 SYNOPSIS
20  
21 use Module::Starter qw(
22 Module::Starter::Simple
23 Module::Starter::Plugin::Template
24 );
25  
26 Module::Starter->create_distro(%args);
27  
28 =head1 DESCRIPTION
29  
30 This plugin is designed to be added to a Module::Starter::Simple-compatible
31 Module::Starter class. It adds stub methods for template retrieval and
32 rendering, and it replaces all of Simple's _guts methods with methods that will
33 retrieve and render the appropriate templates.
34  
35 =head1 CLASS METHODS
36  
37 =head2 C<< new(%args) >>
38  
39 This plugin calls the C<new> supermethod and then initializes the template
40 store and renderer. (See C<templates> and C<renderer> below.)
41  
42 =cut
43  
44 sub new {
45 my $class = shift;
46 my $self = $class->SUPER::new(@_);
47 $self->{templates} = { $self->templates };
48 $self->{renderer} = $self->renderer;
49 return bless $self => $class;
50 }
51  
52 =head1 OBJECT METHODS
53  
54 =head2 C<< templates() >>
55  
56 This method is used to initialize the template store on the Module::Starter
57 object. It returns a hash of templates; each key is a filename and each value
58 is the body of the template. The filename F<Module.pm> is used for the module
59 template.
60  
61 =cut
62  
63 sub templates {
64 confess 'attempted to use abstract base templates method';
65 }
66  
67 =head2 C<< renderer() >>
68  
69 This method is used to initialize the template renderer. Its result is stored
70 in the object's C<renderer> entry. The implementation will determine its use.
71  
72 =cut
73  
74 sub renderer {
75 confess 'attempted to use abstract base renderer method';
76 }
77  
78 =head2 C<< render($template, \%options) >>
79  
80 The C<render> method will render the template passed to it, using the
81 data in the Module::Starter object and in the hash of passed parameters.
82  
83 =cut
84  
85 sub render {
86 my $self = shift;
87 my $template = shift;
88 my $options = shift;
89  
90 confess 'attempted to use abstract base render method';
91 }
92  
93 =head2 _guts methods
94  
95 All of the C<FILE_guts> methods from Module::Starter::Simple are subclassed to
96 look something like this:
97  
98 sub file_guts {
99 my $self = shift;
100 my %options;
101 @options{qw(first second third)} = @_;
102  
103 my $template = $self->{templates}{filename};
104 $self->render($template, \%options);
105 }
106  
107 These methods will need to be rewritten when (as is likely)
108 Module::Starter::Simple's _guts methods are refactored into a registry.
109  
110 =over 4
111  
112 =item module_guts
113  
114 =cut
115  
116 sub module_guts {
117 my $self = shift;
118 my %options;
119 @options{qw(module rtname)} = @_;
120  
121 my $template = $self->{templates}{'Module.pm'};
122 $self->render($template, \%options);
123 }
124  
125 =item Makefile_PL_guts
126  
127 =cut
128  
129 sub Makefile_PL_guts {
130 my $self = shift;
131 my %options;
132 @options{qw(main_module main_pm_file)} = @_;
133  
134 my $template = $self->{templates}{'Makefile.PL'};
135 $self->render($template, \%options);
136 }
137  
138 =item MI_Makefile_PL_guts
139  
140 =cut
141  
142 sub MI_Makefile_PL_guts {
143 my $self = shift;
144 my %options;
145 @options{qw(main_module main_pm_file)} = @_;
146  
147 my $template = $self->{templates}{'MI_Makefile.PL'};
148 $self->render($template, \%options);
149 }
150  
151 =item Build_PL_guts
152  
153 =cut
154  
155 sub Build_PL_guts {
156 my $self = shift;
157 my %options;
158 @options{qw(main_module main_pm_file)} = @_;
159  
160 my $template = $self->{templates}{'Build.PL'};
161 $self->render($template, \%options);
162 }
163  
164 =item Changes_guts
165  
166 =cut
167  
168 sub Changes_guts {
169 my $self = shift;
170  
171 my $template = $self->{templates}{'Changes'};
172 $self->render($template);
173 }
174  
175 =item README_guts
176  
177 =cut
178  
179 sub README_guts {
180 my $self = shift;
181 my %options;
182 @options{qw(build_instructions)} = @_;
183  
184 my $template = $self->{templates}{'README'};
185 $self->render($template, \%options);
186 }
187  
188 =item t_guts
189  
190 =cut
191  
192 sub t_guts {
193 my $self = shift;
194 my %options;
195 $options{modules} = [ @_ ];
196  
197 my %t_files;
198  
199 foreach (grep { /\.t$/ } keys %{$self->{templates}}) {
200 my $template = $self->{templates}{$_};
201 $t_files{$_} = $self->render($template, \%options);
202 }
203  
204 return %t_files;
205 }
206  
207 =item MANIFEST_guts
208  
209 =cut
210  
211 sub MANIFEST_guts {
212 my $self = shift;
213 my %options;
214 $options{files} = [ sort @_ ];
215  
216 my $template = $self->{templates}{MANIFEST};
217 $self->render($template, \%options);
218 }
219  
220 =item ignores_guts
221  
222 =cut
223  
224 sub ignores_guts {
225 my $self = shift;
226  
227 my $template = $self->{templates}{ignores};
228 $self->render($template);
229 }
230  
231 =back
232  
233 =head1 AUTHOR
234  
235 Ricardo SIGNES, C<< <rjbs at cpan.org> >>
236  
237 =head1 Bugs
238  
239 Please report any bugs or feature requests to the bugtracker for this project
240 on GitHub at: L<https://github.com/xsawyerx/module-starter/issues>. I will be
241 notified, and then you'll automatically be notified of progress on your bug
242 as I make changes.
243  
244 =head1 COPYRIGHT
245  
246 Copyright 2005-2007 Ricardo SIGNES, All Rights Reserved.
247  
248 This program is free software; you can redistribute it and/or modify it
249 under the same terms as Perl itself.
250  
251 =cut
252  
253 # vi:et:sw=4 ts=4
254  
255 1;