Ado
view release on metacpan or search on metacpan
lib/Ado/Command/generate/adoplugin.pm view on Meta::CPAN
unless ($$args{name}) {
croak $self->usage;
}
if ($args->{crud} && !$args->{tables}) {
croak 'Option --tables is mandatory when option --crud is passed!' . $/;
}
# Class
my $class = $$args{name} =~ /^[a-z]/ ? camelize($$args{name}) : $$args{name};
$class = "Ado::Plugin::$class";
my $path = class_to_path $class;
my $dir = join '-', split '::', $class;
$self->render_to_rel_file('class', "$dir/lib/$path", $class, $$args{name});
my $decamelized = decamelize($$args{name});
if ($args->{crud}) {
$args->{tables} = join(',', @{$args->{tables}});
$args->{home_dir} //= catdir(getcwd(), $dir);
$args->{templates_root} //= catdir($args->{home_dir}, 'templates');
$args->{lib} //= catdir($args->{home_dir}, 'lib');
$self->crud->run(
'-C' => $args->{controller_namespace},
'-L' => $args->{lib},
'-M' => $args->{model_namespace},
'-O' => $args->{overwrite},
'-T' => $args->{templates_root},
'-t' => $args->{tables},
'-H' => $args->{home_dir},
);
}
# Test
$self->render_to_rel_file('test', "$dir/t/plugin/$decamelized-00.t",
$class, $$args{name}, $decamelized);
# Build.PL
$self->render_to_rel_file('build_file', "$dir/Build.PL", $class, $path, $dir);
# Configuration
$self->render_to_rel_file('config_file', "$dir/etc/plugins/$decamelized.conf",
$decamelized, $self->crud, $args);
return $self;
}
1;
=pod
=encoding utf8
=head1 NAME
Ado::Command::generate::adoplugin - Generates an Ado::Plugin
=head1 SYNOPSIS
On the command-line:
$ cd ~/opt/public_dev
# Ado is "globally" installed for the current perlbrew Perl
$ ado generate adoplugin --name MyBlog
$ ado generate adoplugin --name MyBlog --crud -t 'articles,news'
Programmatically:
use Ado::Command::generate::adoplugin;
my $vhost = Ado::Command::generate::adoplugin->new;
$vhost->run(-n => 'MyBlog', -c => 1, -t => 'articles,news');
=head1 DESCRIPTION
L<Ado::Command::generate::adoplugin> generates directory structures for
fully functional L<Ado>-specific plugins with optional
L<MVC set of files|Ado::Command::generate::crud> in the newly created plugin directory.
The new plugin is generated in the current directory.
This is a core command, that means it is always enabled and its code a
more complex example for learning to build new commands. You're welcome to fork it.
=head1 OPTIONS
Below are the options this command accepts, described in L<Getopt::Long> notation.
=head2 n|name=s
Mandatory. String. The name of the plugin. The resulting full class name is
the camelized version of C<Ado::Plugin::$$args{name}>.
=head2 c|crud
Boolean. When set you can pass in addition all the arguments accepted by
L<Ado::Command::generate::crud>. It is mandatory to pass at least the
C<--tables> option so the controllers can be generated.
When generating a plugin:
C<--controller_namespace>
defaults to C<app-E<gt>routes-E<gt>namespaces-E<gt>[0]>;
C<--home_dir> defaults to the plugin base directory;
C<--lib> defaults to C<lib> in the plugin base directory;
C<--model_namespace> defaults to L<Ado::Model>;
C<--templates_root> defaults to C<templates> in the plugin base directory.
=head1 ATTRIBUTES
L<Ado::Command::generate::adoplugin> inherits all attributes from
L<Ado::Command::generate> and implements the following new ones.
=head2 crud
#returns $self.
$self->crud(Ado::Command::generate::crud->new(app => $self->app))
#returns Ado::Command::generate::crud instance.
my $crud = $self->crud->run(%options);
An instance of L<Ado::Command::generate::crud>.
Used by L<Ado::Command::generate::adoplugin> to generate routes for controllers
and possibly others.
=head2 description
my $description = $command->description;
$command = $command->description('Foo!');
Short description of this command, used for the command list.
=head2 usage
my $usage = $command->usage;
( run in 1.385 second using v1.01-cache-2.11-cpan-5a3173703d6 )