Skip to content

Instantly share code, notes, and snippets.

@nisei
Last active October 3, 2017 07:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisei/3ce2caf2e1b77d1c2f77 to your computer and use it in GitHub Desktop.
Save nisei/3ce2caf2e1b77d1c2f77 to your computer and use it in GitHub Desktop.
CLI for Mojolicious
package Test::Web::CLI::Base;
use Mojo::Base qw/Mojolicious::Command/;
# public processing for CLI
sub get_data {
my $self = shift;
return 'data';
}
1;
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
BEGIN {
unshift @INC, "$FindBin::Bin/../lib";
$ENV{MOJO_HOME} = "$FindBin::Bin/../";
}
use Mojolicious::Commands;
my $cmd = Mojolicious::Commands->new;
$cmd->namespaces([qw/Test::Web::CLI/]);
$cmd->run(@ARGV);
package Test::Web::CLI::Testcli;
use Mojo::Base qw/Test::Web::CLI::Base/;
# Testcli command processing
# package name
sub run {
my ($self, @args) = @_;
my $data = $self->get_data;
print $args[0].$data;
}
$ perl cli.pl Testcli test
datatest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment