File Coverage

blib/lib/Mojolicious/Command/generate/controller.pm
Criterion Covered Total %
statement 9 17 52.9
branch 0 4 0.0
condition n/a
subroutine 3 5 60.0
pod 1 1 100.0
total 13 27 48.1


line stmt bran cond sub pod time code
1             package Mojolicious::Command::generate::controller;
2             # ABSTRACT: Mojolicious command generator for controllers
3 1     1   13552 use Mojo::Base 'Mojolicious::Command';
  1         6821  
  1         4  
4            
5             # version
6             our $VERSION = '0.02';
7              
8 1     1   81220 use Mojolicious;
  1         140687  
  1         8  
9 1     1   30 use Mojo::Util qw(class_to_path);
  1         4  
  1         197  
10              
11              
12             has description => 'This aplication generate controller classes';
13             has usage => sub{ shift->_show_usage };
14              
15             sub run {
16 0     0 1   my ($self, $class, $actions) = (shift, shift, [@_]);
17            
18 0 0         $self->usage unless $class;
19            
20             # error - controller name malformed
21 0 0         die 'Your controller name has to be a well formed (CamelCase) like "MyController".'
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             sub _show_usage {
32 0     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;
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 generates controller directory
67             structure, file and action methods for a L class.
68              
69             This command extends core command b to help developers criating
70             quickly controller class files.
71              
72             See L for a list of commands that are
73             available by default.
74            
75             =head1 ATTRIBUTES
76            
77             L inherits all attributes from
78             L 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 inherits all methods from
89             L 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, L, L.
100            
101             =head1 AUTHOR
102              
103             Daniel Vinciguerra
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__