Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,102 @@
package Mojolicious::Command::Author::cpanify;
use Mojo::Base 'Mojolicious::Command';
use Mojo::File qw(path);
use Mojo::Util qw(getopt);
has description => 'Upload distribution to CPAN';
has usage => sub { shift->extract_usage };
sub run {
my ($self, @args) = @_;
die $self->usage unless getopt \@args,
'p|password=s' => \(my $password = ''),
'u|user=s' => \(my $user = '');
die $self->usage unless my $file = shift @args;
my $tx = $self->app->ua->tap(sub { $_->proxy->detect })->post(
"https://$user:$password\@pause.perl.org/pause/authenquery" => form => {
HIDDENNAME => $user,
CAN_MULTIPART => 1,
pause99_add_uri_upload => path($file)->basename,
SUBMIT_pause99_add_uri_httpupload => ' Upload this file from my disk ',
pause99_add_uri_uri => '',
pause99_add_uri_httpupload => {file => $file},
}
);
if (my $err = $tx->error) {
my $code = $tx->res->code // 0;
my $msg = $err->{message};
if ($code == 401) { $msg = 'Wrong username or password.' }
elsif ($code == 409) { $msg = 'File already exists on CPAN.' }
die qq{Problem uploading file "$file": $msg\n};
}
say 'Upload successful!';
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::cpanify - CPAN-ify command
=head1 SYNOPSIS
Usage: APPLICATION cpanify [OPTIONS] [FILE]
mojo cpanify -u sri -p secr3t Mojolicious-Plugin-MyPlugin-0.01.tar.gz
Options:
-h, --help Show this summary of available options
-p, --password <password> PAUSE password
-u, --user <name> PAUSE username
=head1 DESCRIPTION
L<Mojolicious::Command::Author::cpanify> uploads files to CPAN.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::cpanify> inherits all attributes from L<Mojolicious::Command> and implements the
following new ones.
=head2 description
my $description = $cpanify->description;
$cpanify = $cpanify->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $cpanify->usage;
$cpanify = $cpanify->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::cpanify> inherits all methods from L<Mojolicious::Command> and implements the following
new ones.
=head2 run
$cpanify->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut

View File

@@ -0,0 +1,87 @@
package Mojolicious::Command::Author::generate;
use Mojo::Base 'Mojolicious::Commands';
has description => 'Generate files and directories from templates';
has hint => <<EOF;
See 'APPLICATION generate help GENERATOR' for more information on a specific
generator.
EOF
has message => sub { shift->extract_usage . "\nGenerators:\n" };
has namespaces => sub { ['Mojolicious::Command::Author::generate'] };
sub help { shift->run(@_) }
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate - Generator command
=head1 SYNOPSIS
Usage: APPLICATION generate GENERATOR [OPTIONS]
mojo generate app
mojo generate lite-app
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate> lists available generators.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate> inherits all attributes from L<Mojolicious::Commands> and implements the
following new ones.
=head2 description
my $description = $generator->description;
$generator = $generator->description('Foo');
Short description of this command, used for the command list.
=head2 hint
my $hint = $generator->hint;
$generator = $generator->hint('Foo');
Short hint shown after listing available generator commands.
=head2 message
my $msg = $generator->message;
$generator = $generator->message('Bar');
Short usage message shown before listing available generator commands.
=head2 namespaces
my $namespaces = $generator->namespaces;
$generator = $generator->namespaces(['MyApp::Command::generate']);
Namespaces to search for available generator commands, defaults to L<Mojolicious::Command::Author::generate>.
=head1 METHODS
L<Mojolicious::Command::Author::generate> inherits all methods from L<Mojolicious::Commands> and implements the
following new ones.
=head2 help
$generator->help('app');
Print usage information for generator command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut

View File

@@ -0,0 +1,200 @@
package Mojolicious::Command::Author::generate::app;
use Mojo::Base 'Mojolicious::Command';
use Mojo::Util qw(class_to_file class_to_path decamelize);
has description => 'Generate Mojolicious application directory structure';
has usage => sub { shift->extract_usage };
sub run {
my ($self, $class) = (shift, shift || 'MyApp');
# Script
my $name = class_to_file $class;
$self->render_to_rel_file('mojo', "$name/script/$name", {class => $class});
$self->chmod_rel_file("$name/script/$name", 0744);
# Application class
my $app = class_to_path $class;
$self->render_to_rel_file('appclass', "$name/lib/$app", {class => $class});
# Config file (using the default moniker)
$self->render_to_rel_file('config', "$name/@{[decamelize $class]}.yml");
# Controller
my $controller = "${class}::Controller::Example";
my $path = class_to_path $controller;
$self->render_to_rel_file('controller', "$name/lib/$path", {class => $controller});
# Test
$self->render_to_rel_file('test', "$name/t/basic.t", {class => $class});
# Static file
$self->render_to_rel_file('static', "$name/public/index.html");
# 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;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate::app - App generator command
=head1 SYNOPSIS
Usage: APPLICATION generate app [OPTIONS] [NAME]
mojo generate app
mojo generate app TestApp
Options:
-h, --help Show this summary of available options
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate::app> generates application directory structures for fully functional
L<Mojolicious> applications.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate::app> inherits all attributes from L<Mojolicious::Command> and implements the
following new ones.
=head2 description
my $description = $app->description;
$app = $app->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $app->usage;
$app = $app->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::generate::app> inherits all methods from L<Mojolicious::Command> and implements the
following new ones.
=head2 run
$app->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut
__DATA__
@@ mojo
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::File qw(curfile);
use lib curfile->dirname->sibling('lib')->to_string;
use Mojolicious::Commands;
# Start command line interface for application
Mojolicious::Commands->start_app('<%= $class %>');
@@ appclass
package <%= $class %>;
use Mojo::Base 'Mojolicious', -signatures;
# This method will run once at server start
sub startup ($self) {
# Load configuration from config file
my $config = $self->plugin('NotYAMLConfig');
# Configure the application
$self->secrets($config->{secrets});
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to('example#welcome');
}
1;
@@ controller
package <%= $class %>;
use Mojo::Base 'Mojolicious::Controller', -signatures;
# This action will render a template
sub welcome ($self) {
# Render template "example/welcome.html.ep" with message
$self->render(msg => '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="/">click here</a> to get back to the start.
</body>
</html>
@@ test
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('<%= $class %>');
$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
done_testing();
@@ layout
<!DOCTYPE html>
<html>
<head><title><%%= title %></title></head>
<body><%%= content %></body>
</html>
@@ welcome
%% layout 'default';
%% title 'Welcome';
<h2><%%= $msg %></h2>
<p>
This page was generated from the template "templates/example/welcome.html.ep"
and the layout "templates/layouts/default.html.ep",
<%%= link_to 'click here' => url_for %> to reload the page or
<%%= link_to 'here' => '/index.html' %> to move forward to a static page.
</p>
@@ config
% use Mojo::Util qw(sha1_sum steady_time);
---
secrets:
- <%= sha1_sum $$ . steady_time . rand %>

View File

@@ -0,0 +1,87 @@
package Mojolicious::Command::Author::generate::dockerfile;
use Mojo::Base 'Mojolicious::Command';
use Mojo::File qw(path);
has description => 'Generate "Dockerfile"';
has usage => sub { shift->extract_usage };
sub run {
my $self = shift;
my $name = $self->app->moniker;
my $exe = $ENV{MOJO_EXE} ? path($ENV{MOJO_EXE})->to_rel($self->app->home)->to_string : "script/$name";
$self->render_to_rel_file('dockerfile', 'Dockerfile', {name => $name, cmd => "./$exe prefork"});
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate::dockerfile - Dockerfile generator command
=head1 SYNOPSIS
Usage: APPLICATION generate dockerfile [OPTIONS]
./myapp.pl generate dockerfile
./script/my_app generate dockerfile
Options:
-h, --help Show this summary of available options
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate::dockerfile> generates C<Dockerfile> for applications.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate::dockerfile> inherits all attributes from L<Mojolicious::Command> and
implements the following new ones.
=head2 description
my $description = $dockerfile->description;
$dockerfile = $dockerfile->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $dockerfile->usage;
$dockerfile = $dockerfile->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::generate::dockerfile> inherits all methods from L<Mojolicious::Command> and implements
the following new ones.
=head2 run
$dockerfile->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut
__DATA__
@@ dockerfile
FROM perl
WORKDIR /opt/<%= $name %>
COPY . .
RUN cpanm --installdeps -n .
EXPOSE 3000
CMD <%= $cmd %>

View File

@@ -0,0 +1,99 @@
package Mojolicious::Command::Author::generate::lite_app;
use Mojo::Base 'Mojolicious::Command';
has description => 'Generate Mojolicious::Lite application';
has usage => sub { shift->extract_usage };
sub run {
my ($self, $name) = (shift, shift || 'myapp.pl');
$self->render_to_rel_file('liteapp', $name);
$self->chmod_rel_file($name, 0744);
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate::lite_app - Lite app generator command
=head1 SYNOPSIS
Usage: APPLICATION generate lite-app [OPTIONS] [NAME]
mojo generate lite-app
mojo generate lite-app foo.pl
Options:
-h, --help Show this summary of available options
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate::lite_app> generate fully functional L<Mojolicious::Lite> applications.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate::lite_app> inherits all attributes from L<Mojolicious::Command> and implements
the following new ones.
=head2 description
my $description = $app->description;
$app = $app->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $app->usage;
$app = $app->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::generate::lite_app> inherits all methods from L<Mojolicious::Command> and implements
the following new ones.
=head2 run
$app->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut
__DATA__
@@ liteapp
#!/usr/bin/env perl
use Mojolicious::Lite -signatures;
get '/' => sub ($c) {
$c->render(template => 'index');
};
app->start;
<% %>__DATA__
<% %>@@ index.html.ep
%% layout 'default';
%% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
<% %>@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%%= title %></title></head>
<body><%%= content %></body>
</html>

View File

@@ -0,0 +1,86 @@
package Mojolicious::Command::Author::generate::makefile;
use Mojo::Base 'Mojolicious::Command';
has description => 'Generate "Makefile.PL"';
has usage => sub { shift->extract_usage };
sub run { shift->render_to_rel_file('makefile', 'Makefile.PL') }
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate::makefile - Makefile generator command
=head1 SYNOPSIS
Usage: APPLICATION generate makefile [OPTIONS]
./myapp.pl generate makefile
mojo generate makefile
Options:
-h, --help Show this summary of available options
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate::makefile> generates C<Makefile.PL> files for applications.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate::makefile> inherits all attributes from L<Mojolicious::Command> and implements
the following new ones.
=head2 description
my $description = $makefile->description;
$makefile = $makefile->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $makefile->usage;
$makefile = $makefile->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::generate::makefile> inherits all methods from L<Mojolicious::Command> and implements
the following new ones.
=head2 run
$makefile->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut
__DATA__
@@ makefile
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
VERSION => '0.01',
PREREQ_PM => {
'Mojolicious' => '<%= $Mojolicious::VERSION %>'
},
test => {TESTS => 't/*.t'}
);

View File

@@ -0,0 +1,174 @@
package Mojolicious::Command::Author::generate::plugin;
use Mojo::Base 'Mojolicious::Command';
use Mojo::Util qw(camelize class_to_path getopt);
has description => 'Generate Mojolicious plugin directory structure';
has usage => sub { shift->extract_usage };
sub run {
my ($self, @args) = @_;
die $self->usage unless getopt \@args, 'f|full' => \(my $full);
# Class
my $name = $args[0] // 'MyPlugin';
my $class = $full ? $name : "Mojolicious::Plugin::$name";
my $dir = join '-', split(/::/, $class);
my $app = class_to_path $class;
$self->render_to_rel_file('class', "$dir/lib/$app", {class => $class, name => $name});
# Test
$self->render_to_rel_file('test', "$dir/t/basic.t", {name => $name});
# Makefile
$self->render_to_rel_file('makefile', "$dir/Makefile.PL", {class => $class, path => $app});
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::generate::plugin - Plugin generator command
=head1 SYNOPSIS
Usage: APPLICATION generate plugin [OPTIONS] [NAME]
mojo generate plugin
mojo generate plugin TestPlugin
mojo generate plugin -f MyApp::Plugin::AwesomeFeature
Options:
-f, --full Do not prepend "Mojolicious::Plugin::" to the plugin name
-h, --help Show this summary of available options
=head1 DESCRIPTION
L<Mojolicious::Command::Author::generate::plugin> generates directory structures for fully functional L<Mojolicious>
plugins.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::generate::plugin> inherits all attributes from L<Mojolicious::Command> and implements
the following new ones.
=head2 description
my $description = $plugin->description;
$plugin = $plugin->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $plugin->usage;
$plugin = $plugin->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::generate::plugin> inherits all methods from L<Mojolicious::Command> and implements the
following new ones.
=head2 run
$plugin->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut
__DATA__
@@ class
package <%= $class %>;
use Mojo::Base 'Mojolicious::Plugin';
our $VERSION = '0.01';
sub register {
my ($self, $app) = @_;
}
1;
<% %>=encoding utf8
<% %>=head1 NAME
<%= $class %> - Mojolicious Plugin
<% %>=head1 SYNOPSIS
# Mojolicious
$self->plugin('<%= $name %>');
# Mojolicious::Lite
plugin '<%= $name %>';
<% %>=head1 DESCRIPTION
L<<%= $class %>> is a L<Mojolicious> plugin.
<% %>=head1 METHODS
L<<%= $class %>> inherits all methods from
L<Mojolicious::Plugin> and implements the following new ones.
<% %>=head2 register
$plugin->register(Mojolicious->new);
Register plugin in L<Mojolicious> application.
<% %>=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
<% %>=cut
@@ test
use Mojo::Base -strict;
use Test::More;
use Mojolicious::Lite;
use Test::Mojo;
plugin '<%= $name %>';
get '/' => sub {
my $c = shift;
$c->render(text => 'Hello Mojo!');
};
my $t = Test::Mojo->new;
$t->get_ok('/')->status_is(200)->content_is('Hello Mojo!');
done_testing();
@@ makefile
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => '<%= $class %>',
VERSION_FROM => 'lib/<%= $path %>',
AUTHOR => 'A Good Programmer <nospam@cpan.org>',
PREREQ_PM => {'Mojolicious' => '<%= $Mojolicious::VERSION %>'},
test => {TESTS => 't/*.t'}
);

View File

@@ -0,0 +1,96 @@
package Mojolicious::Command::Author::inflate;
use Mojo::Base 'Mojolicious::Command';
use Mojo::Loader qw(data_section file_is_binary);
use Mojo::Util qw(encode);
has description => 'Inflate embedded files to real files';
has usage => sub { shift->extract_usage };
sub run {
my $self = shift;
# Find all embedded files
my %all;
my $app = $self->app;
for my $class (@{$app->renderer->classes}, @{$app->static->classes}) {
for my $name (keys %{data_section $class}) {
my $data = data_section $class, $name;
$data = encode 'UTF-8', $data unless file_is_binary $class, $name;
$all{$name} = $data;
}
}
# Turn them into real files
for my $name (grep {/\.\w+$/} keys %all) {
my $prefix = $name =~ /\.\w+\.\w+$/ ? 'templates' : 'public';
$self->write_file($self->rel_file("$prefix/$name"), $all{$name});
}
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::Author::inflate - Inflate command
=head1 SYNOPSIS
Usage: APPLICATION inflate [OPTIONS]
./myapp.pl inflate
Options:
-h, --help Show this summary of available options
--home <path> Path to home directory of your application, defaults to
the value of MOJO_HOME or auto-detection
-m, --mode <name> Operating mode for your application, defaults to the
value of MOJO_MODE/PLACK_ENV or "development"
=head1 DESCRIPTION
L<Mojolicious::Command::Author::inflate> turns templates and static files embedded in the C<DATA> sections of your
application into real files.
This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
you're welcome to fork it.
See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
=head1 ATTRIBUTES
L<Mojolicious::Command::Author::inflate> inherits all attributes from L<Mojolicious::Command> and implements the
following new ones.
=head2 description
my $description = $inflate->description;
$inflate = $inflate->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $inflate->usage;
$inflate = $inflate->usage('Foo');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::Author::inflate> inherits all methods from L<Mojolicious::Command> and implements the following
new ones.
=head2 run
$inflate->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
=cut