install:
- export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1
- cpanm --quiet --notest --installdeps .
- - cpanm -nq Devel::Cover::Report::Coveralls
+ - cpanm -nq Devel::Cover::Report::Coveralls Test::PerlTidy
script:
- PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine prove -lrsv t
- cover
use warnings;
our $VERSION = '0.006000';
-$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
+$VERSION = eval $VERSION
+ if $VERSION =~ /_/; # numify for warning-free dev releases
my @levels = qw(debug trace warn info error fatal);
# export anything but the levels selected
sub ____ { }
-exports ('____',
- @dlog, @log,
- qw( set_logger with_logger )
-);
+exports('____', @dlog, @log, qw( set_logger with_logger ));
export_tag dlog => ('____');
export_tag log => ('____');
no strict 'refs';
my $sub = "${_}_logger";
*{"Log::Contextual::$sub"} = sub {
- die "$sub is no longer a direct sub in Log::Contextual. " .
- 'Note that this feature was never tested nor documented. ' .
- "Please fix your code to import $sub instead of trying to use it directly"
- }
+ die "$sub is no longer a direct sub in Log::Contextual. "
+ . 'Note that this feature was never tested nor documented. '
+ . "Please fix your code to import $sub instead of trying to use it directly"
+ }
}
1;
VANILLA: {
for (@levels) {
main->can("log_$_")->(sub { 'fiSMBoC' });
- is( $DumbLogger2::var, "[$_] fiSMBoC\n", "$_ works");
+ is($DumbLogger2::var, "[$_] fiSMBoC\n", "$_ works");
- my @vars = main->can("log_$_")->(sub { 'fiSMBoC: ' . $_[1] }, qw{foo bar baz});
- is( $DumbLogger2::var, "[$_] fiSMBoC: bar\n", "log_$_ works with input");
- ok( eq_array(\@vars, [qw{foo bar baz}]), "log_$_ passes data through correctly");
+ my @vars =
+ main->can("log_$_")->(sub { 'fiSMBoC: ' . $_[1] }, qw{foo bar baz});
+ is($DumbLogger2::var, "[$_] fiSMBoC: bar\n", "log_$_ works with input");
+ ok(
+ eq_array(\@vars, [qw{foo bar baz}]),
+ "log_$_ passes data through correctly"
+ );
my $val = main->can("logS_$_")->(sub { 'fiSMBoC: ' . $_[0] }, 'foo');
- is( $DumbLogger2::var, "[$_] fiSMBoC: foo\n", "logS_$_ works with input");
- is( $val, 'foo', "logS_$_ passes data through correctly");
+ is($DumbLogger2::var, "[$_] fiSMBoC: foo\n", "logS_$_ works with input");
+ is($val, 'foo', "logS_$_ passes data through correctly");
}
}
my $var2;
my $var3;
my $var_logger1 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var1 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var1 = shift },
});
my $var_logger2;
use Test::More;
use lib 't/lib';
-use My::Module; # makes use of Log::Contextual::Easy::Default;
-use My::Module2; # makes use of Log::Contextual::Easy::Package;
+use My::Module; # makes use of Log::Contextual::Easy::Default;
+use My::Module2; # makes use of Log::Contextual::Easy::Package;
# capture logging messages of My::Module, mapping "[...] xxx" to "...$sep"
sub logshort($$) {
- my ($cap, $sep) = @_;
- sub {
- local $_ = shift;
- s/^\[(.+)\] (xxx|"xxx")\n$/$1$sep/;
- $$cap .= $_;
- }
+ my ($cap, $sep) = @_;
+ sub {
+ local $_ = shift;
+ s/^\[(.+)\] (xxx|"xxx")\n$/$1$sep/;
+ $$cap .= $_;
+ }
}
# capture warnings
local $SIG{__WARN__} = logshort \$cap_warn, '!';
{
- My::Module::log();
- My::Module2::log();
- is($cap_warn, undef, 'no logging by default');
+ My::Module::log();
+ My::Module2::log();
+ is($cap_warn, undef, 'no logging by default');
}
{
- local $ENV{MY_MODULE_UPTO} = 'info';
- local $ENV{MY_MODULE2_UPTO} = 'info';
- My::Module::log();
- My::Module2::log();
- is($cap_warn, "info!warn!error!fatal!info!warn!error!fatal!", 'WarnLogger enabled via ENV');
- $cap_warn = '';
+ local $ENV{MY_MODULE_UPTO} = 'info';
+ local $ENV{MY_MODULE2_UPTO} = 'info';
+ My::Module::log();
+ My::Module2::log();
+ is(
+ $cap_warn,
+ "info!warn!error!fatal!info!warn!error!fatal!",
+ 'WarnLogger enabled via ENV'
+ );
+ $cap_warn = '';
}
{
- use Log::Contextual::SimpleLogger;
- use Log::Contextual qw(with_logger set_logger);
+ use Log::Contextual::SimpleLogger;
+ use Log::Contextual qw(with_logger set_logger);
- set_logger( Log::Contextual::SimpleLogger->new({
- levels => [qw(info warn error)],
- coderef => logshort \$cap_set, '/'
- }) );
+ set_logger(
+ Log::Contextual::SimpleLogger->new({
+ levels => [qw(info warn error)],
+ coderef => logshort \$cap_set,
+ '/'
+ }));
- my $with_logger = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace info fatal)],
- coderef => logshort \$cap_with, '|'
- });
-
- with_logger $with_logger => sub {
- My::Module::log();
- My::Module2::log(); # will not be overridden
- };
- is($cap_with, 'trace|info|fatal|', 'with_logger');
+ my $with_logger = Log::Contextual::SimpleLogger->new({
+ levels => [qw(trace info fatal)],
+ coderef => logshort \$cap_with,
+ '|'
+ });
- My::Module::log();
- My::Module2::log(); # will not be overridden
- is($cap_set, 'info/warn/error/', 'set_logger');
+ with_logger $with_logger => sub {
+ My::Module::log();
+ My::Module2::log(); # will not be overridden
+ };
+ is($cap_with, 'trace|info|fatal|', 'with_logger');
- is($cap_warn, '', 'no warnings if with_logger or set_logger');
+ My::Module::log();
+ My::Module2::log(); # will not be overridden
+ is($cap_set, 'info/warn/error/', 'set_logger');
+
+ is($cap_warn, '', 'no warnings if with_logger or set_logger');
}
done_testing;
-
my $complex_dispatcher = do {
my $l1 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var1 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var1 = shift },
});
my $l2 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var2 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var2 = shift },
});
my $l3 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var3 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var3 = shift },
});
my %registry = (
my $logger = DumbLogger2->new;
sub default_import { ':log' }
-sub arg_levels { $_[1] || [qw(lol wut zomg)] }
-sub arg_logger { $_[1] || $logger }
+sub arg_levels { $_[1] || [qw(lol wut zomg)] }
+sub arg_logger { $_[1] || $logger }
package DumbLogger2;
our $var;
sub new { bless {}, 'DumbLogger2' }
-sub is_wut { 1 }
-sub wut { $var = "[wut] $_[1]\n" }
-sub is_lol { 1 }
-sub lol { $var = "[lol] $_[1]\n" }
+sub is_wut { 1 }
+sub wut { $var = "[wut] $_[1]\n" }
+sub is_lol { 1 }
+sub lol { $var = "[lol] $_[1]\n" }
sub is_zomg { 1 }
-sub zomg { $var = "[zomg] $_[1]\n" }
+sub zomg { $var = "[zomg] $_[1]\n" }
1;
use Log::Contextual::Easy::Default;
sub log {
- Dlog_fatal { $_ }
- DlogS_error { $_ }
- logS_warn { $_[0] }
- logS_info { $_[0] }
- log_debug { $_[0] }
- log_trace { $_[0] } 'xxx';
+ Dlog_fatal { $_ }
+ DlogS_error { $_ }
+ logS_warn { $_[0] }
+ logS_info { $_[0] } log_debug { $_[0] } log_trace { $_[0] } 'xxx';
}
1;
use Log::Contextual::Easy::Package;
sub log {
- Dlog_fatal { $_ }
- DlogS_error { $_ }
- logS_warn { $_[0] }
- logS_info { $_[0] }
- log_debug { $_[0] }
- log_trace { $_[0] } 'xxx';
+ Dlog_fatal { $_ }
+ DlogS_error { $_ }
+ logS_warn { $_[0] }
+ logS_info { $_[0] } log_debug { $_[0] } log_trace { $_[0] } 'xxx';
}
1;
my $var2;
my $var3;
my $var_logger1 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var1 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var1 = shift },
});
my $var_logger2 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var2 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var2 = shift },
});
my $var_logger3 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var3 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var3 = shift },
});
SETLOGGER: {
my $var2;
my $var3;
my $var_logger1 = Log::Contextual::SimpleLogger->new({
- levels => [qw(trace debug info warn error fatal)],
- coderef => sub { $var1 = shift },
+ levels => [qw(trace debug info warn error fatal)],
+ coderef => sub { $var1 = shift },
});
my $var_logger2;
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan skip_all => 'Set TIDY_TESTING if you want to run this test'
+ unless $ENV{TIDY_TESTING};
+
+require Test::PerlTidy;
+
+Test::PerlTidy::run_tests(
+ path => '.',
+ perltidyrc => '.perltidyrc',
+ exclude => ['inc/'],
+);
+
+done_testing;
my $response;
my $l2 = Log::Contextual::SimpleLogger->new({
- levels => [qw{trace debug info warn error fatal}],
- coderef => sub { $response = $_[0] },
+ levels => [qw{trace debug info warn error fatal}],
+ coderef => sub { $response = $_[0] },
});
{
local $SIG{__WARN__} = sub { }; # do this just to hide warning for tests