| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Ado::Command::generate::adoplugin; |
|
2
|
3
|
|
|
3
|
|
1759
|
use Mojo::Base 'Ado::Command::generate'; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
15
|
|
|
3
|
3
|
|
|
3
|
|
323
|
use Mojo::Util qw(camelize class_to_path decamelize); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
140
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case); |
|
|
3
|
|
|
|
|
17
|
|
|
|
3
|
|
|
|
|
20
|
|
|
5
|
3
|
|
|
3
|
|
1054
|
use Time::Piece (); |
|
|
3
|
|
|
|
|
8397
|
|
|
|
3
|
|
|
|
|
63
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
125
|
|
|
7
|
3
|
|
|
3
|
|
15
|
use Cwd; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
1531
|
|
|
8
|
|
|
|
|
|
|
File::Spec::Functions->import(qw(catfile catdir)); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has description => "Generates directory structures for Ado-specific plugins..\n"; |
|
12
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
|
13
|
|
|
|
|
|
|
has crud => sub { |
|
14
|
|
|
|
|
|
|
require Ado::Command::generate::crud; |
|
15
|
|
|
|
|
|
|
Ado::Command::generate::crud->new(app => shift->app); |
|
16
|
|
|
|
|
|
|
}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub run { |
|
19
|
5
|
|
|
5
|
1
|
2311
|
my ($self, @args) = @_; |
|
20
|
5
|
|
|
|
|
23
|
my $args = $self->args; |
|
21
|
|
|
|
|
|
|
GetOptionsFromArray \@args, |
|
22
|
|
|
|
|
|
|
'n|name=s' => \$args->{name}, |
|
23
|
|
|
|
|
|
|
'c|crud' => \$args->{crud}, |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# CRUD options |
|
26
|
|
|
|
|
|
|
'C|controller_namespace=s' => \$args->{controller_namespace}, |
|
27
|
|
|
|
|
|
|
'L|lib=s' => \$args->{lib}, |
|
28
|
|
|
|
|
|
|
'M|model_namespace=s' => \$args->{model_namespace}, |
|
29
|
|
|
|
|
|
|
'O|overwrite' => \$args->{overwrite}, |
|
30
|
|
|
|
|
|
|
'T|templates_root=s' => \$args->{templates_root}, |
|
31
|
|
|
|
|
|
|
't|tables=s@' => \$args->{tables}, |
|
32
|
|
|
|
|
|
|
'H|home_dir=s' => \$args->{home_dir}, |
|
33
|
5
|
|
|
|
|
50
|
; |
|
34
|
|
|
|
|
|
|
|
|
35
|
5
|
100
|
|
|
|
3220
|
unless ($$args{name}) { |
|
36
|
1
|
|
|
|
|
8
|
croak $self->usage; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
4
|
100
|
100
|
|
|
24
|
if ($args->{crud} && !$args->{tables}) { |
|
39
|
1
|
|
|
|
|
231
|
croak 'Option --tables is mandatory when option --crud is passed!' . $/; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Class |
|
43
|
3
|
100
|
|
|
|
18
|
my $class = $$args{name} =~ /^[a-z]/ ? camelize($$args{name}) : $$args{name}; |
|
44
|
3
|
|
|
|
|
28
|
$class = "Ado::Plugin::$class"; |
|
45
|
3
|
|
|
|
|
12
|
my $path = class_to_path $class; |
|
46
|
3
|
|
|
|
|
37
|
my $dir = join '-', split '::', $class; |
|
47
|
3
|
|
|
|
|
35
|
$self->render_to_rel_file('class', "$dir/lib/$path", $class, $$args{name}); |
|
48
|
3
|
|
|
|
|
18556
|
my $decamelized = decamelize($$args{name}); |
|
49
|
|
|
|
|
|
|
|
|
50
|
3
|
100
|
|
|
|
68
|
if ($args->{crud}) { |
|
51
|
1
|
|
|
|
|
2
|
$args->{tables} = join(',', @{$args->{tables}}); |
|
|
1
|
|
|
|
|
6
|
|
|
52
|
1
|
|
33
|
|
|
16
|
$args->{home_dir} //= catdir(getcwd(), $dir); |
|
53
|
1
|
|
33
|
|
|
8
|
$args->{templates_root} //= catdir($args->{home_dir}, 'templates'); |
|
54
|
1
|
|
33
|
|
|
8
|
$args->{lib} //= catdir($args->{home_dir}, 'lib'); |
|
55
|
|
|
|
|
|
|
$self->crud->run( |
|
56
|
|
|
|
|
|
|
'-C' => $args->{controller_namespace}, |
|
57
|
|
|
|
|
|
|
'-L' => $args->{lib}, |
|
58
|
|
|
|
|
|
|
'-M' => $args->{model_namespace}, |
|
59
|
|
|
|
|
|
|
'-O' => $args->{overwrite}, |
|
60
|
|
|
|
|
|
|
'-T' => $args->{templates_root}, |
|
61
|
|
|
|
|
|
|
'-t' => $args->{tables}, |
|
62
|
|
|
|
|
|
|
'-H' => $args->{home_dir}, |
|
63
|
1
|
|
|
|
|
5
|
); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Test |
|
67
|
|
|
|
|
|
|
$self->render_to_rel_file('test', "$dir/t/plugin/$decamelized-00.t", |
|
68
|
3
|
|
|
|
|
20
|
$class, $$args{name}, $decamelized); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Build.PL |
|
71
|
3
|
|
|
|
|
6154
|
$self->render_to_rel_file('build_file', "$dir/Build.PL", $class, $path, $dir); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Configuration |
|
74
|
3
|
|
|
|
|
7035
|
$self->render_to_rel_file('config_file', "$dir/etc/plugins/$decamelized.conf", |
|
75
|
|
|
|
|
|
|
$decamelized, $self->crud, $args); |
|
76
|
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
2698
|
return $self; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=encoding utf8 |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Ado::Command::generate::adoplugin - Generates an Ado::Plugin |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
On the command-line: |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$ cd ~/opt/public_dev |
|
94
|
|
|
|
|
|
|
# Ado is "globally" installed for the current perlbrew Perl |
|
95
|
|
|
|
|
|
|
$ ado generate adoplugin --name MyBlog |
|
96
|
|
|
|
|
|
|
$ ado generate adoplugin --name MyBlog --crud -t 'articles,news' |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Programmatically: |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Ado::Command::generate::adoplugin; |
|
101
|
|
|
|
|
|
|
my $vhost = Ado::Command::generate::adoplugin->new; |
|
102
|
|
|
|
|
|
|
$vhost->run(-n => 'MyBlog', -c => 1, -t => 'articles,news'); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L generates directory structures for |
|
107
|
|
|
|
|
|
|
fully functional L-specific plugins with optional |
|
108
|
|
|
|
|
|
|
L in the newly created plugin directory. |
|
109
|
|
|
|
|
|
|
The new plugin is generated in the current directory. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This is a core command, that means it is always enabled and its code a |
|
112
|
|
|
|
|
|
|
more complex example for learning to build new commands. You're welcome to fork it. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 OPTIONS |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Below are the options this command accepts, described in L notation. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 n|name=s |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Mandatory. String. The name of the plugin. The resulting full class name is |
|
121
|
|
|
|
|
|
|
the camelized version of C. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 c|crud |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Boolean. When set you can pass in addition all the arguments accepted by |
|
126
|
|
|
|
|
|
|
L. It is mandatory to pass at least the |
|
127
|
|
|
|
|
|
|
C<--tables> option so the controllers can be generated. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
When generating a plugin: |
|
130
|
|
|
|
|
|
|
C<--controller_namespace> |
|
131
|
|
|
|
|
|
|
defaults to Croutes-Enamespaces-E[0]>; |
|
132
|
|
|
|
|
|
|
C<--home_dir> defaults to the plugin base directory; |
|
133
|
|
|
|
|
|
|
C<--lib> defaults to C in the plugin base directory; |
|
134
|
|
|
|
|
|
|
C<--model_namespace> defaults to L; |
|
135
|
|
|
|
|
|
|
C<--templates_root> defaults to C in the plugin base directory. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L inherits all attributes from |
|
140
|
|
|
|
|
|
|
L and implements the following new ones. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 crud |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#returns $self. |
|
145
|
|
|
|
|
|
|
$self->crud(Ado::Command::generate::crud->new(app => $self->app)) |
|
146
|
|
|
|
|
|
|
#returns Ado::Command::generate::crud instance. |
|
147
|
|
|
|
|
|
|
my $crud = $self->crud->run(%options); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
An instance of L. |
|
150
|
|
|
|
|
|
|
Used by L to generate routes for controllers |
|
151
|
|
|
|
|
|
|
and possibly others. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 description |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
my $description = $command->description; |
|
156
|
|
|
|
|
|
|
$command = $command->description('Foo!'); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Short description of this command, used for the command list. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 usage |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my $usage = $command->usage; |
|
163
|
|
|
|
|
|
|
$command = $command->usage('Foo!'); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Usage information for this command, used for the help screen. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 METHODS |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
L inherits all methods from |
|
170
|
|
|
|
|
|
|
L and implements the following new ones. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 run |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$plugin->run(@ARGV); |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Run this command. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L, |
|
181
|
|
|
|
|
|
|
L, |
|
182
|
|
|
|
|
|
|
L, |
|
183
|
|
|
|
|
|
|
L, L, |
|
184
|
|
|
|
|
|
|
L, L, |
|
185
|
|
|
|
|
|
|
L L, |
|
186
|
|
|
|
|
|
|
L, L |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Красимир Беров (Krasimir Berov) |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Copyright 2014 Красимир Беров (Krasimir Berov). |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or |
|
197
|
|
|
|
|
|
|
modify it under the terms of the |
|
198
|
|
|
|
|
|
|
GNU Lesser General Public License v3 (LGPL-3.0). |
|
199
|
|
|
|
|
|
|
You may copy, distribute and modify the software provided that |
|
200
|
|
|
|
|
|
|
modifications are open source. However, software that includes |
|
201
|
|
|
|
|
|
|
the license may release under a different license. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
See http://opensource.org/licenses/lgpl-3.0.html for more information. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__DATA__ |