Acrux
view release on metacpan or search on metacpan
eg/acrux_std.pl view on Meta::CPAN
# perl -Ilib eg/acrux_std.pl noop
package MyApp;
use parent 'Acme::Crux';
use Acrux::Util qw/dumper color/;
our $VERSION = '1.00';
sub startup {
my $self = shift;
print color(green => "Start application"), "\n" ;
return $self;
}
DESTROY {
my $el = sprintf("%+.*f sec", 4, shift->elapsed);
print color(green => "Finish application ($el)"), "\n" ;
eg/acrux_test.pl view on Meta::CPAN
# perl -Ilib eg/acrux_test.pl test 1 2 3
package MyApp;
use parent 'Acme::Crux';
use Acrux::Util qw/dumper color/;
our $VERSION = '1.00';
sub startup {
my $self = shift;
print sprintf(color(green => "Start application %s"), $self->project), "\n" ;
# Set plugin 'Test'
$self->plugin(Test => 'MyTestPlugin'); # $self->test;
return $self;
}
DESTROY {
lib/Acme/Crux.pm view on Meta::CPAN
$app = $app->webdir( "/path/to/webdoc/dir" );
my $webdirr = $app->webdir;
Default: /var/www/<MONIKER>
=head1 METHODS
This class implements the following methods
=head2 startup
This is your main hook into the application, it will be called at application startup.
Meant to be overloaded in a subclass.
This method is called immediately after creating the instance and returns it
B<NOTE:> Please use only in your subclasses!
sub startup {
my $self = shift;
. . .
return $self; # REQUIRED!
}
=head2 debugmode
$app->debugmode;
lib/Acme/Crux.pm view on Meta::CPAN
my $elapsed = $app->elapsed( $timing_begin );
=head2 elapsed
my $elapsed = $app->elapsed;
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
lib/Acme/Crux.pm view on Meta::CPAN
# Preloading plugins
my $preload_plugins = $self->{preload_plugins};
$preload_plugins = [$preload_plugins] unless is_array_ref($preload_plugins);
my $pplgns = words(@$preload_plugins);
$self->plugin($_) for @$pplgns;
#foreach my $p (@$preload_plugins) {
# next unless defined($p) && is_value($p);
# $self->plugin($_) for split(/[\s;,]+/, $p);
#}
return $self->startup(%$args);
}
sub startup { shift }
# Attributes
sub options {
my $self = shift;
if (scalar(@_) >= 1) {
$self->{options} = shift;
return $self;
}
return $self->{options};
}
lib/Acme/Crux.pm view on Meta::CPAN
return $self->{error};
}
sub begin {
my $self = shift;
$self->{hitime} = [gettimeofday];
return $self->{hitime}
}
sub elapsed {
my $self = shift;
my $timing_begin = shift;
return undef unless my $started = $timing_begin || $self->{hitime};
return tv_interval($started, [gettimeofday]);
}
sub exedir { shift->{exedir} }
sub orig { shift->{orig} }
sub option {
my $self = shift;
my $key = shift;
my $opts = $self->{options};
return undef unless $opts;
return $opts unless defined $key;
return $opts->{$key};
lib/Acme/Crux/Plugin.pm view on Meta::CPAN
my $name = $plugin->name;
Tgis method returns name of this plugin
=head2 register
$plugin->register( $app, $plugin_args );
$plugin->register( $app, @$plugin_args );
This method will be called at startup time. You should overload it in your subclass
=head1 TO DO
See C<TODO> file
=head1 SEE ALSO
L<CTK::Plugin>, L<Mojolicious::Plugin>
=head1 AUTHOR
lib/Acme/Crux/Plugin/Config.pm view on Meta::CPAN
use utf8;
=encoding utf-8
=head1 NAME
Acme::Crux::Plugin::Config - The Acme::Crux plugin for configuration your application
=head1 SYNOPSIS
# In startup
my $config = $app->plugin('Config');
my $config = $app->plugin('Config', undef, {file => '/etc/myapp.conf'});
# In application
my $val = $app->config->get("/foo/bar/baz");
my $all = $app->config->conf;
my $array = $app->config->array('/foo'); # 'value'
# ['value']
lib/Acme/Crux/Plugin/Log.pm view on Meta::CPAN
use utf8;
=encoding utf-8
=head1 NAME
Acme::Crux::Plugin::Log - The Acme::Crux plugin for logging in your application
=head1 SYNOPSIS
# In startup
$app->plugin('Log');
$app->plugin('Log', undef, { ... options ... });
# In application
$app->log->trace('Whatever');
$app->log->debug('You screwed up, but that is ok');
$app->log->info('You are bad, but you prolly know already');
$app->log->notice('Normal, but significant, condition...');
$app->log->warn('Dont do that Dave...');
$app->log->error('You really screwed up this time');
lib/Acrux/Util.pm view on Meta::CPAN
else { $dots = 3 }
# Real length of cutted string
my $reallenght = $cutoff - $dots;
# Input string is too short
return $string if length($string) <= $cutoff;
# Truncate
my $fix = floor($reallenght / 2);
my $new_start = substr($string, 0, ($reallenght - $fix)); # Start part of string
$new_start =~ s/\s+$//; # trim
my $new_midle = $marker x $dots; # Middle part of string
my $new_end = substr($string, (length($string) - $fix), $fix); # Last part of string
$new_end =~ s/^\s+//; # trim
return sprintf ("%s%s%s", $new_start, $new_midle, $new_end);
}
sub indent {
my $str = shift // '';
my $ind = floor(shift || 0);
my $chr = shift // ' ';
return $str unless $ind && $ind <= 65535;
return join '', map { ($chr x $ind) . $_ . "\n" } split /\n/, $str;
}
sub words {
my @in;
( run in 2.012 seconds using v1.01-cache-2.11-cpan-fe3c2283af0 )