NAME
Ado::Command::generate::crud - Generates MVC set of files
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');
DESCRIPTION
Disclaimer: This command is highly experimental! The generated code is not even expected to work properly.
Ado::Command::generate::crud generates directory structure for a fully functional MVC set of files, based on existing tables in the database. You should have already created the tables in the database. This tool's purpose is to promote RAD and help programmers new to Ado and Mojolicious to quickly create well structured, fully functional applications.
Internally this generator uses DBIx::Simple::Class::Schema to generate on the fly the classes, used to manipulate the tables' records, if they are not already generated. If the Model classes already exist, it creates only the controller classes and templates.
Altough Ado already have defined generic routes for CRUD, this command will generate more specific routes (if used through Ado::Command::generate::adoplugin), that will secure the create
, update
and delete
actions, so they are available only to an authenticated user. After executing the command you should end up with a RESTful service. The generated code uses "respond_to" in Mojolicious::Controller. For details see "Content-negotiation" in Mojolicious::Guides::Rendering.
In the actions you will find eventually working code for reading, creating, updating and deleting records from the tables you specified on the command-line. The generated code uses DBIx::Simple::Class-based classes.
In addition, example code is created that uses only DBIx::Simple. In case you prefer to use only DBIx::Simple and not DBIx::Simple::Class, use the option 'N|no_dsc_code'
. If you want pure DBI, write the code your self.
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.
OPTIONS
Below are the options this command accepts, described in Getopt::Long notation.
C|controller_namespace=s
Optional. The namespace for the controller classes to be generated. Defaults to app->routes->namespaces->[0]
, usuallly Ado::Control. If you decide to use another namespace for the controllers, do not forget to add it to the list app->routes->namespaces
in etc/ado.conf
or your plugin configuration file.
d|dsn=s
Optional. Connection string parsed using "parse_dsn" in DBI and passed to "connect" in DBIx::Simple. See also "dsn" in Mojolicious::Plugin::DSC. By default the connection to the application database is used.
L|lib_root=s
Defaults to lib
relative to the current dierctory. If you installed Ado in some custom path and you wish to set it to e.g. site_lib
, use this option. Do not forget to add this directory to $ENV{PERL5LIB}
, so the classes can be found by perl
.
M|model_namespace=s
Optional. The namespace for the model classes to be generated. Defaults to Ado::Model. If you wish however to use another namespace for another database, you will have to add another item for Mojolicious::Plugin::DSC to the list of loaded pligins in etc/ado.conf
or in your plugin configuration. Yes, multiple database connections/schemas are supported.
N|no_dsc_code
Boolean. If this option is passed the previous option (M|model_namespace=s) is ignored. No table classes will be generated.
O|overwrite
If there are already generated files they will be overwritten.
P|password=s
Password for the database to connect to. Needed only when dsn
argument is passed and the database requires a password.
T|templates_root=s
Defaults to app->renderer->paths->[0]
. This is usually site_templates
directory. If you want to use another directory, do not forget to add it to the app->renderer->paths
list.
t|tables=s@
Mandatory. Passing '%' would mean all the tables from the specified database with the d|dsn=s
option or the Ado database. Note that existing Ado::Model classes will not be overwritten even if you specify O|overwrite
.
U|user=s
Username for the database to connect to. Needed only when dsn
argument is passed and the database requires a username.
ATTRIBUTES
Ado::Command::generate::crud inherits all attributes from Ado::Command::generate and implements the following new ones.
app
$crud->app($c->app);
my $app = $crud->app;
An instance of Ado.
description
my $description = $command->description;
$command = $command->description('Foo!');
Short description of this command, used for the command list.
usage
my $usage = $command->usage;
$command = $command->usage('Foo!');
Usage information for this command, used for the help screen.
METHODS
Ado::Command::generate::crud inherits all methods from Ado::Command and implements the following new ones.
initialise
sub run {
my ($self) = shift->initialise(@_);
#...
}
Parses arguments and prepares the command to be run. Calling this method for the second time has no effect. Returns $self
.
run
$plugin->run(@ARGV);
Run this command.
TODO
Add authentication checks to update and delete actions.
SEE ALSO
Ado::Command::generate::adoplugin, Ado::Command::generate::apache2vhost, Ado::Command::generate::apache2htaccess, Ado::Command::generate, Mojolicious::Command::generate, Getopt::Long, Ado::Command Ado::Manual, Mojolicious, "DEPLOYMENT" in Mojolicious::Guides::Cookbook
AUTHOR
Красимир Беров (Krasimir Berov)
COPYRIGHT AND LICENSE
Copyright 2014 Красимир Беров (Krasimir Berov).
This program is free software, you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License v3 (LGPL-3.0). You may copy, distribute and modify the software provided that modifications are open source. However, software that includes the license may release under a different license.
See http://opensource.org/licenses/lgpl-3.0.html for more information.