in reply to Re^2: Module forwarding
in thread Module forwarding

.. this isn't looking very easy... My problem is that it seems to depend on whether the forwarded module uses "export" or not....

Replies are listed 'Best First'.
Re^4: Module forwarding
by Anonymous Monk on Feb 06, 2012 at 16:55 UTC
    package ForwardSimpleModule; require Exporter; @ISA = qw(Exporter); use constant FORWARDED => 'SimpleModule'; require do { FORWARDED . '.pm' }; warn; sub import { warn; my $exporter = FORWARDED . "->export_to_level(2, @_)"; my $simple = FORWARDED . "->import(@_)"; eval $exporter; eval $simple if $@; }
    The above demonstration seems to work where exporter is used and where it isn't and import doesn't require details about the caller. BUT: I still can't get it so that the forwarders filename is the same as the underlying pm and use "use" -- I think import get overwritten in the package namespace. (hence the introduction of ForwardSimpleModule namespace)

      Why do you want to lie about the filename? This will make debugging your construct horribly bad, as you can't be sure which file to open to find the root cause of a warning or a crash.

      See perlsyn about comments. The following code should show you how to make Perl claim and a module believe it is loaded from another file:

      eval qq[\n#line 2001 ""\ndie 'foo']; print $@;

      You might also want to set up %INC appropriately.