Show
Ignore:
Timestamp:
12/10/07 15:44:07 (13 months ago)
Author:
nyarla
Message:

lang/perl/Class-Hookable: I implemented delete_callback method.

Location:
lang/perl/Class-Hookable/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Class-Hookable/trunk/lib/Class/Hookable.pm

    r2423 r2977  
    231231} 
    232232 
     233sub delete_hook { 
     234    my ( $self, $hook, @plugins ) = @_; 
     235 
     236    Carp::croak "Hook is not specified." if ( ! defined $hook ); 
     237 
     238    if ( @plugins == 0 ) { 
     239        $self->hookable_all_hooks->{$hook} = []; 
     240    } 
     241    else { 
     242        for my $plugin ( @plugins ) { 
     243            $self->delete_plugin( $plugin, $hook ); 
     244        } 
     245    } 
     246} 
     247 
     248sub delete_callback { 
     249    my ( $self, $callback, @hooks ) = @_; 
     250 
     251    Carp::croak "Callback is not CODE reference." 
     252        if ( ref $callback ne 'CODE' ); 
     253 
     254    @hooks = $self->registered_hooks 
     255        if ( @hooks == 0 ); 
     256 
     257    for my $hook ( @hooks ) { 
     258        my @new; 
     259        for my $action ( $self->registered_callbacks( $hook ) ) { 
     260            if ( $action->{'callback'} ne $callback ) { 
     261                push @new, $action; 
     262            } 
     263        } 
     264        $self->hookable_all_hooks->{$hook} = \@new; 
     265    } 
     266} 
     267 
    233268sub delete_plugin { 
    234269    my ( $self, $object, @hooks ) = @_; 
     
    259294    } 
    260295 
    261 } 
    262  
    263 sub delete_hook { 
    264     my ( $self, $hook, @plugins ) = @_; 
    265  
    266     Carp::croak "Hook is not specified." if ( ! defined $hook ); 
    267  
    268     if ( @plugins == 0 ) { 
    269         $self->hookable_all_hooks->{$hook} = []; 
    270     } 
    271     else { 
    272         for my $plugin ( @plugins ) { 
    273             $self->delete_plugin( $plugin, $hook ); 
    274         } 
    275     } 
    276296} 
    277297 
     
    690710 
    691711And when specifying a hook and plugin object (or class name) as arguments, 
    692 specified plugins are deleted from a specified hook. 
     712specified plugins are deleted from specified hooks. 
     713 
     714=head2 delete_callback 
     715 
     716  $hook->delete_callback( $plugin->can('callback') ); 
     717  $hook->delete_callback( \&callback => qw( hook.A hook.B ) ); 
     718 
     719This method deletes a registered callback. 
     720 
     721Callback (CODE reference) is specified as the first argument, 
     722and some hook names are specified after that. 
     723 
     724When specifying a callback as an argument, 
     725all callbacks registered with the hook are deleted. 
     726 
     727And When specifying callback and hook names as arguments, 
     728specified callbacks are deleted from specified hooks. 
    693729 
    694730=head2 delete_plugin