/usr/share/perl5/Mojolicious/Command/generate/app.pm is in libmojolicious-perl 2.23-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | package Mojolicious::Command::generate::app;
use Mojo::Base 'Mojo::Command';
has description => <<'EOF';
Generate Mojolicious application directory structure.
EOF
has usage => <<"EOF";
usage: $0 generate app [CLASS]
EOF
# "I say, you've damaged our servants quarters... and our servants."
sub run {
my ($self, $class) = @_;
$class ||= 'MyMojoliciousApp';
# Prevent bad applications
die <<EOF unless $class =~ /^[A-Z](?:\w|\:\:)+$/;
Your application name has to be a well formed (camel case) Perl module name
like "MyApp".
EOF
# Script
my $name = $self->class_to_file($class);
$self->render_to_rel_file('mojo', "$name/script/$name", $class);
$self->chmod_file("$name/script/$name", 0744);
# Appclass
my $app = $self->class_to_path($class);
$self->render_to_rel_file('appclass', "$name/lib/$app", $class);
# Controller
my $controller = "${class}::Example";
my $path = $self->class_to_path($controller);
$self->render_to_rel_file('controller', "$name/lib/$path", $controller);
# Test
$self->render_to_rel_file('test', "$name/t/basic.t", $class);
# Log
$self->create_rel_dir("$name/log");
# Static
$self->render_to_rel_file('static', "$name/public/index.html");
# Layout and Templates
$self->render_to_rel_file('layout',
"$name/templates/layouts/default.html.ep");
$self->render_to_rel_file('welcome',
"$name/templates/example/welcome.html.ep");
}
1;
__DATA__
@@ mojo
% my $class = shift;
#!/usr/bin/env perl
use Mojo::Base -strict;
use File::Basename 'dirname';
use File::Spec;
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), 'lib';
use lib join '/', File::Spec->splitdir(dirname(__FILE__)), '..', 'lib';
# Check if Mojolicious is installed;
die <<EOF unless eval 'use Mojolicious::Commands; 1';
It looks like you don't have the Mojolicious framework installed.
Please visit http://mojolicio.us for detailed installation instructions.
EOF
# Application
$ENV{MOJO_APP} ||= '<%= $class %>';
# Start commands
Mojolicious::Commands->start;
@@ appclass
% my $class = shift;
package <%= $class %>;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Documentation browser under "/perldoc"
$self->plugin('PODRenderer');
# Routes
my $r = $self->routes;
# Normal route to controller
$r->route('/welcome')->to('example#welcome');
}
1;
@@ controller
% my $class = shift;
package <%= $class %>;
use Mojo::Base 'Mojolicious::Controller';
# This action will render a template
sub welcome {
my $self = shift;
# Render template "example/welcome.html.ep" with message
$self->render(
message => 'Welcome to the Mojolicious real-time web framework!');
}
1;
@@ static
<!doctype html><html>
<head>
<title>Welcome to the Mojolicious real-time web framework!</title>
</head>
<body>
<h2>Welcome to the Mojolicious real-time web framework!</h2>
This is the static document "public/index.html",
<a href="/welcome">click here</a> to get back to the start.
</body>
</html>
@@ test
% my $class = shift;
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More tests => 4;
use Test::Mojo;
use_ok '<%= $class %>';
my $t = Test::Mojo->new('<%= $class %>');
$t->get_ok('/welcome')->status_is(200)->content_like(qr/Mojolicious/i);
@@ layout
<!doctype html><html>
<head><title><%%= title %></title></head>
<body><%%= content %></body>
</html>
@@ welcome
%% layout 'default';
%% title 'Welcome';
<h2><%%= $message %></h2>
This page was generated from the template
"templates/example/welcome.html.ep" and the layout
"templates/layouts/default.html.ep",
<a href="<%%== url_for %>">click here</a>
to reload the page or
<a href="/index.html">here</a>
to move forward to a static page.
__END__
=head1 NAME
Mojolicious::Command::generate::app - App generator command
=head1 SYNOPSIS
use Mojolicious::Command::generate::app;
my $app = Mojolicious::Command::generate::app->new;
$app->run(@ARGV);
=head1 DESCRIPTION
L<Mojolicious::Command::generate::app> is an application generator.
=head1 ATTRIBUTES
L<Mojolicious::Command::generate::app> inherits all attributes from
L<Mojo::Command> and implements the following new ones.
=head2 C<description>
my $description = $app->description;
$app = $app->description('Foo!');
Short description of this command, used for the command list.
=head2 C<usage>
my $usage = $app->usage;
$app = $app->usage('Foo!');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::generate::app> inherits all methods from
L<Mojo::Command> and implements the following new ones.
=head2 C<run>
$app->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
=cut
|