NAME

Class::AutoPlug::Pluggable - automatically make a non-pluggable class pluggable

SYNOPSIS

package Nonpluggable::Class::Pluggable;
use base qw(Class::AutoPlug::Pluggable);
1;

DESCRIPTION

Class::AutoPlug::Pluggable provides a means to automatically add pluggability to any class without it. The plugin modules can not only export methods into the new base pluggable class, but can also define prehooks and posthooks for any method supported by the base class.

Prehooks get control before the method is called, and posthooks are called after the method. You can bypass the call altogether or alter what the call does via these hooks. See Class::AutoPlug::Plugin for details on writing hooks.

This class simply sets up the necessary infrastructure; you need write no code whatsoever in classes which use it.

METHODS

new(...)

The new method takes exactly the parameters that the base class supports and passes them along to its constructor. The resulting object is cached internall and is used to execute actual calls to the base class's methods.

You may add extra parameters to be handled by your plugins; see Class::AutoPlug::Plugin for details on how to do this. The extra parameters can either be left in the parameter list or deleted by the plugins.

pre_hook($method_name, $hook_sub_ref)

The prehook method adds a prehook to the named method. The order in which the hooks are added is currently not directly controllable by the plugin writer (it's actually done in collation order of the names of the plugins).

post_hook($method_name, $hook_sub_ref)

The posthook method adds a posthook in much the same way as prehook() adds a prehook.

insert_hook($queue_name, $method_name, $hook_sub_ref)

Allows you to explicitly address a hook queue and add a hook to it; you probably don't want to use this unless you're creating a completely new queue for your own purposes. This method will generally be called in a plugin because you need the address of a hook subroutine to use it. (It's certainly possible to, for instance, only set up a hook in the module which uses Class::AutoPlug::Pluggable and not use a plugin at all. This might be useful if you just want to use this module to "front-end" a few method calls in another module.)

remove_hook($queue_name, $method_name, $hook_sub_ref)

Allows you to remove a hook from a hook queue. Very similar to insert_hook(). Note that as long as you have a reference to a subroutine which is being used as a hook, you can remove it using this method, ev en if the code doing the remove_hook() wasn't the one that set the hook in the first place!

base_obj

Returns a reference to the internally-cached base-class object. Makes it easy for plugins to call methods directly without running any of the hooks.

last_method

The name of the last method called on this object. Can be useful if you want to be able to send another message to the object from within a hook without losing track of what method was called.