in reply to Re^2: Altering Package Subs and Running In To Problems
in thread Altering Package Subs and Running In To Problems
Even though the dispatch-ness sounds pretty cool, my goal is to have the base module have all the subs.
Understood. The advantage of using method dispatch over stash mangling is that you can have multiple instances which don't conflict.
package Foo; sub shared { print "Shared method" } sub foozle { print "Foo's foozle" } package Bar; sub foozle { print "Bar's foozle" } package Blip; sub foozle { print "Blip's foozle" } package FooBar; @ISA = qw( Bar Foo ); package FooBlip; @ISA = qw( Blip Foo );
With that kind of setup, you can choose which set of plugins you want to have active, and can have one part of your code use one plugin while another part does not.
package main; $package = 'Foo'; $package->shared(); $package->foozle(); # Calls Foo's foozle $package = 'FooBar'; $package->shared(); $package->foozle(); # Calls Bar's foozle
This approach also lets you dynamically stack your "plugins" so that a method in one of them can call NEXT and get the results of the next method up the chain; see my earlier article for details of this technique.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Altering Package Subs and Running In To Problems
by Bovine (Initiate) on Nov 11, 2004 at 23:12 UTC |