Sprocket::Util::Observable - Helper class for the Sprocket event system
package MyModule; use Sprocket qw( Util::Observable ); use base qw( Sprocket::Util::Observable ); sub new { ... snip ... $self->register_hook( 'sprocket.mymodule.action' ); ... snip ... } ... snip ... $self->broadcast( 'sprocket.mymodule.action', { ..data.. } );
This module provides methods to allow callbacks and event broadasting by name. It is inteded to be subclassed.
Register one or more hooks for the callback system. You should follow this convention: 'sprocket.foo.bar.action' $hook_name can also be an array ref of hook names.
Attach to a callback. A hook does not need to be registered to be used, but SHOULD be registered for good style points. :) $hook_name can also be an array ref of hook names. Returns a UUID for this attached set of hooks.
Removes one or more attached hooks using the uuid returned by attach_hook.
Broadcast a hash ref of $data to observers of $hook_name. $data will be blessed into the package Sprocket::Event. Expect $data to be modified in place.
Clear all hooks. Good for shutting down when used with sprocket callbacks. This method will be called for you when Sprocket is shutting down.
Sprocket
David Davis <xantus@cpan.org>
Copyright 2006-2007 by David Davis
See Sprocket for license information.
To install Sprocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sprocket
CPAN shell
perl -MCPAN -e shell install Sprocket
For more information on module installation, please visit the detailed CPAN module installation guide.