view release on metacpan or search on metacpan
lib/Acme/Crux.pm view on Meta::CPAN
. . .
return $self; # REQUIRED!
}
=head2 debugmode
$app->debugmode;
Returns debug flag. 1 - on, 0 - off
=head2 begin
my $timing_begin = $app->begin;
This method sets timestamp for L</elapsed>
my $timing_begin = $app->begin;
# ... long operations ...
my $elapsed = $app->elapsed( $timing_begin );
lib/Acme/Crux.pm view on Meta::CPAN
foo => "one",
bar => 1
) or die $app->error;
Runs handler by name and returns result of it handler running
=head2 silentmode
$app->silentmode;
Returns the verbose flag in the opposite value. 0 - verbose, 1 - silent.
See L</verbosemode>
=head2 testmode
$app->testmode;
Returns test flag. 1 - on, 0 - off
=head2 verbosemode
$app->verbosemode;
Returns verbose flag. 1 - on, 0 - off
See L</silentmode>
=head1 PLUGINS
The following plugins are included in the Acrux distribution
=over 4
=item L<Acme::Crux::Plugin::Config>
lib/Acme/Crux.pm view on Meta::CPAN
use Carp qw/carp croak/;
use Time::HiRes qw/gettimeofday tv_interval/;
use FindBin qw/$RealBin $Script/;
use File::Spec qw//;
use Cwd qw/getcwd/;
use Sub::Util qw/set_subname/;
use Acrux::RefUtil qw/
as_hash_ref is_hash_ref
as_array_ref is_array_ref
is_value is_code_ref is_true_flag
/;
use Acrux::Const qw/:dir IS_ROOT/;
use Acrux::Util qw/load_class trim words/;
use constant {
WIN => !!($^O =~ /mswin/i),
ALOWED_MODES => [qw/debug test verbose/],
PRELOAD_PLUGINS => [qw/Config Log/], # Order is very important!
DEFAULT_PLUGINS => {
Config => "Acme::Crux::Plugin::Config",
lib/Acme/Crux.pm view on Meta::CPAN
# Files
logfile => $args->{logfile}, # Log file of project. Default: /var/log/moniker/moniker.log
configfile => $args->{configfile}, # Config file of project. Default: /etc/moniker/moniker.conf
pidfile => $args->{pidfile}, # PID file of project. Default: /var/run/moniker.pid
}, $class;
# Modes
foreach my $mode ( @{(ALOWED_MODES)}) {
$self->{$mode."mode"} = 1 if is_true_flag($args->{$mode});
}
# Root dir
my $root = $self->{root};
$root = $self->{root} = $pwd if defined($root) && $root eq '.';
unless (defined($root) && length($root)) {
$root = $self->{root} = File::Spec->catdir(SYSCONFDIR, $moniker);
}
# Temp dir
lib/Acme/Crux/Plugin/Config.pm view on Meta::CPAN
See C<LICENSE> file and L<https://dev.perl.org/licenses/>
=cut
our $VERSION = '0.02';
use parent 'Acme::Crux::Plugin';
use Acrux::Config;
use Acrux::RefUtil qw/as_array_ref as_hash_ref is_true_flag/;
sub register {
my ($self, $app, $args) = @_;
# NoLoad flag: PLGARGS || OPTS || ORIG || DEFS
my $noload = is_true_flag($args->{noload}) # From plugin arguments first
|| $app->getopt("noload") # From command line options
|| $app->orig->{"config_noload"} # From App arguments
|| 0;
# Config file: PLGARGS || OPTS || ORIG || DEFS
my $file = $args->{file} || $app->getopt("configfile") || $app->configfile;
# Config::General Options: PLGARGS || DEFS
my $options = as_hash_ref($args->{options} || $args->{opts});
lib/Acme/Crux/Plugin/Log.pm view on Meta::CPAN
=cut
our $VERSION = '0.01';
use parent 'Acme::Crux::Plugin';
use Acrux::Log;
use Carp qw/croak/;
use Acrux::RefUtil qw/as_array_ref as_hash_ref is_code_ref is_true_flag is_ref/;
sub register {
my ($self, $app, $args) = @_;
my $has_config = $app->can('config') ? 1 : 0;
# Autoclean flag: PLGARGS || OPTS || ORIG || CONF || DEFS
my $autoclean = is_true_flag($args->{autoclean}) # From plugin arguments first
|| $app->getopt("logautoclean") # From command line options
|| $app->orig->{"logautoclean"} # From App arguments
|| ($has_config ? $app->config->get("/logautoclean") : 0); # From config file
# Colorize flag: PLGARGS || OPTS || ORIG || CONF || DEFS
my $colorize = is_true_flag($args->{color}) # From plugin arguments first
|| $app->getopt("logcolorize") # From command line options
|| $app->orig->{"logcolorize"} # From App arguments
|| ($has_config ? $app->config->get("/logcolorize") : 0); # From config file
# Log facility: PLGARGS || OPTS || ORIG || CONF || DEFS
my $facility = $args->{facility} # From plugin arguments first
|| $app->getopt("logfacility") # From command line options
|| $app->orig->{"logfacility"} # From App arguments
|| ($has_config ? $app->config->get("/logfacility") : ''); # From config file
lib/Acme/Crux/Plugin/Log.pm view on Meta::CPAN
if (defined $logger) {
croak(qq{Invalid logger object}) unless is_ref($logger);
}
# Log options: PLGARGS || OPTS || ORIG || CONF || DEFS
my $logopt = $args->{logopt} # From plugin arguments first
|| $app->getopt("logopt") # From command line options
|| $app->orig->{"logopt"} # From App arguments
|| ($has_config ? $app->config->get("/logopt") : ''); # From config file
# Short flag: PLGARGS || OPTS || ORIG || CONF || DEFS
my $short = is_true_flag($args->{short}) # From plugin arguments first
|| $app->getopt("logshort") # From command line options
|| $app->orig->{"logshort"} # From App arguments
|| ($has_config ? $app->config->get("/logshort") : 0); # From config file
# Log prefix: PLGARGS || OPTS || ORIG || CONF || DEFS
my $prefix = $args->{prefix} # From plugin arguments first
|| $app->getopt("logprefix") # From command line options
|| $app->orig->{"logprefix"} # From App arguments
|| ($has_config ? $app->config->get("/logprefix") : ''); # From config file
lib/Acrux/FilePid.pm view on Meta::CPAN
This constructor takes three optional paramters.
C<file> - The name of the pid file to work on. If not specified, a pid
file located in current directory. So, for example, if C<$0> is F<~/bin/sig.pl>,
the pid file will be F<./sig.pl.pid>.
C<pid> - The pid to write to a new pidfile. If not specified, C<$$> is
used when the pid file doesn't exist. When the pid file does exist, the
pid inside it is used.
C<autoremove> - Auto-remove flag. If this flag specified as true, then
will be removed the pid file automatically on DESTROY phase. Default: false
C<autosave> - Auto-save flag. If this flag specified as true, then
will be saved the pid file automatically while instance create. Default: false
C<auto> - this flag forced sets C<autoremove> and C<autosave> flags. Default: false
=head2 file
$fp->file("/var/run/file.pid");
my $pidfile = $fp->file;
Accessor/mutator for the filename used as the pid file.
=head2 load
lib/Acrux/RefUtil.pm view on Meta::CPAN
Returns true if the structure does not contain any nested useful data.
Useful data - this data is different from the value undef
=back
=head2 FLAG
=over 4
=item is_false_flag
print "Disabled" if is_false_flag("off");
If specified argument value is set to false then will be normalised to 1.
The following values will be considered as false:
no, off, 0, false, disable
This effect is case-insensitive, i.e. both "No" or "no" will result in 1.
=item is_true_flag
print "Enabled" if is_true_flag("on");
If specified argument value is set to true then will be normalised to 1.
The following values will be considered as true:
yes, on, 1, true, enable
This effect is case-insensitive, i.e. both "Yes" or "yes" will result in 1.
=back
lib/Acrux/RefUtil.pm view on Meta::CPAN
is_ref is_undef
is_scalar_ref is_array_ref is_hash_ref is_code_ref
is_glob_ref is_regexp_ref is_regex_ref is_rx
is_value is_string is_number is_integer
is_int8 is_int16 is_int32 is_int64
/);
# Required
our @EXPORT_OK = (qw/
is_void isnt_void
is_true_flag is_false_flag
as_array as_list as_array_ref as_hash as_hash_ref
as_first as_first_val as_last as_last_val as_latest
/, @EXPORT);
# Tags
our %EXPORT_TAGS = (
all => [@EXPORT_OK],
check => [@EXPORT],
void => [qw/
is_void isnt_void
/],
flag => [qw/
is_true_flag is_false_flag
/],
as => [qw/
as_array as_list as_array_ref as_hash as_hash_ref
as_first as_first_val as_last as_last_val as_latest
/],
);
use constant MAX_DEPTH => 32;
# Base functions
lib/Acrux/RefUtil.pm view on Meta::CPAN
return 1; # DEFINED DATA NOT FOUND - VOID
} elsif ($t eq 'HASH') {
return 0 if keys(%$struct);
return 1; # DEFINED DATA NOT FOUND - VOID
}
# CODE, REF, GLOB, LVALUE, FORMAT, IO, VSTRING and Regexp are not supported here
return 0; # NOT VOID
}
sub isnt_void {is_void(@_) ? 0 : 1}
sub is_true_flag {
my $f = shift || return 0;
return $f =~ /^(on|y|true|enable|1)/i ? 1 : 0;
}
sub is_false_flag {
my $f = shift || return 1;
return $f =~ /^(off|n|false|disable|0)/i ? 1 : 0;
}
# As
sub as_array_ref {
return [] unless scalar @_; # if no args
return [@_] if scalar(@_) > 1; # if too many args
return [] unless defined($_[0]); # if value is undef
if (ref($_[0]) eq 'ARRAY') { return $_[0] } # Array
lib/Acrux/Util.pm view on Meta::CPAN
C<binmode()> on the handle used for writing.
Can optionally take these named arguments:
=over 4
=item append
This argument is a boolean option, defaulted to false (C<0>).
Setting this argument to true (C<1>) will cause the data to be be written at the end of the current file.
Internally this sets the sysopen mode flag C<O_APPEND>
=item binmode
Set the layers to write the file with. The default will be something sensible on your platform
=item locked
This argument is a boolean option, defaulted to false (C<0>).
Setting this argument to true (C<1>) will ensure an that existing file will not be overwritten
t/03-refutil.t view on Meta::CPAN
ok is_value("foo"), 'is_value("foo")';
ok is_string("foo"), 'is_string("foo")';
ok is_number(-123), 'is_number(-123)';
ok is_integer(17), 'is_integer(17)';
ok is_int8(28), 'is_int8(28)';
ok is_int16(512), 'is_int16(512)';
ok is_int32(65537), 'is_int32(65537)';
ok is_int64(1234567890), 'is_int64(1234567890)';
ok(is_int8(0), 'Function is_int8(0)');
# True flags
ok(!is_false_flag("yes"), 'yes is true');
ok(is_true_flag("Y"), 'Y too');
ok(is_true_flag("YEP"), 'And YEP too');
ok(is_true_flag(1), 'And 1 too');
# False flags
ok(is_false_flag("Nope"), 'Nope is false');
ok(is_false_flag(0), 'And 0 too');
ok(is_false_flag("disabled"), 'And disabled too');
# Void
ok(is_void(undef),'undef - void value');
ok(is_void(\undef),'\\undef - void value');
ok(isnt_void(""),'null - void value');
ok(isnt_void("0"),'"0" - NOT void value');
ok(isnt_void(\"0"),'\\"0" - NOT void value');
ok(isnt_void(0),'0 - NOT void value');
ok(is_void([]),'[] - void value');
ok(isnt_void([0]),'[0] - NOT void value');
t/08-config.t view on Meta::CPAN
## <Foo>
## <Bar>
## Test blah blah blah
## </Bar>
## </Foo>
## </Deep>
# Loaded config data
is($c->config('_config_loaded'), 1, 'get config directive directrly');
# Get on/off flags directly
is($c->config('baz'), 1, 'Get on/off flags directly');
# Get by pointer path
is($c->get('/box/test'), 123, 'Get by pointer path /box/test');
is($c->get('box/test'), 123, 'Get by pointer path in short notation box/test');
# Get deeply
is($c->get('/deep/foo/bar/test'), 'blah blah blah', 'Get deeply /deep/foo/bar/test');
# Get on/off flags
is($c->get('/baz'), 1, 'Get on flags');
is($c->get('/qux'), 0, 'Get off flags');
# Get first value
is($c->first('/array/test'), 'First', 'Get first value');
# Get latest value
is($c->latest('/array/test'), 'Third', 'Get latest value');
# Get list of values as array
is(ref($c->array('/array/test')), 'ARRAY', 'Get list of values as array');