Skip to content

Commit

Permalink
Merge 0be7ad8 into bf69be8
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Nov 21, 2017
2 parents bf69be8 + 0be7ad8 commit e4485f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Log/Contextual.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ my @log = ((map "log_$_", @levels), (map "logS_$_", @levels));
sub _maybe_export {
my ($spec, $target, $name, $new_code) = @_;

if (my $code = $target->can($name)) {
no strict 'refs';
if (defined &{"${target}::${name}"}) {
my $code = \&{"${target}::${name}"};

# this will warn
$spec->add_export("&$name", $new_code)
Expand Down
33 changes: 33 additions & 0 deletions t/inherit.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Log::Contextual qw(set_logger);
use Log::Contextual::SimpleLogger;

BEGIN {
package MySuperClass;
use Log::Contextual qw(:log);
}

BEGIN {
package MyChildClass;
BEGIN { our @ISA = qw(MySuperClass) };
use Log::Contextual qw(:log);

sub do_thing {
log_error { "child class log" };
}
}

my $last_log;
set_logger(Log::Contextual::SimpleLogger->new({
levels => [qw(error)],
coderef => sub { $last_log = shift },
}));

is exception { MyChildClass->do_thing; }, undef,
'log imports work in child class with exports in parent';

done_testing;

0 comments on commit e4485f9

Please sign in to comment.