File Coverage

blib/lib/Mojolicious/Command/Author/generate/app.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition 1 2 50.0
subroutine 3 3 100.0
pod 1 1 100.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Mojolicious::Command::Author::generate::app;
2 1     1   7 use Mojo::Base 'Mojolicious::Command';
  1         2  
  1         6  
3              
4 1     1   10 use Mojo::Util qw(class_to_file class_to_path decamelize);
  1         2  
  1         390  
5              
6             has description => 'Generate Mojolicious application directory structure';
7             has usage => sub { shift->extract_usage };
8              
9             sub run {
10 1   50 1 1 68 my ($self, $class) = (shift, shift || 'MyApp');
11              
12             # Script
13 1         7 my $name = class_to_file $class;
14 1         21 $self->render_to_rel_file('mojo', "$name/script/$name", {class => $class});
15 1         17 $self->chmod_rel_file("$name/script/$name", 0744);
16              
17             # Application class
18 1         10 my $app = class_to_path $class;
19 1         10 $self->render_to_rel_file('appclass', "$name/lib/$app", {class => $class});
20              
21             # Config file (using the default moniker)
22 1         7 $self->render_to_rel_file('config', "$name/@{[decamelize $class]}.conf");
  1         6  
23              
24             # Controller
25 1         6 my $controller = "${class}::Controller::Example";
26 1         7 my $path = class_to_path $controller;
27 1         9 $self->render_to_rel_file('controller', "$name/lib/$path",
28             {class => $controller});
29              
30             # Test
31 1         12 $self->render_to_rel_file('test', "$name/t/basic.t", {class => $class});
32              
33             # Static file
34 1         10 $self->render_to_rel_file('static', "$name/public/index.html");
35              
36             # Templates
37 1         9 $self->render_to_rel_file('layout',
38             "$name/templates/layouts/default.html.ep");
39 1         9 $self->render_to_rel_file('welcome',
40             "$name/templates/example/welcome.html.ep");
41             }
42              
43             1;
44              
45             =encoding utf8
46              
47             =head1 NAME
48              
49             Mojolicious::Command::Author::generate::app - App generator command
50              
51             =head1 SYNOPSIS
52              
53             Usage: APPLICATION generate app [OPTIONS] [NAME]
54              
55             mojo generate app
56             mojo generate app TestApp
57              
58             Options:
59             -h, --help Show this summary of available options
60              
61             =head1 DESCRIPTION
62              
63             L generates application directory
64             structures for fully functional L applications.
65              
66             This is a core command, that means it is always enabled and its code a good
67             example for learning to build new commands, you're welcome to fork it.
68              
69             See L for a list of commands that are
70             available by default.
71              
72             =head1 ATTRIBUTES
73              
74             L inherits all attributes from
75             L and implements the following new ones.
76              
77             =head2 description
78              
79             my $description = $app->description;
80             $app = $app->description('Foo');
81              
82             Short description of this command, used for the command list.
83              
84             =head2 usage
85              
86             my $usage = $app->usage;
87             $app = $app->usage('Foo');
88              
89             Usage information for this command, used for the help screen.
90              
91             =head1 METHODS
92              
93             L inherits all methods from
94             L and implements the following new ones.
95              
96             =head2 run
97              
98             $app->run(@ARGV);
99              
100             Run this command.
101              
102             =head1 SEE ALSO
103              
104             L, L, L.
105              
106             =cut
107              
108             __DATA__