NAME

Sprocket::Util::Observable - Helper class for the Sprocket event system

SYNOPSIS

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.. } );

DESCRIPTION

This module provides methods to allow callbacks and event broadasting by name. It is inteded to be subclassed.

METHODS

register_hook( $hook_name )

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_hook( $hook_name, $callback )

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.

remove_hook( $uuid )

Removes one or more attached hooks using the uuid returned by attach_hook.

broadcast( $hook_name, $data )

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_hooks()

Clear all hooks. Good for shutting down when used with sprocket callbacks. This method will be called for you when Sprocket is shutting down.

SEE ALSO

Sprocket

AUTHOR

David Davis <xantus@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2006-2007 by David Davis

See Sprocket for license information.