line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Helper; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Helper.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
37
|
|
|
37
|
|
209276
|
use strict; |
|
37
|
|
|
|
|
86
|
|
|
37
|
|
|
|
|
1533
|
|
8
|
37
|
|
|
37
|
|
210
|
use warnings; |
|
37
|
|
|
|
|
57
|
|
|
37
|
|
|
|
|
1248
|
|
9
|
37
|
|
|
37
|
|
241
|
use Carp qw/ croak /; |
|
37
|
|
|
|
|
71
|
|
|
37
|
|
|
|
|
2791
|
|
10
|
37
|
|
|
37
|
|
295
|
use base qw/ Egg::Helper::Util::Base /; |
|
37
|
|
|
|
|
67
|
|
|
37
|
|
|
|
|
26161
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION= '3.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$SIG{__DIE__}= sub { Egg::Error->throw(@_) }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %A= ( |
17
|
|
|
|
|
|
|
project => 'Build::Project', |
18
|
|
|
|
|
|
|
vtest => 'Util::VirtualProject', |
19
|
|
|
|
|
|
|
tester => 'Util::Tester', |
20
|
|
|
|
|
|
|
tools => 'Util::Tools', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
my %Alias= ( |
23
|
|
|
|
|
|
|
B => 'Build', |
24
|
|
|
|
|
|
|
C => 'Controller', |
25
|
|
|
|
|
|
|
D => 'Dispatch', |
26
|
|
|
|
|
|
|
H => 'Helper', |
27
|
|
|
|
|
|
|
L => 'Log', |
28
|
|
|
|
|
|
|
M => 'Model', |
29
|
|
|
|
|
|
|
P => 'Plugin', |
30
|
|
|
|
|
|
|
R => 'Response', |
31
|
|
|
|
|
|
|
U => 'Util', |
32
|
|
|
|
|
|
|
V => 'View', |
33
|
|
|
|
|
|
|
m => 'Module', |
34
|
|
|
|
|
|
|
r => 'Request', |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
my($modenow, $contextnow); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub run { |
39
|
0
|
|
|
0
|
|
|
my $class= shift; |
40
|
0
|
|
0
|
|
|
|
my $mode = ucfirst(shift) || croak q{ I want 'MODE'. }; |
41
|
0
|
|
0
|
|
|
|
my $attr = shift || {}; |
42
|
0
|
0
|
|
|
|
|
if (my $a= $A{lc $mode}) { $mode= $a } |
|
0
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($mode=~m{^([A-Za-z])[\:\-]+}) { |
44
|
0
|
0
|
|
|
|
|
if (my $alias= $Alias{$1}) { $mode=~s{^[^\:\-]+} [$alias] } |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
$mode=~s{\-} [::]g; |
47
|
0
|
|
|
|
|
|
$mode=~s{([^\:])\:([^\:])} [$1.'::'.$2]eg; |
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$mode=~s{\:([a-z])} [':'. ucfirst($1)]eg; |
|
0
|
|
|
|
|
|
|
49
|
0
|
0
|
0
|
|
|
|
($modenow and $modenow eq $mode) |
50
|
|
|
|
|
|
|
and die qq{ '$modenow' mode is operating. }; |
51
|
0
|
0
|
|
|
|
|
if ($contextnow) { |
52
|
0
|
|
|
|
|
|
my %conf= ( |
53
|
0
|
|
0
|
|
|
|
%{$contextnow->config}, |
54
|
|
|
|
|
|
|
project_name => ($attr->{project_name} || undef), |
55
|
|
|
|
|
|
|
helper_option=> $attr, |
56
|
|
|
|
|
|
|
); |
57
|
0
|
|
|
|
|
|
$contextnow->config(\%conf); |
58
|
0
|
|
|
|
|
|
return $contextnow->_start_helper; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
my $pkg= "Egg::Helper::$mode"; |
61
|
0
|
0
|
|
|
|
|
$pkg->require || return $class->_helper_help( |
|
|
0
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$@=~/^\s*Can\'t\s+locate/ |
63
|
|
|
|
|
|
|
? qq{ Typing error of mode name. [$mode] } |
64
|
|
|
|
|
|
|
: qq{ Script error: $@ } |
65
|
|
|
|
|
|
|
); |
66
|
0
|
|
|
|
|
|
my $plugins; |
67
|
0
|
0
|
|
|
|
|
if (my $loads= $pkg->can('_helper_load_plugins')) { |
68
|
0
|
|
0
|
|
|
|
$plugins= $loads->() || []; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
|
$plugins= []; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
$contextnow= $class->_helper_context($pkg, $plugins, $attr); |
73
|
0
|
|
|
|
|
|
$contextnow->_start_helper; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
sub helper_tools { |
76
|
0
|
|
|
0
|
|
|
my $class= shift; |
77
|
0
|
|
|
|
|
|
$class->_helper_context('Egg::Helper::Dummy', [], @_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
sub _helper_context { |
80
|
0
|
|
|
0
|
|
|
my($class, $pkg, $plugins)= splice @_, 0, 3; |
81
|
0
|
0
|
0
|
|
|
|
my $attr = $_[1] ? {@_}: ($_[0] || {}); |
82
|
0
|
|
0
|
|
|
|
my $handler= $ENV{EGG_HELPER_CLASS} || 'Egg::Helper::Project'; |
83
|
0
|
|
|
|
|
|
$attr->{start_dir}= $class->helper_current_dir; |
84
|
0
|
|
0
|
|
|
|
$attr->{project_root} ||= $class->helper_tempdir || $attr->{start_dir}; |
|
|
|
0
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$attr->{root}= $attr->{project_root}; |
86
|
0
|
|
0
|
|
|
|
$handler->__import($pkg, $plugins, { |
87
|
|
|
|
|
|
|
project_name => ($attr->{project_name_orign} || 'EggHelper'), |
88
|
|
|
|
|
|
|
root => $attr->{project_root}, |
89
|
|
|
|
|
|
|
start_dir => $attr->{start_dir}, |
90
|
|
|
|
|
|
|
helper_option=> $attr, |
91
|
|
|
|
|
|
|
}); |
92
|
0
|
|
|
|
|
|
$handler->new; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
sub helper_script { |
95
|
0
|
|
|
0
|
|
|
print STDOUT <<SCRIPT; |
96
|
0
|
|
|
|
|
|
#!@{[ Egg::Helper::Util::Base->helper_perl_path ]} |
97
|
|
|
|
|
|
|
use Egg::Helper; |
98
|
|
|
|
|
|
|
Egg::Helper->run( shift(\@ARGV) ); |
99
|
|
|
|
|
|
|
SCRIPT |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
*out= \&helper_script; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package Egg::Helper::Project; |
104
|
37
|
|
|
37
|
|
322
|
use strict; |
|
37
|
|
|
|
|
136
|
|
|
37
|
|
|
|
|
1629
|
|
105
|
37
|
|
|
37
|
|
238
|
use warnings; |
|
37
|
|
|
|
|
99
|
|
|
37
|
|
|
|
|
5647
|
|
106
|
|
|
|
|
|
|
require Egg; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
our @ISA= qw/ Egg::Helper::Util::Base /; |
109
|
|
|
|
|
|
|
our $START_DIR; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub __import { |
112
|
0
|
|
|
0
|
|
|
my($class, $pkg, $plugins, $attr)= @_; |
113
|
0
|
|
|
|
|
|
$ENV{"EGG::HELPER::PROJECT_DISPATCH_CLASS"}= 0; |
114
|
0
|
|
|
|
|
|
Egg->import(@$plugins); |
115
|
0
|
|
|
|
|
|
unshift @ISA, $pkg; |
116
|
0
|
|
|
|
|
|
__PACKAGE__->_startup($attr); |
117
|
37
|
|
|
37
|
|
242
|
no strict 'refs'; ## no critic. |
|
37
|
|
|
|
|
73
|
|
|
37
|
|
|
|
|
1501
|
|
118
|
37
|
|
|
37
|
|
214
|
no warnings 'redefine'; |
|
37
|
|
|
|
|
1459
|
|
|
37
|
|
|
|
|
27953
|
|
119
|
0
|
|
|
0
|
|
|
*{"${class}::namespace"}= sub { $_[0]->config->{project_name} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
*{"${class}::project_name"}= $class->can('namespace'); |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
0
|
|
|
|
$START_DIR= $attr->{start_dir} || ""; |
122
|
0
|
|
|
|
|
|
$class; |
123
|
|
|
|
|
|
|
} |
124
|
37
|
50
|
|
37
|
|
374
|
END { chdir($START_DIR) if $START_DIR }; ## no critic. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package Egg::Helper::Dummy; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 NAME |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Egg::Helper - Helper module for Egg. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DESCRIPTION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This module is started by the helper script. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 Helper of standard appending. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * L<Egg::Helper::Build::Module >. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
The template of the Perl module is generated. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * L<Egg::Helper::Build::Plugin>. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
The template of the plug-in module is generated. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * L<Egg::Helper::Build::Project>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The project is constructed. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * L<Egg::Helper::Build::Prototype>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
'prototype.js' etc. are output. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * L<Egg::Helper::Config::YAML>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The model of the configuration of the YAML form is generated. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * L<Egg::Helper::Util::Tester>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Test of project application. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * L<Egg::Helper::Util::VirtualProject>. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Virtual project for package test. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 METHODS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 run |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
When the helper script is started, this method is called. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 helper_tools |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Especially, nothing is done. Helper object is only returned. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
The thing used to cause some actions as the file is made before the |
185
|
|
|
|
|
|
|
L<Egg::Helper::Util::VirtualProject> object is acquired in the package |
186
|
|
|
|
|
|
|
test etc. is assumed. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
use Egg::Helper; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $tool= Egg::Helper->helper_tools; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
$tool->helper_create_file(join '', <DATA>); |
193
|
|
|
|
|
|
|
..... |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
It is a project object that this method returns that succeeds to |
196
|
|
|
|
|
|
|
L<Egg::Helper::Util::Base>. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 helper_script |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The code of the helper scripting to generate the project is returned. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
To generate the helper script, as follows is done. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
% perl -MEgg::Helper -e 'Egg::Helper->helper_script' > /path/to/egg_helper.pl |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
I think that the generated script is convenient when it outputs to the place that |
207
|
|
|
|
|
|
|
passing passed, and the execution attribute is given at the right time. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
And, the project is generated as follows. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
% egg_helper.pl project [PROJECT_NAME] -o/path/to |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over 4 |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * Alias = out |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 SEE ALSO |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
L<Egg>, |
222
|
|
|
|
|
|
|
L<Egg::Release>, |
223
|
|
|
|
|
|
|
L<Egg::Helper::Util::Base>, |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 AUTHOR |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
234
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
235
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|