Acrux
view release on metacpan or search on metacpan
eg/acrux_test.pl view on Meta::CPAN
return 1;
});
1;
package main;
use Getopt::Long;
use IO::Handle;
use Acrux::Util qw/dumper color/;
# Get options from command line
Getopt::Long::Configure("bundling");
GetOptions(my $options = {},
"verbose|v", # Verbose mode
"debug|d", # Debug mode
"test|t", # Test mode
# Application
"noload|n", # NoLoad config file
"config|conf|c=s", # Config file
"datadir|dir|D=s", # DataDir
) || die color("bright_red" => 'Incorrect options'), "\n";
my $command = shift(@ARGV) // 'default';
my @arguments = @ARGV ? @ARGV : ();
# Create
my $app = MyApp->new(
project => 'MyApp',
preload => [qw/Config Log/], # disable preloading all system plugins
options => $options,
root => '.',
configfile => $options->{config} // 't/test.conf',
verbose => $options->{verbose},
debug => $options->{debug},
test => $options->{test},
#config_noload => 1,
loghandle => IO::Handle->new_from_fd(fileno(STDOUT), "w"),
logcolorize => 1
# ($options->{datadir} ? (datadir => $options->{datadir}) : ()),
);
# Check command
unless (grep {$_ eq $command} (@{ $app->handlers(1) })) {
die color("bright_red" => "No handler $command found") . "\n";
}
# Run
my $exitval = $app->run($command, @arguments) ? 0 : 1;
warn color("bright_red" => $app->error) . "\n" and exit $exitval if $exitval;
1;
package MyTestPlugin;
use warnings;
use strict;
use utf8;
our $VERSION = '0.01';
use parent 'Acme::Crux::Plugin';
use Acrux::Util qw/color/;
sub register {
my ($self, $app, $args) = @_;
print sprintf(color(bright_magenta => "Registered %s plugin"), $self->name), "\n";
$app->register_method(test => sub { print color(red => "This test method created in plugin register"), "\n" });
$app->log->debug(sprintf("Registered %s plugin", $self->name));
return sprintf 'Ok! I am %s plugin!', $self->name;
}
1;
__END__
( run in 0.599 second using v1.01-cache-2.11-cpan-524268b4103 )