| 1 | package Mojolicious::Command::generate::controller; | ||||||||||
| 2 | # ABSTRACT: Mojolicious command generator for controllers | ||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | # version | ||||||||||
| 6 | 1 | our $VERSION = '0.02'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Mojolicious; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Mojo::Util qw(class_to_path); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | 1 | has description => 'This aplication generate controller classes'; | |||||||||
| 13 | 0 | ▶ | has usage => sub{ shift->_show_usage }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 16 | 0 | my ($self, $class, $actions) = (shift, shift, [@_]); | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | $self->usage unless $class; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | # error - controller name malformed | ||||||||||
| 21 | 0 | ▶ | die 'Your controller name has to be a well formed (CamelCase) like "MyController".' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | unless $class =~ /^[A-Z](?:\w|::)+$/; | ||||||||||
| 23 | |||||||||||
| 24 | # controller | ||||||||||
| 25 | 0 | my $controller = "${class}"; | |||||||||
| 26 | 0 | my $path = class_to_path $controller; | |||||||||
| 27 | |||||||||||
| 28 | 0 | $self->render_to_rel_file('controller', "lib/$path", $controller, $actions); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub _show_usage { | ||||||||
|
Subroutine
_show_usage: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 0 | say qq{ | |||||||||
| 33 | Usage: APPLICATION generate controller [CONTROLLER] [ACTION_LIST] | ||||||||||
| 34 | |||||||||||
| 35 | mojo generate controller MyAPP::Controller::User | ||||||||||
| 36 | mojo generate controller MyAPP::Controller::User index create show update remove | ||||||||||
| 37 | |||||||||||
| 38 | Options: | ||||||||||
| 39 | -h, --help Show this summary of available options | ||||||||||
| 40 | }; | ||||||||||
| 41 | |||||||||||
| 42 | 0 | exit; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | 1; | |||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | =encoding utf8 | ||||||||||
| 49 | |||||||||||
| 50 | =head1 NAME | ||||||||||
| 51 | |||||||||||
| 52 | Mojolicious::Command::generate::controller - Controller generator command | ||||||||||
| 53 | |||||||||||
| 54 | =head1 SYNOPSIS | ||||||||||
| 55 | |||||||||||
| 56 | Usage: APPLICATION generate controller [CONTROLLER] [ACTION_LIST] | ||||||||||
| 57 | |||||||||||
| 58 | mojo generate controller MyAPP::Controller::User | ||||||||||
| 59 | mojo generate controller MyAPP::Controller::User index create show update remove | ||||||||||
| 60 | |||||||||||
| 61 | Options: | ||||||||||
| 62 | -h, --help Show this summary of available options | ||||||||||
| 63 | |||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||
| 65 | |||||||||||
| 66 | L<Mojolicious::Command::generate::controller> generates controller directory | ||||||||||
| 67 | structure, file and action methods for a L<Mojolicious::Controller> class. | ||||||||||
| 68 | |||||||||||
| 69 | This command extends core command b<generate> to help developers criating | ||||||||||
| 70 | quickly controller class files. | ||||||||||
| 71 | |||||||||||
| 72 | See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are | ||||||||||
| 73 | available by default. | ||||||||||
| 74 | |||||||||||
| 75 | =head1 ATTRIBUTES | ||||||||||
| 76 | |||||||||||
| 77 | L<Mojolicious::Command::generate::controller> inherits all attributes from | ||||||||||
| 78 | L<Mojolicious::Command> and implements the following new ones. | ||||||||||
| 79 | |||||||||||
| 80 | =head2 usage | ||||||||||
| 81 | |||||||||||
| 82 | my $usage = $app->usage; | ||||||||||
| 83 | |||||||||||
| 84 | Usage information for this command, used for the help screen. | ||||||||||
| 85 | |||||||||||
| 86 | =head1 METHODS | ||||||||||
| 87 | |||||||||||
| 88 | L<Mojolicious::Command::generate::controller> inherits all methods from | ||||||||||
| 89 | L<Mojolicious::Command> and implements the following new ones. | ||||||||||
| 90 | |||||||||||
| 91 | =head2 run | ||||||||||
| 92 | |||||||||||
| 93 | $app->run(@ARGV); | ||||||||||
| 94 | |||||||||||
| 95 | Run this command. | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SEE ALSO | ||||||||||
| 98 | |||||||||||
| 99 | L<Mojolicious::Command>, L<Mojolicious::Guides>, L<http://mojolicious.org>. | ||||||||||
| 100 | |||||||||||
| 101 | =head1 AUTHOR | ||||||||||
| 102 | |||||||||||
| 103 | Daniel Vinciguerra <daniel.vinciguerra@bivee.com.br> | ||||||||||
| 104 | |||||||||||
| 105 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 106 | |||||||||||
| 107 | This software is copyright (c) 2016 by Daniel Vinciguerra. | ||||||||||
| 108 | |||||||||||
| 109 | This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | __DATA__ | ||||||||||