| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Module::Setup::Helper; |
|
2
|
3
|
|
|
3
|
|
15511
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
182
|
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
94
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use base 'Module::Setup::Flavor'; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
1969
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
26
|
use Module::Setup; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
1659
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
6
|
|
|
6
|
0
|
549
|
my($class, %args) = @_; |
|
10
|
6
|
|
|
|
|
45
|
my $self = bless { |
|
11
|
|
|
|
|
|
|
argv => [], |
|
12
|
|
|
|
|
|
|
options => {}, |
|
13
|
|
|
|
|
|
|
%args, |
|
14
|
|
|
|
|
|
|
}, $class; |
|
15
|
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
54
|
$self->{options}->{flavor_class} = "+$class"; |
|
17
|
|
|
|
|
|
|
|
|
18
|
6
|
|
|
|
|
38
|
$self->helper_base_init; |
|
19
|
6
|
|
|
|
|
35
|
$self->helper_flavor_init; |
|
20
|
6
|
|
|
|
|
38
|
$self; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
sub helper_base_init { |
|
23
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
|
24
|
6
|
|
|
|
|
11
|
$self->{options}->{module} = shift @{ $self->{argv} }; |
|
|
6
|
|
|
|
|
24
|
|
|
25
|
|
|
|
|
|
|
} |
|
26
|
4
|
|
|
4
|
1
|
7
|
sub helper_flavor_init {} |
|
27
|
3
|
|
|
3
|
1
|
10
|
sub helper_default_plugins { qw/ Template Helper / } |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
1
|
0
|
sub helper_option_prefix { die "$_[0] class is not implement helper_option_prefix method" } |
|
30
|
2
|
|
|
2
|
0
|
8
|
sub generate_path_option_names { qw// } |
|
31
|
1
|
|
|
1
|
1
|
9
|
sub is_append_files { 0 } |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub run { |
|
34
|
3
|
|
|
3
|
0
|
29
|
my $self = shift; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# set the direct run mode |
|
37
|
3
|
|
|
|
|
13
|
$self->{options}->{direct} = 1; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# add default plugins |
|
40
|
3
|
|
50
|
|
|
33
|
$self->{options}->{plugins} ||= []; |
|
41
|
3
|
|
|
|
|
5
|
push @{ $self->{options}->{plugins} }, $self->helper_default_plugins; |
|
|
3
|
|
|
|
|
31
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
25
|
$self->before_run; |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
33
|
my $setup = Module::Setup->new( |
|
46
|
3
|
|
|
|
|
9
|
argv => [ $self->{options}->{module}, @{ $self->{argv} } ], |
|
47
|
|
|
|
|
|
|
options => $self->{options}, |
|
48
|
|
|
|
|
|
|
helper => $self->{helper}, |
|
49
|
|
|
|
|
|
|
); |
|
50
|
3
|
|
|
|
|
20
|
$setup->run; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
3
|
|
|
3
|
1
|
6
|
sub before_run {} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Module::Setup::Helper - build in your application helper support |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
script/helper.pl is your helper script |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use strict; |
|
66
|
|
|
|
|
|
|
use warnings; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $type = shift @ARGV; |
|
69
|
|
|
|
|
|
|
my $helper = "YourApp::Helper::$type"; |
|
70
|
|
|
|
|
|
|
eval "use $helper"; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$helper->new( |
|
73
|
|
|
|
|
|
|
argv => [ @ARGV ], |
|
74
|
|
|
|
|
|
|
options => { |
|
75
|
|
|
|
|
|
|
# Module::Setup's options |
|
76
|
|
|
|
|
|
|
}, |
|
77
|
|
|
|
|
|
|
helper => { |
|
78
|
|
|
|
|
|
|
option => 'FOO_OPTION', |
|
79
|
|
|
|
|
|
|
}, |
|
80
|
|
|
|
|
|
|
)->run; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
lib/YourApp/Helper.pm is your application helper base class. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
package YourApp::Helper; |
|
85
|
|
|
|
|
|
|
use strict; |
|
86
|
|
|
|
|
|
|
use warnings; |
|
87
|
|
|
|
|
|
|
use base 'Module::Setup::Helper'; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# make your application's options name prefix |
|
90
|
|
|
|
|
|
|
sub helper_option_prefix { 'yourapp' } |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub helper_base_init { |
|
93
|
|
|
|
|
|
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# auto detect app module name by Makefile.PL |
|
96
|
|
|
|
|
|
|
open my $fh, '<', 'Makefile.PL' or die $!; |
|
97
|
|
|
|
|
|
|
local $/; |
|
98
|
|
|
|
|
|
|
my $makefile = <$fh>; |
|
99
|
|
|
|
|
|
|
my($module) = $makefile =~ /all_from 'lib/(.+).pm'/; |
|
100
|
|
|
|
|
|
|
unless ($module) { |
|
101
|
|
|
|
|
|
|
return $self->{options}->{module} = shift @{ $self->{argv} }; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
$module =~ s{/}{::}g; |
|
104
|
|
|
|
|
|
|
$self->{options}->{module} = $module; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
lib/YourApp/Helper/Controller.pm is your application helper for controller |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
package YourApp::Helper::Controller; |
|
114
|
|
|
|
|
|
|
use strict; |
|
115
|
|
|
|
|
|
|
use warnings; |
|
116
|
|
|
|
|
|
|
use base 'YourApp::Helper'; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub generate_path_option_names { qw/ target / } |
|
119
|
|
|
|
|
|
|
sub is_append_files { 1 } # append type helper |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub helper_flavor_init { |
|
122
|
|
|
|
|
|
|
my $self = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# auto detect target name by @ARGV |
|
125
|
|
|
|
|
|
|
my $target = $self->{argv}->[0]; |
|
126
|
|
|
|
|
|
|
die 'required target name' unless $target; |
|
127
|
|
|
|
|
|
|
$self->{helper}->{target} = $target; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__DATA__ |
|
133
|
|
|
|
|
|
|
--- |
|
134
|
|
|
|
|
|
|
file: lib/____var-module_path-var____/Controller/____var-yourapp_target_path-var____.pm |
|
135
|
|
|
|
|
|
|
template: | |
|
136
|
|
|
|
|
|
|
package [% module %]::Controller::[% yourapp_target %]; |
|
137
|
|
|
|
|
|
|
use base 'YourApp::Controller'; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my $option = '[% yourapp_option %]'; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
... some code |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
|
144
|
|
|
|
|
|
|
file: t/100_controller/____var-yourapp_target_path-var____.t |
|
145
|
|
|
|
|
|
|
template: | |
|
146
|
|
|
|
|
|
|
use Test::More tests => 1; |
|
147
|
|
|
|
|
|
|
use_ok '[% yourapp_app %]::Controller::[% yourapp_target %]'; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
run the script/helper.pl |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$ perl ./script/helper.pl Controller Search |
|
152
|
|
|
|
|
|
|
$ cat lib/Foo/Controller/Search.pm |
|
153
|
|
|
|
|
|
|
package Foo::Controller::Search; |
|
154
|
|
|
|
|
|
|
use base 'YourApp::Controller'; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $option = 'FOO_OPTION'; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
... some code |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
|
161
|
|
|
|
|
|
|
$ cat t/100_controller/Search.t |
|
162
|
|
|
|
|
|
|
use Test::More tests => 1; |
|
163
|
|
|
|
|
|
|
use_ok 'Foo::Controller::Search'; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 Helper Hook Point |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 helper_option_prefix (required) |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
When using config of helper by template, prefix specified here is used. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub helper_option_prefix { 'foo' } |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
in your flavor's template |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
[% foo_bar %] |
|
176
|
|
|
|
|
|
|
# use the $self->{helper}->{bar} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 is_append_files |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
When this function returns truth, flavor is added to the existing application. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub is_append_files { 1 } # default is false |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
It is the same work as the time helper of adding Controller of Catalyst. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 helper_base_init |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
helper initialize phase for your application helper base class |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# default |
|
191
|
|
|
|
|
|
|
sub helper_base_init { |
|
192
|
|
|
|
|
|
|
my $self = shift; |
|
193
|
|
|
|
|
|
|
$self->{options}->{module} = shift @{ $self->{argv} }; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
you can set the base module name |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 helper_flavor_init |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
helper initialize phase for flavor class |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub helper_flavor_init { |
|
203
|
|
|
|
|
|
|
my $self = shift; |
|
204
|
|
|
|
|
|
|
$self->{helper} = { |
|
205
|
|
|
|
|
|
|
# some options for helper |
|
206
|
|
|
|
|
|
|
}; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
you can set the target module name, or more options for helper |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head3 $helper->{helper}->{setup_template_vars_callback} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
you can set the callback for setup_template_vars phase |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub helper_flavor_init { |
|
216
|
|
|
|
|
|
|
my $self = shift; |
|
217
|
|
|
|
|
|
|
# set callback handler for setup_template_vars hook point |
|
218
|
|
|
|
|
|
|
$self->{helper}->{setup_template_vars_callback} = sub { |
|
219
|
|
|
|
|
|
|
my($setup, $vars) = @_; |
|
220
|
|
|
|
|
|
|
$vars->{callback_var} = 'this is callback var'; |
|
221
|
|
|
|
|
|
|
$vars->{callback_path} = 'callback/path'; |
|
222
|
|
|
|
|
|
|
}; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
example is C |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 helper_default_plugins |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Plugin which helper uses is listed. |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# default |
|
232
|
|
|
|
|
|
|
sub helper_default_plugins { qw/ Template Helper / } |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 before_run |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
It is a phase just before helper actually starts Module::Setup. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |