in reply to Forwarding functions to a different module

Personally, I would just set up aliases to the functions, and wrap that functionality in a bit of code. For example:

package ParentModule; use strict; sub base_foo {}; sub base_baz {}; sub import { my ($class,@routines) = @_; my $target = caller; # Install the requested routines in the target package for my $name (@routines) { no strict 'refs'; *{"$target\::$name"} = \&{"base_$name"}; }; }; 1;

And then in the child classes:

package ChildModule1; use strict; use ParentModule qw( foo bar ); package ChildModule2; use strict; use ParentModule qw( foo ); # Own implementation of bar() sub bar {...}; 1;

You can get fancier and provide hashes for name mappings.

Replies are listed 'Best First'.
Re^2: Forwarding functions to a different module
by rovf (Priest) on Aug 07, 2008 at 10:52 UTC

    This is great! I have never attempted to write my own import routine, so this is also of high educative value....

    -- 
    Ronald Fischer <ynnor@mm.st>