line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SweetPea::Cli::Make; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use SweetPea::Application; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
7
|
1
|
|
|
1
|
|
6
|
use SweetPea::Cli::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
8
|
1
|
|
|
1
|
|
3324
|
use SweetPea::Cli::Flash; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
9
|
1
|
|
|
1
|
|
23406
|
use SweetPea::Cli::Error; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
10
|
1
|
|
|
1
|
|
8499
|
use SweetPea::Cli::Help; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3817
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# SweetPea::Cli::Make - Application builder for use with SweetPea-Cli |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @return = ( |
15
|
|
|
|
|
|
|
'SweetPea application files were created successfully.', |
16
|
|
|
|
|
|
|
'', |
17
|
|
|
|
|
|
|
'Attention, you may need to fix permissions for generated files.', |
18
|
|
|
|
|
|
|
'Remember to secure your application, try the following commands:', |
19
|
|
|
|
|
|
|
'', |
20
|
|
|
|
|
|
|
'sudo chown -R www-data *', |
21
|
|
|
|
|
|
|
'sudo chmod -R 0700 *', |
22
|
|
|
|
|
|
|
'sudo chmod -R 0755 static/ .htaccess .routes .pl', |
23
|
|
|
|
|
|
|
'', |
24
|
|
|
|
|
|
|
'Next! Create database data profiles. See help data;' |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
29
|
0
|
|
|
|
|
|
my $self = {}; |
30
|
0
|
|
|
|
|
|
bless $self, $class; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $c = $self->{c} = shift; |
33
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
34
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$self->{commands} = [ |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
name => 'make', |
39
|
|
|
|
|
|
|
code => sub { |
40
|
0
|
|
|
0
|
|
|
$self->make(@_) |
41
|
|
|
|
|
|
|
}, |
42
|
0
|
|
|
|
|
|
args => { |
43
|
|
|
|
|
|
|
'script' => { |
44
|
|
|
|
|
|
|
aliases => ['s'] |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
'basic' => { |
47
|
|
|
|
|
|
|
aliases => ['b'] |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
'stack' => { |
50
|
|
|
|
|
|
|
aliases => ['f'] |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
'profile' => { |
53
|
|
|
|
|
|
|
aliases => ['p'] |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
help => 'generate a script, basic or full-stack app.' |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
]; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $self; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub make { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my $c = shift; |
66
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
67
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
68
|
0
|
|
|
|
|
|
my $u = SweetPea::Cli::Util->new; |
69
|
0
|
|
|
|
|
|
my $h = SweetPea::Cli::Help->new; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $type; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($c->options->{basic}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# build basic app |
75
|
0
|
|
|
|
|
|
return $self->basic($c); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif ($c->options->{script}) { |
78
|
|
|
|
|
|
|
# build script-only app |
79
|
0
|
|
|
|
|
|
return $self->script($c); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif ($c->options->{stack}) { |
82
|
|
|
|
|
|
|
# build full-stack app |
83
|
0
|
|
|
|
|
|
return $self->stack($c); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ($c->options->{profile}) { |
86
|
|
|
|
|
|
|
# build data profile |
87
|
0
|
|
|
|
|
|
return $self->profile($c); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
0
|
|
|
|
|
|
return $h->display('make', $c); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub script { |
97
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
98
|
0
|
|
|
|
|
|
my $c = shift; |
99
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
100
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
101
|
0
|
|
|
|
|
|
my $u = SweetPea::Cli::Util->new; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# make files |
104
|
0
|
|
|
|
|
|
$self->_write(0755, '.htaccess', 'generated/htaccess.tt'); |
105
|
0
|
|
|
|
|
|
$self->_write(0755, '.pl', 'generated/script/pl.tt'); |
106
|
0
|
|
|
|
|
|
$self->_write(0754, '.server', 'generated/server.tt'); |
107
|
0
|
|
|
|
|
|
$self->_write(0755, 'routes.pl', 'generated/routes.tt'); |
108
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Makefile.PL', 'generated/makefile.tt'); |
109
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/TODO', 'placeholder'); |
110
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Changes', 'placeholder'); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $f->flash(@return)->report($c); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub basic { |
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
|
my $c = shift; |
118
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
119
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
120
|
0
|
|
|
|
|
|
my $u = SweetPea::Cli::Util->new; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# make files |
123
|
0
|
|
|
|
|
|
$self->_write(0755, '.htaccess', 'generated/htaccess.tt'); |
124
|
0
|
|
|
|
|
|
$self->_write(0755, '.pl', 'generated/basic/pl.tt'); |
125
|
0
|
|
|
|
|
|
$self->_write(0754, '.server', 'generated/server.tt'); |
126
|
0
|
|
|
|
|
|
$self->_write(0755, 'routes.pl', 'generated/routes.tt'); |
127
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Controller/Root.pm', 'generated/controller/root.tt'); |
128
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Controller/Sweet.pm', 'generated/controller/basic/sweet.tt'); |
129
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Model/Schema.pm', 'generated/model/schema.tt'); |
130
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/View/Main.pm', 'generated/view/main.tt'); |
131
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/App.pm', 'generated/app.tt'); |
132
|
0
|
|
|
|
|
|
$self->_write(0777, 'sweet/sessions/empty', 'placeholder'); |
133
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/empty', 'placeholder'); |
134
|
0
|
|
|
|
|
|
$self->_write(0755, 'static/empty', 'placeholder'); |
135
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Makefile.PL', 'generated/makefile.tt'); |
136
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/TODO', 'placeholder'); |
137
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Changes', 'placeholder'); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return $f->flash(@return)->report($c); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub stack { |
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
144
|
0
|
|
|
|
|
|
my $c = shift; |
145
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
146
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# make files |
149
|
0
|
|
|
|
|
|
$self->_write(0755, '.htaccess', 'generated/htaccess.tt'); |
150
|
0
|
|
|
|
|
|
$self->_write(0755, '.pl', 'generated/stack/pl.tt'); |
151
|
0
|
|
|
|
|
|
$self->_write(0755, 'routes.pl', 'generated/routes.tt'); |
152
|
0
|
|
|
|
|
|
$self->_write(0754, '.server', 'generated/server.tt'); |
153
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Controller/Root.pm', 'generated/controller/root.tt'); |
154
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Controller/Sweet.pm', 'generated/controller/stack/sweet.tt'); |
155
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/Model/Schema.pm', 'generated/model/schema.tt'); |
156
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/application/View/Main.pm', 'generated/view/main.tt'); |
157
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/App.pm', 'generated/app.tt'); |
158
|
0
|
|
|
|
|
|
$self->_write(0777, 'sweet/sessions/empty', 'placeholder'); |
159
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/empty', 'placeholder'); |
160
|
0
|
|
|
|
|
|
$self->_write(0755, 'static/empty', 'placeholder'); |
161
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Makefile.PL', 'generated/makefile.tt'); |
162
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/TODO', 'placeholder'); |
163
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/Changes', 'placeholder'); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/configuration/datastores/development/empty', 'placeholder'); |
166
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/configuration/datastores/production/empty', 'placeholder'); |
167
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/configuration/application.yml', 'generated/config/application.tt'); |
168
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/configuration/datastores.yml', 'generated/config/datastores.tt'); |
169
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/configuration/permissions.yml', 'generated/config/permissions.tt'); |
170
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/locales/en.yml', 'generated/locale/english.tt'); |
171
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/elements/form.tt', 'generated/element/form.tt'); |
172
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/elements/grid.tt', 'generated/element/grid.tt'); |
173
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/layouts/default.tt', 'data'); |
174
|
0
|
|
|
|
|
|
$self->_write(0754, 'sweet/templates/index.tt', 'Now go be fruitful and multiply.'); |
175
|
0
|
|
|
|
|
|
$self->_write(0754, 'extras/t/00-load.t', 'generated/stack/test-00.tt'); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return $f->flash(@return)->report($c); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub profile { |
181
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
182
|
0
|
|
|
|
|
|
my $c = shift; |
183
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
184
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
185
|
0
|
|
|
|
|
|
my $u = SweetPea::Cli::Util->new; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
my $profile = $c->argv->[0]; |
188
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
|
if ($profile) { |
190
|
0
|
|
|
|
|
|
$profile =~ s/^[\\\/]+//; |
191
|
0
|
|
|
|
|
|
$profile =~ s/\.yml$//; |
192
|
0
|
|
|
|
|
|
$profile =~ s/\\/\//g; |
193
|
0
|
|
|
|
|
|
$profile .= '.yml'; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# make files |
196
|
0
|
|
|
|
|
|
$self->_write(0754, "sweet/configuration/$profile", 'generated/config/profile/new.tt'); |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my @return = ( |
199
|
|
|
|
|
|
|
"Data profile $profile created successfully." |
200
|
|
|
|
|
|
|
); |
201
|
0
|
|
|
|
|
|
return $f->flash(@return)->report($c); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
else { |
204
|
0
|
|
|
|
|
|
my @return = ( |
205
|
|
|
|
|
|
|
'No data profile specified. Use `help make;` for instructions.' |
206
|
|
|
|
|
|
|
); |
207
|
0
|
|
|
|
|
|
return $e->error(@return)->report($c); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub _write { |
212
|
0
|
|
|
0
|
|
|
my $self = shift; |
213
|
0
|
|
|
|
|
|
my ($mask, $to, $from, $type) = @_; |
214
|
0
|
|
|
|
|
|
my $f = SweetPea::Cli::Flash->new; |
215
|
0
|
|
|
|
|
|
my $e = SweetPea::Cli::Error->new; |
216
|
0
|
|
|
|
|
|
my $u = SweetPea::Cli::Util->new; |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
my $stash = { |
219
|
|
|
|
|
|
|
shebang => $^X, |
220
|
|
|
|
|
|
|
sver => $SweetPea::VERSION, |
221
|
|
|
|
|
|
|
saver => $SweetPea::Application::VERSION, |
222
|
|
|
|
|
|
|
head => '---', |
223
|
|
|
|
|
|
|
fruitful => 'Now go be fruitful and multiply.', |
224
|
|
|
|
|
|
|
}; |
225
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
my $content = ''; |
227
|
|
|
|
|
|
|
|
228
|
0
|
0
|
|
|
|
|
if ($from eq "placeholder") { |
|
|
0
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
$content = "placeholder"; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
elsif ($from eq "data") { |
232
|
0
|
|
|
|
|
|
$content .= $_ while (); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
else { |
235
|
0
|
0
|
|
|
|
|
if ($from !~ /\.tt$/) { |
236
|
0
|
|
|
|
|
|
$content = $from; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
else { |
239
|
0
|
|
|
|
|
|
$content = $u->template($from, $stash); |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
0
|
|
|
|
|
|
$u->makefile( |
244
|
|
|
|
|
|
|
'file' => $to, |
245
|
|
|
|
|
|
|
'content' => $content, |
246
|
|
|
|
|
|
|
'bitmask' => $mask |
247
|
|
|
|
|
|
|
); |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
1; # End of SweetPea::Cli::Make |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__DATA__ |