Acrux
view release on metacpan or search on metacpan
lib/Acme/Crux.pm view on Meta::CPAN
my $timing_begin = [gettimeofday];
# ... long operations ...
my $elapsed = $app->elapsed( $timing_begin );
Return fractional amount of time in seconds since unnamed timstamp has been created while start application
my $elapsed = $app->elapsed;
$app->log->debug("Database stuff took $elapsed seconds");
For formatted output:
$app->log->debug(sprintf("%+.*f sec", 4, $app->elapsed));
=head2 error
my $error = $app->error;
Returns error string if occurred any errors while working with application
$app = $app->error( "error text" );
Sets new error message and returns object
=head2 exedir
my $exedir = $app->exedir;
Gets exedir value
=head2 handlers
my @names = $app->handlers;
Returns list of names of registered handlers
my @names_and_aliases = $app->handlers(1);
Returns list of aliases and names of registered handlers
=head2 lookup_handler
my $handler = $app->lookup_handler($name)
or die "Handler not found";
Lookup handler by name or aliase. Returns handler or undef while error
=head2 option, opt, getopt
my $value = $app->option("key");
Returns option value by key
my $options = $app->option;
Returns hash-ref structure to all options
See L</options>
=head2 orig
my $origin_args = $app->orig;
Returns hash-ref structure to all origin arguments
=head2 plugin
$app->plugin(foo => 'MyApp::Plugin::Foo');
$app->plugin(foo);
$app->plugin(foo => 'MyApp::Plugin::Foo', {bar => 123, baz => 'test'});
$app->plugin(foo => 'MyApp::Plugin::Foo', bar => 123, baz => 'test');
$app->plugin(foo, undef, {bar => 123, baz => 'test'});
Load a plugin by name or pair - name and class
=head2 pwd
my $pwd = $app->pwd;
This method returns current/working directory
=head2 register_handler
use parent qw/Acme::Crux/;
__PACKAGE__->register_handler(
handler => "foo",
aliases => "one, two",
description => "Foo handler",
params => {
param1 => "test",
param2 => 123,
},
code => sub {
### CODE:
my $self = shift; # App
my $meta = shift; # Meta data
my @args = @_; # Arguments
print Acrux::Util::dumper({
meta => $meta,
args => \@args,
});
return 1;
});
Method for register new handler
Example output while running:
$app->run('one', abc => 123, def => 456); # returns 1
{
"args" => ["abc", 123, "def", 456],
"meta" => {
"aliases" => ["one", "two"],
"description" => "Foo handler",
"name" => "foo",
"params" => {
"param1" => "test",
"param2" => 123
}
},
( run in 0.899 second using v1.01-cache-2.11-cpan-f56aa216473 )