in reply to use base and inheritance of non-method subroutines
However if you make some assumptions you can get something that works (or gets close to it).package A; use Data::Dumper (); sub Dumper { print "This is not dumper\n"; }
Then use ibase rather than base.package ibase; BEGIN { require base; *{"_import"} = \&{"base::import"}; for (qw( )) { *{"$_"} = \&{"base::$_"}; } } our $ExportLevel = 0; sub import { my $self = shift; my $callpkg = caller($ExportLevel); eval { $self->_import(@_); }; for my $key (keys %INC) { if ($key =~ m|Data/Dumper.pm|) { *{"$callpkg\::Dumper"} = \&{"Data::Dumper::Dumper"}; } } } 1;
You code make this a little more robust buy using @EXPORT_OK to see what all should be imported.package A; use Data::Dumper; print Dumper \%INC, \@INC; package B; use strict; use ibase 'A'; print Data::Dumper::Dumper(\%A::INC, \%INC); print Dumper([1]);
|
|---|