Codebase list libmasonx-processdir-perl / upstream/0.02
Import original source of MasonX-ProcessDir 0.02 Florian Schlichting 11 years ago
15 changed file(s) with 945 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Revision history for MasonX-ProcessDir
1
2 ** denotes an incompatible change
3
4 0.02 Mar 7, 2012
5
6 - Remove debugging line
7
8 0.01 Nov 27, 2011
9
10 - Initial version
11
0
1 This is the Perl distribution MasonX-ProcessDir.
2
3 Installing MasonX-ProcessDir is straightforward.
4
5 ## Installation with cpanm
6
7 If you have cpanm, you only need one line:
8
9 % cpanm MasonX::ProcessDir
10
11 If you are installing into a system-wide directory, you may need to pass the
12 "-S" flag to cpanm, which uses sudo to install the module:
13
14 % cpanm -S MasonX::ProcessDir
15
16 ## Installing with the CPAN shell
17
18 Alternatively, if your CPAN shell is set up, you should just be able to do:
19
20 % cpan MasonX::ProcessDir
21
22 ## Manual installation
23
24 As a last resort, you can manually install it. Download the tarball, untar it,
25 then build it:
26
27 % perl Makefile.PL
28 % make && make test
29
30 Then install it:
31
32 % make install
33
34 If you are installing into a system-wide directory, you may need to run:
35
36 % sudo make install
37
38 ## Documentation
39
40 MasonX-ProcessDir documentation is available as POD.
41 You can run perldoc from a shell to read the documentation:
42
43 % perldoc MasonX::ProcessDir
0 This software is copyright (c) 2011 by Jonathan Swartz.
1
2 This is free software; you can redistribute it and/or modify it under
3 the same terms as the Perl 5 programming language system itself.
4
5 Terms of the Perl programming language system itself
6
7 a) the GNU General Public License as published by the Free
8 Software Foundation; either version 1, or (at your option) any
9 later version, or
10 b) the "Artistic License"
11
12 --- The GNU General Public License, Version 1, February 1989 ---
13
14 This software is Copyright (c) 2011 by Jonathan Swartz.
15
16 This is free software, licensed under:
17
18 The GNU General Public License, Version 1, February 1989
19
20 GNU GENERAL PUBLIC LICENSE
21 Version 1, February 1989
22
23 Copyright (C) 1989 Free Software Foundation, Inc.
24 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
25 Everyone is permitted to copy and distribute verbatim copies
26 of this license document, but changing it is not allowed.
27
28 Preamble
29
30 The license agreements of most software companies try to keep users
31 at the mercy of those companies. By contrast, our General Public
32 License is intended to guarantee your freedom to share and change free
33 software--to make sure the software is free for all its users. The
34 General Public License applies to the Free Software Foundation's
35 software and to any other program whose authors commit to using it.
36 You can use it for your programs, too.
37
38 When we speak of free software, we are referring to freedom, not
39 price. Specifically, the General Public License is designed to make
40 sure that you have the freedom to give away or sell copies of free
41 software, that you receive source code or can get it if you want it,
42 that you can change the software or use pieces of it in new free
43 programs; and that you know you can do these things.
44
45 To protect your rights, we need to make restrictions that forbid
46 anyone to deny you these rights or to ask you to surrender the rights.
47 These restrictions translate to certain responsibilities for you if you
48 distribute copies of the software, or if you modify it.
49
50 For example, if you distribute copies of a such a program, whether
51 gratis or for a fee, you must give the recipients all the rights that
52 you have. You must make sure that they, too, receive or can get the
53 source code. And you must tell them their rights.
54
55 We protect your rights with two steps: (1) copyright the software, and
56 (2) offer you this license which gives you legal permission to copy,
57 distribute and/or modify the software.
58
59 Also, for each author's protection and ours, we want to make certain
60 that everyone understands that there is no warranty for this free
61 software. If the software is modified by someone else and passed on, we
62 want its recipients to know that what they have is not the original, so
63 that any problems introduced by others will not reflect on the original
64 authors' reputations.
65
66 The precise terms and conditions for copying, distribution and
67 modification follow.
68
69 GNU GENERAL PUBLIC LICENSE
70 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
71
72 0. This License Agreement applies to any program or other work which
73 contains a notice placed by the copyright holder saying it may be
74 distributed under the terms of this General Public License. The
75 "Program", below, refers to any such program or work, and a "work based
76 on the Program" means either the Program or any work containing the
77 Program or a portion of it, either verbatim or with modifications. Each
78 licensee is addressed as "you".
79
80 1. You may copy and distribute verbatim copies of the Program's source
81 code as you receive it, in any medium, provided that you conspicuously and
82 appropriately publish on each copy an appropriate copyright notice and
83 disclaimer of warranty; keep intact all the notices that refer to this
84 General Public License and to the absence of any warranty; and give any
85 other recipients of the Program a copy of this General Public License
86 along with the Program. You may charge a fee for the physical act of
87 transferring a copy.
88
89 2. You may modify your copy or copies of the Program or any portion of
90 it, and copy and distribute such modifications under the terms of Paragraph
91 1 above, provided that you also do the following:
92
93 a) cause the modified files to carry prominent notices stating that
94 you changed the files and the date of any change; and
95
96 b) cause the whole of any work that you distribute or publish, that
97 in whole or in part contains the Program or any part thereof, either
98 with or without modifications, to be licensed at no charge to all
99 third parties under the terms of this General Public License (except
100 that you may choose to grant warranty protection to some or all
101 third parties, at your option).
102
103 c) If the modified program normally reads commands interactively when
104 run, you must cause it, when started running for such interactive use
105 in the simplest and most usual way, to print or display an
106 announcement including an appropriate copyright notice and a notice
107 that there is no warranty (or else, saying that you provide a
108 warranty) and that users may redistribute the program under these
109 conditions, and telling the user how to view a copy of this General
110 Public License.
111
112 d) You may charge a fee for the physical act of transferring a
113 copy, and you may at your option offer warranty protection in
114 exchange for a fee.
115
116 Mere aggregation of another independent work with the Program (or its
117 derivative) on a volume of a storage or distribution medium does not bring
118 the other work under the scope of these terms.
119
120 3. You may copy and distribute the Program (or a portion or derivative of
121 it, under Paragraph 2) in object code or executable form under the terms of
122 Paragraphs 1 and 2 above provided that you also do one of the following:
123
124 a) accompany it with the complete corresponding machine-readable
125 source code, which must be distributed under the terms of
126 Paragraphs 1 and 2 above; or,
127
128 b) accompany it with a written offer, valid for at least three
129 years, to give any third party free (except for a nominal charge
130 for the cost of distribution) a complete machine-readable copy of the
131 corresponding source code, to be distributed under the terms of
132 Paragraphs 1 and 2 above; or,
133
134 c) accompany it with the information you received as to where the
135 corresponding source code may be obtained. (This alternative is
136 allowed only for noncommercial distribution and only if you
137 received the program in object code or executable form alone.)
138
139 Source code for a work means the preferred form of the work for making
140 modifications to it. For an executable file, complete source code means
141 all the source code for all modules it contains; but, as a special
142 exception, it need not include source code for modules which are standard
143 libraries that accompany the operating system on which the executable
144 file runs, or for standard header files or definitions files that
145 accompany that operating system.
146
147 4. You may not copy, modify, sublicense, distribute or transfer the
148 Program except as expressly provided under this General Public License.
149 Any attempt otherwise to copy, modify, sublicense, distribute or transfer
150 the Program is void, and will automatically terminate your rights to use
151 the Program under this License. However, parties who have received
152 copies, or rights to use copies, from you under this General Public
153 License will not have their licenses terminated so long as such parties
154 remain in full compliance.
155
156 5. By copying, distributing or modifying the Program (or any work based
157 on the Program) you indicate your acceptance of this license to do so,
158 and all its terms and conditions.
159
160 6. Each time you redistribute the Program (or any work based on the
161 Program), the recipient automatically receives a license from the original
162 licensor to copy, distribute or modify the Program subject to these
163 terms and conditions. You may not impose any further restrictions on the
164 recipients' exercise of the rights granted herein.
165
166 7. The Free Software Foundation may publish revised and/or new versions
167 of the General Public License from time to time. Such new versions will
168 be similar in spirit to the present version, but may differ in detail to
169 address new problems or concerns.
170
171 Each version is given a distinguishing version number. If the Program
172 specifies a version number of the license which applies to it and "any
173 later version", you have the option of following the terms and conditions
174 either of that version or of any later version published by the Free
175 Software Foundation. If the Program does not specify a version number of
176 the license, you may choose any version ever published by the Free Software
177 Foundation.
178
179 8. If you wish to incorporate parts of the Program into other free
180 programs whose distribution conditions are different, write to the author
181 to ask for permission. For software which is copyrighted by the Free
182 Software Foundation, write to the Free Software Foundation; we sometimes
183 make exceptions for this. Our decision will be guided by the two goals
184 of preserving the free status of all derivatives of our free software and
185 of promoting the sharing and reuse of software generally.
186
187 NO WARRANTY
188
189 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
190 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
191 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
192 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
193 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
194 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
195 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
196 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
197 REPAIR OR CORRECTION.
198
199 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
200 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
201 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
202 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
203 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
204 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
205 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
206 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
207 POSSIBILITY OF SUCH DAMAGES.
208
209 END OF TERMS AND CONDITIONS
210
211 Appendix: How to Apply These Terms to Your New Programs
212
213 If you develop a new program, and you want it to be of the greatest
214 possible use to humanity, the best way to achieve this is to make it
215 free software which everyone can redistribute and change under these
216 terms.
217
218 To do so, attach the following notices to the program. It is safest to
219 attach them to the start of each source file to most effectively convey
220 the exclusion of warranty; and each file should have at least the
221 "copyright" line and a pointer to where the full notice is found.
222
223 <one line to give the program's name and a brief idea of what it does.>
224 Copyright (C) 19yy <name of author>
225
226 This program is free software; you can redistribute it and/or modify
227 it under the terms of the GNU General Public License as published by
228 the Free Software Foundation; either version 1, or (at your option)
229 any later version.
230
231 This program is distributed in the hope that it will be useful,
232 but WITHOUT ANY WARRANTY; without even the implied warranty of
233 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234 GNU General Public License for more details.
235
236 You should have received a copy of the GNU General Public License
237 along with this program; if not, write to the Free Software Foundation,
238 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
239
240 Also add information on how to contact you by electronic and paper mail.
241
242 If the program is interactive, make it output a short notice like this
243 when it starts in an interactive mode:
244
245 Gnomovision version 69, Copyright (C) 19xx name of author
246 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
247 This is free software, and you are welcome to redistribute it
248 under certain conditions; type `show c' for details.
249
250 The hypothetical commands `show w' and `show c' should show the
251 appropriate parts of the General Public License. Of course, the
252 commands you use may be called something other than `show w' and `show
253 c'; they could even be mouse-clicks or menu items--whatever suits your
254 program.
255
256 You should also get your employer (if you work as a programmer) or your
257 school, if any, to sign a "copyright disclaimer" for the program, if
258 necessary. Here a sample; alter the names:
259
260 Yoyodyne, Inc., hereby disclaims all copyright interest in the
261 program `Gnomovision' (a program to direct compilers to make passes
262 at assemblers) written by James Hacker.
263
264 <signature of Ty Coon>, 1 April 1989
265 Ty Coon, President of Vice
266
267 That's all there is to it!
268
269
270 --- The Artistic License 1.0 ---
271
272 This software is Copyright (c) 2011 by Jonathan Swartz.
273
274 This is free software, licensed under:
275
276 The Artistic License 1.0
277
278 The Artistic License
279
280 Preamble
281
282 The intent of this document is to state the conditions under which a Package
283 may be copied, such that the Copyright Holder maintains some semblance of
284 artistic control over the development of the package, while giving the users of
285 the package the right to use and distribute the Package in a more-or-less
286 customary fashion, plus the right to make reasonable modifications.
287
288 Definitions:
289
290 - "Package" refers to the collection of files distributed by the Copyright
291 Holder, and derivatives of that collection of files created through
292 textual modification.
293 - "Standard Version" refers to such a Package if it has not been modified,
294 or has been modified in accordance with the wishes of the Copyright
295 Holder.
296 - "Copyright Holder" is whoever is named in the copyright or copyrights for
297 the package.
298 - "You" is you, if you're thinking about copying or distributing this Package.
299 - "Reasonable copying fee" is whatever you can justify on the basis of media
300 cost, duplication charges, time of people involved, and so on. (You will
301 not be required to justify it to the Copyright Holder, but only to the
302 computing community at large as a market that must bear the fee.)
303 - "Freely Available" means that no fee is charged for the item itself, though
304 there may be fees involved in handling the item. It also means that
305 recipients of the item may redistribute it under the same conditions they
306 received it.
307
308 1. You may make and give away verbatim copies of the source form of the
309 Standard Version of this Package without restriction, provided that you
310 duplicate all of the original copyright notices and associated disclaimers.
311
312 2. You may apply bug fixes, portability fixes and other modifications derived
313 from the Public Domain or from the Copyright Holder. A Package modified in such
314 a way shall still be considered the Standard Version.
315
316 3. You may otherwise modify your copy of this Package in any way, provided that
317 you insert a prominent notice in each changed file stating how and when you
318 changed that file, and provided that you do at least ONE of the following:
319
320 a) place your modifications in the Public Domain or otherwise make them
321 Freely Available, such as by posting said modifications to Usenet or an
322 equivalent medium, or placing the modifications on a major archive site
323 such as ftp.uu.net, or by allowing the Copyright Holder to include your
324 modifications in the Standard Version of the Package.
325
326 b) use the modified Package only within your corporation or organization.
327
328 c) rename any non-standard executables so the names do not conflict with
329 standard executables, which must also be provided, and provide a separate
330 manual page for each non-standard executable that clearly documents how it
331 differs from the Standard Version.
332
333 d) make other distribution arrangements with the Copyright Holder.
334
335 4. You may distribute the programs of this Package in object code or executable
336 form, provided that you do at least ONE of the following:
337
338 a) distribute a Standard Version of the executables and library files,
339 together with instructions (in the manual page or equivalent) on where to
340 get the Standard Version.
341
342 b) accompany the distribution with the machine-readable source of the Package
343 with your modifications.
344
345 c) accompany any non-standard executables with their corresponding Standard
346 Version executables, giving the non-standard executables non-standard
347 names, and clearly documenting the differences in manual pages (or
348 equivalent), together with instructions on where to get the Standard
349 Version.
350
351 d) make other distribution arrangements with the Copyright Holder.
352
353 5. You may charge a reasonable copying fee for any distribution of this
354 Package. You may charge any fee you choose for support of this Package. You
355 may not charge a fee for this Package itself. However, you may distribute this
356 Package in aggregate with other (possibly commercial) programs as part of a
357 larger (possibly commercial) software distribution provided that you do not
358 advertise this Package as a product of your own.
359
360 6. The scripts and library files supplied as input to or produced as output
361 from the programs of this Package do not automatically fall under the copyright
362 of this Package, but belong to whomever generated them, and may be sold
363 commercially, and may be aggregated with this Package.
364
365 7. C or perl subroutines supplied by you and linked into this Package shall not
366 be considered part of this Package.
367
368 8. The name of the Copyright Holder may not be used to endorse or promote
369 products derived from this software without specific prior written permission.
370
371 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
372 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
373 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
374
375 The End
376
0 Changes
1 INSTALL
2 LICENSE
3 MANIFEST
4 META.json
5 META.yml
6 Makefile.PL
7 lib/MasonX/ProcessDir.pm
8 t/01-use.t
9 t/process.t
10 t/source/Base.mc
11 t/source/four.mc
12 t/source/plus.mi
13 t/source/two.mc
0 {
1 "abstract" : "Process a directory of Mason templates",
2 "author" : [
3 "Jonathan Swartz <swartz@pobox.com>"
4 ],
5 "dynamic_config" : 0,
6 "generated_by" : "Dist::Zilla version 4.200008, CPAN::Meta::Converter version 2.113640",
7 "license" : [
8 "perl_5"
9 ],
10 "meta-spec" : {
11 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
12 "version" : "2"
13 },
14 "name" : "MasonX-ProcessDir",
15 "prereqs" : {
16 "configure" : {
17 "requires" : {
18 "ExtUtils::MakeMaker" : "6.30"
19 }
20 },
21 "runtime" : {
22 "requires" : {
23 "Any::Template::ProcessDir" : "0.04",
24 "Mason" : "2.10"
25 }
26 },
27 "test" : {
28 "requires" : {
29 "Test::More" : 0
30 }
31 }
32 },
33 "release_status" : "stable",
34 "resources" : {
35 "bugtracker" : {
36 "mailto" : "bug-masonx-processdir@rt.cpan.org",
37 "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=MasonX-ProcessDir"
38 },
39 "repository" : {
40 "type" : "git",
41 "url" : "git://github.com/jonswar/perl-masonx-processdir.git",
42 "web" : "https://github.com/jonswar/perl-masonx-processdir"
43 }
44 },
45 "version" : "0.02"
46 }
47
0 ---
1 abstract: 'Process a directory of Mason templates'
2 author:
3 - 'Jonathan Swartz <swartz@pobox.com>'
4 build_requires:
5 Test::More: 0
6 configure_requires:
7 ExtUtils::MakeMaker: 6.30
8 dynamic_config: 0
9 generated_by: 'Dist::Zilla version 4.200008, CPAN::Meta::Converter version 2.113640'
10 license: perl
11 meta-spec:
12 url: http://module-build.sourceforge.net/META-spec-v1.4.html
13 version: 1.4
14 name: MasonX-ProcessDir
15 requires:
16 Any::Template::ProcessDir: 0.04
17 Mason: 2.10
18 resources:
19 bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=MasonX-ProcessDir
20 repository: git://github.com/jonswar/perl-masonx-processdir.git
21 version: 0.02
0
1 use strict;
2 use warnings;
3
4
5
6 use ExtUtils::MakeMaker 6.30;
7
8
9
10 my %WriteMakefileArgs = (
11 'ABSTRACT' => 'Process a directory of Mason templates',
12 'AUTHOR' => 'Jonathan Swartz <swartz@pobox.com>',
13 'BUILD_REQUIRES' => {
14 'Test::More' => '0'
15 },
16 'CONFIGURE_REQUIRES' => {
17 'ExtUtils::MakeMaker' => '6.30'
18 },
19 'DISTNAME' => 'MasonX-ProcessDir',
20 'EXE_FILES' => [],
21 'LICENSE' => 'perl',
22 'NAME' => 'MasonX::ProcessDir',
23 'PREREQ_PM' => {
24 'Any::Template::ProcessDir' => '0.04',
25 'Mason' => '2.10'
26 },
27 'VERSION' => '0.02',
28 'test' => {
29 'TESTS' => 't/*.t'
30 }
31 );
32
33
34 unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
35 my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
36 my $pp = $WriteMakefileArgs{PREREQ_PM};
37 for my $mod ( keys %$br ) {
38 if ( exists $pp->{$mod} ) {
39 $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
40 }
41 else {
42 $pp->{$mod} = $br->{$mod};
43 }
44 }
45 }
46
47 delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
48 unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
49
50 WriteMakefile(%WriteMakefileArgs);
51
52
53
0 NAME
1 MasonX::ProcessDir - Process a directory of Mason 2 templates
2
3 VERSION
4 version 0.02
5
6 SYNOPSIS
7 use MasonX::ProcessDir;
8
9 # Generate result files in the same directory as the templates
10 #
11 my $pd = MasonX::ProcessDir->new(
12 dir => '/path/to/dir'
13 );
14 $pd->process_dir();
15
16 # Generate result files in a separate directory
17 #
18 my $pd = MasonX::ProcessDir->new(
19 source_dir => '/path/to/source/dir',
20 dest_dir => '/path/to/dest/dir'
21 );
22 $pd->process_dir();
23
24 DESCRIPTION
25 Recursively processes a directory of Mason 2 templates, generating a set
26 of result files in the same directory or in a parallel directory.
27
28 Every file with suffix ".mc" will be processed, and the results placed
29 in a file of the same name without the suffix. ".mi", autobase and
30 dhandler files will be used by Mason when processing the templates but
31 will not generate files themselves.
32
33 For example, if the source directory contains
34
35 Base.mc
36 httpd.conf.mc
37 proxy.conf.mc
38 etc/crontab.mc
39 blah.mi
40 somefile.txt
41
42 and we run
43
44 my $pd = MasonX::ProcessDir->new(
45 source_dir => '/path/to/source/dir',
46 dest_dir => '/path/to/dest/dir'
47 );
48 $pd->process_dir();
49
50 then afterwards the destination directory will contain files
51
52 httpd.conf
53 proxy.conf
54 etc/crontab
55 somefile.txt
56
57 where *foo* and *bar* are the results of processing *foo.mc* and
58 *bar.mc* through Mason. *Base.mc* and *blah.mi* may be used during Mason
59 processing but won't generate result files themselves.
60
61 This class is a convenience extension of Any::Template::ProcessDir.
62
63 CONSTRUCTOR
64 Specifying directory/directories
65 * If you want to generate the result files in the same directory as
66 the templates, just specify *dir*.
67
68 my $pd = MasonX::ProcessDir->new(
69 dir => '/path/to/dir',
70 ...
71 );
72
73 * If you want to generate the result files in a separate directory
74 from the templates, specify *source_dir* and *dest_dir*.
75
76 my $pd = MasonX::ProcessDir->new(
77 source_dir => '/path/to/source/dir',
78 source_dir => '/path/to/dest/dir',
79 ...
80 );
81
82 Mason options
83 mason_options
84 An optional hash of options to the Mason interpreter. For example,
85 the default Mason data directory will be ".mason" under the source
86 directory, but you can override this:
87
88 mason_options => { data_dir => '/path/to/data/dir' }
89
90 Options inherited from Any::Template::ProcessDir
91 See Any::Template::ProcessDir for other options, such as
92
93 dir_create_mode
94 file_create_mode
95 readme_filename
96
97 SUPPORT AND DOCUMENTATION
98 Bugs and feature requests will be tracked at RT:
99
100 http://rt.cpan.org/NoAuth/Bugs.html?Dist=MasonX-ProcessDir
101 bug-masonx-processdir@rt.cpan.org
102
103 The latest source code can be browsed and fetched at:
104
105 http://github.com/jonswar/perl-masonx-processdir
106 git clone git://github.com/jonswar/perl-masonx-processdir.git
107
108 SEE ALSO
109 Mason, Any::Template::ProcessDir
110
111 AUTHOR
112 Jonathan Swartz <swartz@pobox.com>
113
114 COPYRIGHT AND LICENSE
115 This software is copyright (c) 2011 by Jonathan Swartz.
116
117 This is free software; you can redistribute it and/or modify it under
118 the same terms as the Perl 5 programming language system itself.
119
0 package MasonX::ProcessDir;
1 BEGIN {
2 $MasonX::ProcessDir::VERSION = '0.02';
3 }
4 use Mason;
5 use Moose;
6 use strict;
7 use warnings;
8
9 extends 'Any::Template::ProcessDir';
10
11 has '+ignore_files' => ( default => sub { sub { $_[0] =~ /Base\.|\.mason|\.mi$/ } } );
12 has '+template_file_suffix' => ( default => '.mc' );
13 has 'mason' => ( is => 'ro', init_arg => undef, lazy_build => 1 );
14 has 'mason_options' => ( is => 'ro', default => sub { {} } );
15
16 sub _build_mason {
17 my $self = shift;
18
19 my $source_dir = $self->source_dir;
20 my %options = (
21 comp_root => $source_dir,
22 data_dir => "$source_dir/.mason",
23 %{ $self->mason_options }
24 );
25 return Mason->new(%options);
26 }
27
28 sub _build_process_file {
29 return sub {
30 my ( $file, $self ) = @_;
31 my $comp_path = substr( $file, length( $self->source_dir ), -3 );
32 return $self->mason->run($comp_path)->output;
33 };
34 }
35
36 1;
37
38
39
40 =pod
41
42 =head1 NAME
43
44 MasonX::ProcessDir - Process a directory of Mason 2 templates
45
46 =head1 VERSION
47
48 version 0.02
49
50 =head1 SYNOPSIS
51
52 use MasonX::ProcessDir;
53
54 # Generate result files in the same directory as the templates
55 #
56 my $pd = MasonX::ProcessDir->new(
57 dir => '/path/to/dir'
58 );
59 $pd->process_dir();
60
61 # Generate result files in a separate directory
62 #
63 my $pd = MasonX::ProcessDir->new(
64 source_dir => '/path/to/source/dir',
65 dest_dir => '/path/to/dest/dir'
66 );
67 $pd->process_dir();
68
69 =head1 DESCRIPTION
70
71 Recursively processes a directory of L<Mason 2|Mason> templates, generating a
72 set of result files in the same directory or in a parallel directory.
73
74 Every file with suffix ".mc" will be processed, and the results placed in a
75 file of the same name without the suffix. ".mi", autobase and dhandler files
76 will be used by Mason when processing the templates but will not generate files
77 themselves.
78
79 For example, if the source directory contains
80
81 Base.mc
82 httpd.conf.mc
83 proxy.conf.mc
84 etc/crontab.mc
85 blah.mi
86 somefile.txt
87
88 and we run
89
90 my $pd = MasonX::ProcessDir->new(
91 source_dir => '/path/to/source/dir',
92 dest_dir => '/path/to/dest/dir'
93 );
94 $pd->process_dir();
95
96 then afterwards the destination directory will contain files
97
98 httpd.conf
99 proxy.conf
100 etc/crontab
101 somefile.txt
102
103 where I<foo> and I<bar> are the results of processing I<foo.mc> and I<bar.mc>
104 through Mason. I<Base.mc> and I<blah.mi> may be used during Mason processing
105 but won't generate result files themselves.
106
107 This class is a convenience extension of
108 L<Any::Template::ProcessDir|Any::Template::ProcessDir>.
109
110 =head1 CONSTRUCTOR
111
112 =head2 Specifying directory/directories
113
114 =over
115
116 =item *
117
118 If you want to generate the result files in the B<same> directory as the
119 templates, just specify I<dir>.
120
121 my $pd = MasonX::ProcessDir->new(
122 dir => '/path/to/dir',
123 ...
124 );
125
126 =item *
127
128 If you want to generate the result files in a B<separate> directory from the
129 templates, specify I<source_dir> and I<dest_dir>.
130
131 my $pd = MasonX::ProcessDir->new(
132 source_dir => '/path/to/source/dir',
133 source_dir => '/path/to/dest/dir',
134 ...
135 );
136
137 =back
138
139 =head2 Mason options
140
141 =over
142
143 =item mason_options
144
145 An optional hash of options to the Mason interpreter. For example, the default
146 Mason data directory will be ".mason" under the source directory, but you can
147 override this:
148
149 mason_options => { data_dir => '/path/to/data/dir' }
150
151 =back
152
153 =head2 Options inherited from Any::Template::ProcessDir
154
155 See L<Any::Template::ProcessDir> for other options, such as
156
157 dir_create_mode
158 file_create_mode
159 readme_filename
160
161 =head1 SUPPORT AND DOCUMENTATION
162
163 Bugs and feature requests will be tracked at RT:
164
165 http://rt.cpan.org/NoAuth/Bugs.html?Dist=MasonX-ProcessDir
166 bug-masonx-processdir@rt.cpan.org
167
168 The latest source code can be browsed and fetched at:
169
170 http://github.com/jonswar/perl-masonx-processdir
171 git clone git://github.com/jonswar/perl-masonx-processdir.git
172
173 =head1 SEE ALSO
174
175 L<Mason>, L<Any::Template::ProcessDir>
176
177 =head1 AUTHOR
178
179 Jonathan Swartz <swartz@pobox.com>
180
181 =head1 COPYRIGHT AND LICENSE
182
183 This software is copyright (c) 2011 by Jonathan Swartz.
184
185 This is free software; you can redistribute it and/or modify it under
186 the same terms as the Perl 5 programming language system itself.
187
188 =cut
189
190
191 __END__
192
0 #!perl
1 use Test::More tests => 1;
2
3 use_ok('MasonX::ProcessDir');
0 #!perl
1 use MasonX::ProcessDir;
2 use Cwd qw(realpath);
3 use File::Basename;
4 use File::Copy::Recursive qw(dircopy);
5 use File::Find::Wanted;
6 use File::Path qw(remove_tree);
7 use File::Slurp;
8 use File::Temp qw(tempdir);
9 use Test::More;
10 use strict;
11 use warnings;
12
13 my $root_dir = tempdir( 'template-any-processdir-XXXX', TMPDIR => 1, CLEANUP => 1 );
14 my $source_dir = "$root_dir/source";
15 my $dest_dir = "$root_dir/dest";
16
17 sub try {
18 dircopy( "t/source", $source_dir );
19
20 my $pd = MasonX::ProcessDir->new(
21 source_dir => $source_dir,
22 dest_dir => $dest_dir,
23 readme_filename => 'readme.txt',
24 mason_options => { data_dir => "$root_dir/.mason_data_dir" },
25 );
26 $pd->process_dir();
27
28 is( trim( scalar( read_file("$dest_dir/two") ) ), "TWO PLUS TWO EQUALS 4", "two" );
29 is( trim( scalar( read_file("$dest_dir/four") ) ), "FOUR PLUS FOUR EQUALS 8", "four" );
30 ok( -f "$dest_dir/readme.txt", "readme" );
31 ok( -d "$root_dir/.mason_data_dir", "mason_options" );
32
33 my @dest_files = find_wanted( sub { -f }, $dest_dir );
34 is( scalar(@dest_files), 3, "3 files generated" );
35 }
36
37 sub trim {
38 my $str = shift;
39 for ($str) { s/^\s+//; s/\s+$// }
40 return $str;
41 }
42
43 try();
44 done_testing();
0 <%augment wrap>
1 % sub { uc($_[0]) } {{
2 <% inner %>
3 % }}
4 </%augment>
0 <& plus.mi, num => 4, word => 'four' &>
0 <%class>
1 has ['num', 'word'];
2 </%class>
3
4 <% $.word %> plus <% $.word %> equals <% $.num + $.num %>
0 <& plus.mi, num => 2, word => 'two' &>