Good news, everyone! After 20 years of living in the pre-Perl 5.10 cold of
the CGI.pm universe, I've spent only a few months basking in the glory of
modern perl and Mojolicious. Meaning the code that follows may be terrible,
so please be nice. :)
I initial wrote this to make it easier to switch between development
projects without having to clutter up my projects with launcher scripts or
juggle environment settings and command line switches.
Now I think it would be fun to submit it to CPAN for CPAN Day as my first
module, and would like any feedback on making it better, and if the name is
too official or would pollute the namespace (I'd happily rename it).
package Mojolicious::Command::morbo;
use Mojo::Base 'Mojolicious::Command';
# Kittens give Morbo gas.
use Mojo::Server::Morbo;
has description => 'Start Morbo via application configuration';
has usage => sub { shift->extract_usage };
sub run {
my ($self, @args) = @_;
my $morbo = Mojo::Server::Morbo->new;
my $config = $self->app->config->{morbo};
if (_is_defined_arrayref($config->{listen})) {
$ENV{MOJO_LISTEN} = join ',', @{$config->{listen}};
}
if (defined $config->{mode}) {
$ENV{MOJO_MODE} = $config->{mode};
}
if (defined $config->{proxy}) {
$ENV{MOJO_REVERSE_PROXY} = $config->{proxy} ? 1 : 0;
}
if (defined $config->{verbose}) {
$ENV{MORBO_VERBOSE} = $config->{verbose} ? 1 : 0;
}
if (_is_defined_arrayref($config->{watch})) {
my $watch = $config->{watch};
if ($$watch[0] eq '+') {
shift @$watch;
push @$watch, @{$morbo->watch};
}
$morbo->watch($watch);
}
$morbo->run($ENV{MOJO_EXE});
}
sub _is_defined_arrayref { return (defined $_[0] && ref $_[0] eq 'ARRAY' &&
scalar(@{$_[0]}) > 0); }
1;
=encoding utf8
=head1 NAME
Mojolicious::Command::morbo - Morbo command
=head1 SYNOPSIS
Usage: APPLICATION morbo
# myapp.conf
morbo => {
listen => ['https://*:443','http://[::]:3000'],
mode => 'production',
proxy => 1,
verbose => 1,
watch => ['just','these','dirs']
}
# Mojolicious::Lite
plugin Config => {
default => {
morbo => {
listen => ['https://*:443','http://[::]:3000'],
...
watch => ['+','more','dirs']
}
}
}
# Replace default watched directories
watch => ['just','these','dirs']
# Append to default watched directories
watch => ['+','more','dirs']
=head1 DESCRIPTION
L<Mojolicious::Command::morbo> starts applications with
L<Mojo::Server::Morbo>
using the application's configuration.
All settings are optional. Boolean settings that effect evironment variables
will clobber existing values even when set to false.
=head1 ATTRIBUTES
L<Mojolicious::Command::morbo> inherits all attributes from
L<Mojolicious::Command> and implements the following new ones.
=head2 description
my $description = $morbo->description;
$morbo = $morbo->description('Foo!');
Short description of this command, used for the command list.
=head2 usage
my $usage = $morbo->usage;
$morbo = $morbo->usage('Foo!');
Usage information for this command, used for the help screen.
=head1 METHODS
L<Mojolicious::Command::morbo> inherits all methods from
L<Mojolicious::Command> and implements the following new ones.
=head2 run
$morbo->run(@ARGV);
Run this command.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
=cut
Thank you!
V
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.