File Coverage

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


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