Ado
view release on metacpan or search on metacpan
lib/Ado/Command/generate/crud.pm view on Meta::CPAN
$self->render_to_file('create_template', $t_file, $args);
$t_file = catfile($template_root, $template_dir, 'read.html.ep');
$self->render_to_file('read_template', $t_file, $args);
$t_file = catfile($template_root, $template_dir, 'delete.html.ep');
$self->render_to_file('delete_template', $t_file, $args);
} # end foreach tables
return $self;
}
1;
=pod
=encoding utf8
=head1 NAME
Ado::Command::generate::crud - Generates MVC set of files
=head1 SYNOPSIS
Usage:
#on the command-line
# for one or more tables.
$ bin/ado generate crud --tables='news,articles'
#programatically
use Ado::Command::generate::crud;
my $v = Ado::Command::generate::crud->new;
$v->run(-t => 'news,articles');
=head1 DESCRIPTION
B<Disclaimer: I<This command is highly experimental!>
The generated code is not even expected to work properly.>
L<Ado::Command::generate::crud> generates directory structure for
a fully functional
L<MVC|http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller>
set of files, based on existing tables in the database.
You only need to create the tables. The Model (M) classes are generated on the fly
from the tables when the controller classes are loaded by L<Ado> for the first time.
You can dump them to disk if you want using the C<dsc_dump_schema.pl> script that
comes with L<DBIx::Simple::Class>. You may decide to use only L<DBIx::Simple>
via the C<$c-E<gt>dbix> helper or L<DBI> via C<$c-E<gt>dbix-E<gt>dbh>.
That's up to you.
This tool's purpose is to promote
L<RAD|http://en.wikipedia.org/wiki/Rapid_application_development>
by generating the boilerplate code for controllers (C)
and help programmers new to L<Ado> and L<Mojolicious> to quickly create
well structured, fully functional applications.
In the generated actions you will find I<eventually working> code
for reading, creating, updating and deleting records from the tables you
specified on the command-line.
The generated code is just boilerplate to give you a jump start, so you can
concentrate on writing your business-specific code. It is assumed that you will
modify the generated code to suit your specific needs.
=head1 OPTIONS
Below are the options this command accepts, described in L<Getopt::Long> notation.
=head2 C|controller_namespace=s
Optional. The namespace for the controller classes to be generated.
Defaults to C<app-E<gt>routes-E<gt>namespaces-E<gt>[0]>, usually
L<Ado::Control>. If you decide to use another namespace for the controllers,
do not forget to add it to the list C<app-E<gt>routes-E<gt>namespaces>
in C<etc/ado.conf> or your plugin configuration file.
=head2 H|home_dir=s
Defaults to C<$ENV{MOJO_HOME}> (which is Ado home directory).
Used to set the root directory to which the files
will be dumped when L<generating an Ado plugin|Ado::Command::generate::adoplugin>.
=head2 L|lib=s
Defaults to C<lib> relative to the C<--home_dir> directory.
If you installed L<Ado> in some custom path and you wish to generate your controllers into
e.g. C<site_lib>, use this option. Do not forget to add this
directory to C<$ENV{PERL5LIB}>, so the classes can be found and loaded.
=head2 M|model_namespace=s
Optional. The namespace for the model classes to be generated.
Defaults to L<Ado::Model>. If you wish however to use another namespace
for another database, you will have to add another item for
L<Mojolicious::Plugin::DSC> to the list of loaded plugins in C<etc/ado.conf>
or in your plugin configuration. Yes, multiple database connections/schemas
are supported.
=head2 T|templates_root=s
Defaults to C<app-E<gt>renderer-E<gt>paths-E<gt>[0]>. This is usually
C<site_templates> directory. If you want to use another directory,
do not forget to add it to the C<app-E<gt>renderer-E<gt>paths> list
in your configuration file.
=head2 t|tables=s@
Mandatory. List of tables separated by commas for which controllers should be generated.
=head1 ATTRIBUTES
L<Ado::Command::generate::crud> inherits all attributes from
L<Ado::Command::generate> and implements the following new ones.
=head2 description
my $description = $command->description;
$command = $command->description('Foo!');
Short description of this command, used for the command list.
( run in 1.811 second using v1.01-cache-2.11-cpan-99c4e6809bf )