Any way to "inject" an INIT block into a different module?

Abigail abigail at abigail.be
Fri May 30 19:27:51 BST 2008


On Fri, May 30, 2008 at 01:26:36PM +0100, Andy Wardley wrote:
> I'm messing with INIT blocks, trying to get some methods auto-generated at
> the right time.
> 
> Here's an example.  Let's say I have an amplifier.  Naturally, it goes up
> to eleven.
> 
>     package Amp;
>     use Control qw( volume sustain );
> 
>     sub volume {
>         print "This amp goes up to eleven\n"
>     }


Another thing you can do is to create the subroutines in Control.pm
unconditionally (at import time), and write Amp.pm like this:

    package Amp;

    use Control qw (volume sustain);
    no warnings 'redefine';

    sub volume {
        ...
    }

    __END__


Abigail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20080530/d4c89e8b/attachment.pgp


More information about the london.pm mailing list