Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't skip exports that exist in parent class #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;