Ado
view release on metacpan or search on metacpan
lib/Ado/Command/generate/crud.pm view on Meta::CPAN
=head2 description
my $description = $command->description;
$command = $command->description('Foo!');
Short description of this command, used for the command list.
=head2 routes
$self->routtes();
Returns an ARRAY reference containing routes, prepared after C<$self-E<gt>args-E<gt>{tables}>.
Altough L<Ado> already has defined generic routes for CRUD,
this attribute contains more specific routes, that will secure the C<create>,
C<update> and C<delete> actions, so they are available only to an
authenticated user. This attribute is used for generating routes in
L<Ado::Command::generate::adoplugin>.
After generating a plugin you should end up with a
L<RESTful|http://en.wikipedia.org/wiki/REST>
service. The generated code uses
L<Mojolicious::Controller/respond_to>. For details see
L<Mojolicious::Guides::Rendering/Content-negotiation>.
=head2 usage
my $usage = $command->usage;
$command = $command->usage('Foo!');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Ado::Command::generate::crud> inherits all methods from
L<Ado::Command> and implements the following new ones.
=head2 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 C<$self>.
=head2 run
Ado::Command::generate::crud->new(app=>$app)->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Ado::Command::generate::adoplugin>,
L<Ado::Command::generate::apache2vhost>,
L<Ado::Command::generate::apache2htaccess>, L<Ado::Command::generate>,
L<Mojolicious::Command::generate>, L<Getopt::Long>,
L<Ado::Command> L<Ado::Manual>,
L<Mojolicious>, L<Mojolicious::Guides::Cookbook/DEPLOYMENT>
=head1 AUTHOR
ÐÑаÑÐ¸Ð¼Ð¸Ñ ÐеÑов (Krasimir Berov)
=head1 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.
=cut
__DATA__
@@ class
% my $a = shift;
package <%= $a->{class} %>;
use Mojo::Base '<%= $a->{controller_namespace} %>';
our $VERSION = '0.01';
# Generate class on the fly from the database.
# No worries - this is cheap, one-time generation.
# See documentation for Ado::Model::class_from_table
my $table_class = Ado::Model->table_to_class(
namespace => '<%= $a->{model_namespace} %>',
table => '<%= $a->{t} %>',
type => 'TABLE'
);
# List resourses from table <%= $a->{t} %>.
sub list {
my $c = shift;
$c->require_formats('json','html') || return;
my $args = Params::Check::check(
{ limit => {
allow => sub { $_[0] =~ /^\d+$/ ? 1 : ($_[0] = 20); }
},
offset => {
allow => sub { $_[0] =~ /^\d+$/ ? 1 : defined($_[0] = 0); }
},
},
{ limit => $c->req->param('limit') || 20,
offset => $c->req->param('offset') || 0,
}
);
$c->res->headers->content_range(
"<%= $a->{t} %> $$args{offset}-${\($$args{limit} + $$args{offset})}/*");
$c->debug("rendering json and html only [$$args{limit}, $$args{offset}]");
#Used in template <%= $a->{t}%>/list.html.ep
( run in 1.507 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )