The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 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 Ado for the first time. You can dump them to disk if you want using the dsc_dump_schema.pl script that comes with DBIx::Simple::Class. You may decide to use only DBIx::Simple via the $c->dbix helper or DBI via $c->dbix->dbh. That's up to you.

This tool's purpose is to promote RAD by generating the boilerplate code for controllers (C) and help programmers new to Ado and Mojolicious to quickly create well structured, fully functional applications.

In the generated 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 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], usually 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.

H|home_dir=s

Defaults to $ENV{MOJO_HOME} (which is Ado home directory). Used to set the root directory to which the files will be dumped when generating an Ado plugin.

L|lib=s

Defaults to lib relative to the --home_dir directory. If you installed Ado in some custom path and you wish to generate your controllers into e.g. site_lib, use this option. Do not forget to add this directory to $ENV{PERL5LIB}, so the classes can be found and loaded.

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 plugins in etc/ado.conf or in your plugin configuration. Yes, multiple database connections/schemas are supported.

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 in your configuration file.

t|tables=s@

Mandatory. List of tables separated by commas for which controllers should be generated.

ATTRIBUTES

Ado::Command::generate::crud inherits all attributes from Ado::Command::generate and implements the following new ones.

description

  my $description = $command->description;
  $command        = $command->description('Foo!');

Short description of this command, used for the command list.

routes

  $self->routtes();

Returns an ARRAY reference containing routes, prepared after $self->args->{tables}.

Altough Ado already has defined generic routes for CRUD, this attribute contains more specific routes, that will secure the create, update and delete actions, so they are available only to an authenticated user. This attribute is used for generating routes in Ado::Command::generate::adoplugin. After generating a plugin 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.

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

  Ado::Command::generate::crud->new(app=>$app)->run(@ARGV);

Run this command.

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.