line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MasonX::ProcessDir; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
873
|
$MasonX::ProcessDir::VERSION = '0.02'; |
4
|
|
|
|
|
|
|
} |
5
|
2
|
|
|
2
|
|
1166
|
use Mason; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moose; |
7
|
|
|
|
|
|
|
use strict; |
8
|
|
|
|
|
|
|
use warnings; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Any::Template::ProcessDir'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '+ignore_files' => ( default => sub { sub { $_[0] =~ /Base\.|\.mason|\.mi$/ } } ); |
13
|
|
|
|
|
|
|
has '+template_file_suffix' => ( default => '.mc' ); |
14
|
|
|
|
|
|
|
has 'mason' => ( is => 'ro', init_arg => undef, lazy_build => 1 ); |
15
|
|
|
|
|
|
|
has 'mason_options' => ( is => 'ro', default => sub { {} } ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_mason { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $source_dir = $self->source_dir; |
21
|
|
|
|
|
|
|
my %options = ( |
22
|
|
|
|
|
|
|
comp_root => $source_dir, |
23
|
|
|
|
|
|
|
data_dir => "$source_dir/.mason", |
24
|
|
|
|
|
|
|
%{ $self->mason_options } |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
return Mason->new(%options); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _build_process_file { |
30
|
|
|
|
|
|
|
return sub { |
31
|
|
|
|
|
|
|
my ( $file, $self ) = @_; |
32
|
|
|
|
|
|
|
my $comp_path = substr( $file, length( $self->source_dir ), -3 ); |
33
|
|
|
|
|
|
|
return $self->mason->run($comp_path)->output; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MasonX::ProcessDir - Process a directory of Mason 2 templates |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 VERSION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
version 0.02 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use MasonX::ProcessDir; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Generate result files in the same directory as the templates |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
my $pd = MasonX::ProcessDir->new( |
58
|
|
|
|
|
|
|
dir => '/path/to/dir' |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
$pd->process_dir(); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Generate result files in a separate directory |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
my $pd = MasonX::ProcessDir->new( |
65
|
|
|
|
|
|
|
source_dir => '/path/to/source/dir', |
66
|
|
|
|
|
|
|
dest_dir => '/path/to/dest/dir' |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
$pd->process_dir(); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Recursively processes a directory of L<Mason 2|Mason> templates, generating a |
73
|
|
|
|
|
|
|
set of result files in the same directory or in a parallel directory. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Every file with suffix ".mc" will be processed, and the results placed in a |
76
|
|
|
|
|
|
|
file of the same name without the suffix. ".mi", autobase and dhandler files |
77
|
|
|
|
|
|
|
will be used by Mason when processing the templates but will not generate files |
78
|
|
|
|
|
|
|
themselves. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
For example, if the source directory contains |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Base.mc |
83
|
|
|
|
|
|
|
httpd.conf.mc |
84
|
|
|
|
|
|
|
proxy.conf.mc |
85
|
|
|
|
|
|
|
etc/crontab.mc |
86
|
|
|
|
|
|
|
blah.mi |
87
|
|
|
|
|
|
|
somefile.txt |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
and we run |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $pd = MasonX::ProcessDir->new( |
92
|
|
|
|
|
|
|
source_dir => '/path/to/source/dir', |
93
|
|
|
|
|
|
|
dest_dir => '/path/to/dest/dir' |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
$pd->process_dir(); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
then afterwards the destination directory will contain files |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
httpd.conf |
100
|
|
|
|
|
|
|
proxy.conf |
101
|
|
|
|
|
|
|
etc/crontab |
102
|
|
|
|
|
|
|
somefile.txt |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
where I<foo> and I<bar> are the results of processing I<foo.mc> and I<bar.mc> |
105
|
|
|
|
|
|
|
through Mason. I<Base.mc> and I<blah.mi> may be used during Mason processing |
106
|
|
|
|
|
|
|
but won't generate result files themselves. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This class is a convenience extension of |
109
|
|
|
|
|
|
|
L<Any::Template::ProcessDir|Any::Template::ProcessDir>. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 Specifying directory/directories |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
If you want to generate the result files in the B<same> directory as the |
120
|
|
|
|
|
|
|
templates, just specify I<dir>. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $pd = MasonX::ProcessDir->new( |
123
|
|
|
|
|
|
|
dir => '/path/to/dir', |
124
|
|
|
|
|
|
|
... |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
If you want to generate the result files in a B<separate> directory from the |
130
|
|
|
|
|
|
|
templates, specify I<source_dir> and I<dest_dir>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $pd = MasonX::ProcessDir->new( |
133
|
|
|
|
|
|
|
source_dir => '/path/to/source/dir', |
134
|
|
|
|
|
|
|
source_dir => '/path/to/dest/dir', |
135
|
|
|
|
|
|
|
... |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 Mason options |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item mason_options |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
An optional hash of options to the Mason interpreter. For example, the default |
147
|
|
|
|
|
|
|
Mason data directory will be ".mason" under the source directory, but you can |
148
|
|
|
|
|
|
|
override this: |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
mason_options => { data_dir => '/path/to/data/dir' } |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 Options inherited from Any::Template::ProcessDir |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
See L<Any::Template::ProcessDir> for other options, such as |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
dir_create_mode |
159
|
|
|
|
|
|
|
file_create_mode |
160
|
|
|
|
|
|
|
readme_filename |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SUPPORT AND DOCUMENTATION |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Bugs and feature requests will be tracked at RT: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MasonX-ProcessDir |
167
|
|
|
|
|
|
|
bug-masonx-processdir@rt.cpan.org |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The latest source code can be browsed and fetched at: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
http://github.com/jonswar/perl-masonx-processdir |
172
|
|
|
|
|
|
|
git clone git://github.com/jonswar/perl-masonx-processdir.git |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<Mason>, L<Any::Template::ProcessDir> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Jonathan Swartz <swartz@pobox.com> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Jonathan Swartz. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
187
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |
193
|
|
|
|
|
|
|
|