4 use Log::Contextual qw{:dlog :log with_logger set_logger},
6 use Log::Contextual::SimpleLogger;
7 use Test::More qw(no_plan);
9 my $logger = DumbLogger->new;
11 set_logger(sub { $logger });
13 log_custom { 'fiSMBoC' };
14 is($DumbLogger::var, "fiSMBoC", "custom works");
16 my @vars = log_custom { 'fiSMBoC: ' . $_[1] } qw{foo bar baz};
17 is($DumbLogger::var, "fiSMBoC: bar", "log_custom works with input");
19 eq_array(\@vars, [qw{foo bar baz}]),
20 "log_custom passes data through correctly"
23 my $val = logS_custom { 'fiSMBoC: ' . $_[0] } 'foo';
24 is($DumbLogger::var, "fiSMBoC: foo", "logS_custom works with input");
25 is($val, 'foo', "logS_custom passes data through correctly");
27 my @foo = Dlog_custom { "Look ma, data: $_" } qw{frew bar baz};
30 eq_array(\@foo, [qw{frew bar baz}]),
31 "Dlog_custom passes data through correctly"
35 qq(Look ma, data: "frew"\n"bar"\n"baz"\n),
36 "Output for Dlog_custom is correct"
39 my $bar = DlogS_custom { "Look ma, data: $_" }[qw{frew bar baz}];
40 ok(eq_array($bar, [qw{frew bar baz}]),
41 'DlogS_custom passes data through correctly');
44 qq(Look ma, data: [\n "frew",\n "bar",\n "baz"\n]\n),
45 "Output for DlogS_custom is correct"
48 @foo = Dlog_custom { "nothing: $_" } ();
49 ok(eq_array(\@foo, []), "Dlog_custom passes nothing through correctly");
50 is($DumbLogger::var, "nothing: ()", "Output for Dlog_custom is correct");
52 ok(!main->can($_), "$_ not imported")
53 for map +("log_$_", "logS_$_"), qw(debug trace warn info error fatal);
55 ok(!eval { Log::Contextual->import; 1 }, 'Blank Log::Contextual import dies');
62 sub new { bless {}, 'DumbLogger' }
64 sub custom { $var = $_[1] }