File Coverage

blib/lib/Mojolicious/Command/generate/controller.pm
Criterion Covered Total %
statement 9 15 60.0
branch 0 4 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 24 54.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   17482 use Mojo::Base 'Mojolicious::Command';
  1         7192  
  1         5  
4              
5             # version
6             our $VERSION = '0.01';
7              
8              
9 1     1   92473 use Mojolicious;
  1         162284  
  1         10  
10 1     1   33 use Mojo::Util qw(class_to_path);
  1         6  
  1         152  
11              
12             sub run {
13 0     0 1   my ($self, $class, $actions) = (shift, shift, [@_]);
14            
15             # error - controller name undef
16 0 0         die 'Controller class name cant be undef.' unless $class;
17            
18             # error - controller name malformed
19 0 0         die 'Your controller name has to be a well formed (CamelCase) like "MyController".'
20             unless $class =~ /^[A-Z](?:\w|::)+$/;
21              
22             # controller
23 0           my $controller = "${class}";
24 0           my $path = class_to_path $controller;
25              
26 0           $self->render_to_rel_file('controller', "lib/$path", $controller, $actions);
27             }
28            
29             1;
30              
31             __DATA__