Changeset 9993

Show
Ignore:
Timestamp:
04/20/08 18:47:56 (5 years ago)
Author:
nyarla
Message:

lang/perl/Class-Hookable: I implemented run_hook and call_method methods.

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

Legend:

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

    r9563 r9993  
    381381    } 
    382382 
    383  
    384383    my @results; 
    385384 
    386     my $context = ( defined $self->hookable_context ) ? $self->hookable_context : $self ; 
    387  
    388     for my $action ( $self->registered_callbacks( $hook ) ) { 
    389         if ( $self->hookable_call_filter( 'run_hook', $hook, $args, $action ) ) { 
     385    my $context = ( defined $self->class_hookable_context ) ? $self->class_hookable_context : $self ; 
     386 
     387    for my $action ( @{ $self->class_hookable_hooks->{$hook} || [] } ) { 
     388        if ( $self->class_hookable_filter( 'run_hook', $hook, $action, $args ) ) { 
    390389            my $plugin = $action->{'plugin'}; 
    391390            my $result = $action->{'callback'}->( $plugin, $context, $args ); 
    392391            $callback->( $result ) if ( $callback ); 
    393392            if ( $once ) { 
    394                 return $result if ( defined $once ); 
     393                return $result if ( defined $result ); 
    395394            } 
    396395            else { 
     
    416415    } 
    417416 
    418     my $context = ( defined $self->hookable_context ) 
    419                 ? $self->hookable_context 
     417    my $context = ( defined $self->class_hookable_context ) 
     418                ? $self->class_hookable_context 
    420419                : $self ; 
    421420 
    422     my $action = $self->registered_function( $method ); 
     421    my $action  = $self->class_hookable_methods->{$method}; 
    423422    return if ( ! $action ); 
    424423 
    425     if ( $self->hookable_call_filter( 'call_method', $method, $args, $action ) ) { 
     424    if ( $self->class_hookable_filter( 'call_method', $method, $action, $args ) ) { 
    426425        my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
    427426        my $result = $function->( $plugin, $context, $args ); 
     
    596595=back 
    597596 
    598 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 
    599  
    600   $hook->hookable_call_filter( 'run_hook', $hook, $args, $action ); 
    601  
    602 Only when C<$hook-E<gt>hookable_call_filter( 'run_hook', $hook, $args, $action )> has returned truth, 
     597Only when C<$hook-E<gt>class_hookable_filter( 'run_hook', $hook, $action, $args )> has returned truth, 
    603598this method calls callback. 
    604599 
    605 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 
    606  
    607 =over 
    608  
    609 =item 'run_hook' 
    610  
    611 C<'run_hook'> is filter name. 
    612  
    613 =item C<$hook> 
    614  
    615 The hook name specified by the run_hook method. 
    616  
    617 =item C<$args> 
    618  
    619 The argument specified by the run_hook method. 
    620  
    621 =item C<$action> 
    622  
    623   my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 
    624  
    625 The hash reference including the plugin and the callback. 
    626  
    627 =back 
     600Please see L<"class_hookable_filter"> about C<$hook-E<gt>class_hookable_filter>. 
    628601 
    629602=head2 run_hook_once 
     
    687660=back 
    688661 
    689 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 
    690  
    691   $hook->hookable_call_filter( 'call_method', $method, $args, $action ); 
    692  
    693 Only when C<$hook-E<gt>hookable_call_filter( 'call_method', $method, $args, $action )> has returned truth, 
     662Only when C<$hook-E<gt>class_hookable_filter( 'call_method', $method, $action, $args )> has returned truth, 
    694663this method calls function. 
    695664 
    696 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 
    697  
    698 =over 
    699  
    700 =item C<'call_method'> 
    701  
    702 C<'call_method'> is filter name. 
    703  
    704 =item C<$method> 
    705  
    706 The function name specified by the call_method method. 
    707  
    708 =item C<$args> 
    709  
    710 The argument specified by the call_method method. 
    711  
    712 =item C<$action> 
    713  
    714   my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
    715  
    716 The hash reference including the plugin and the function. 
    717  
    718 =back 
     665Please see L<"class_hookable_filter"> about C<$hook-E<gt>class_hookable_filter>. 
    719666 
    720667=head1 FILTER METHODS 
  • lang/perl/Class-Hookable/trunk/t/50_call/00_run_hook.t

    r4056 r9993  
    5353# -- context test -------------------- # 
    5454 
    55 $hook->hookable_context( Context->new ); 
     55$hook->class_hookable_context( Context->new ); 
    5656 
    5757$hook->run_hook_once('context'); 
     
    6565# -- dispatch_plugin test ------------ # 
    6666 
    67 $hook->hookable_set_filter( 
     67$hook->class_hookable_set_filter( 
    6868    'run_hook' => sub { 
    69         my ( $self, $filter, $hook, $args, $action ) = @_; 
     69        my ( $self, $filter, $hook, $action, $args ) = @_; 
    7070 
    7171        isa_ok( $self, 'Class::Hookable' ); 
  • lang/perl/Class-Hookable/trunk/t/50_call/01_call_method.t

    r4056 r9993  
    4343# -- context test -------------------- # 
    4444 
    45 $hook->hookable_context( Context->new ); 
     45$hook->class_hookable_context( Context->new ); 
    4646$hook->call_method('context'); 
    4747 
     
    5353# -- filter test --------------------- # 
    5454 
    55 $hook->hookable_set_filter( 
     55$hook->class_hookable_set_filter( 
    5656    'call_method' => sub { 
    57         my ( $self, $filter, $method, $args, $action ) = @_; 
     57        my ( $self, $filter, $method, $action, $args ) = @_; 
    5858 
    5959        isa_ok( $self, 'Class::Hookable' );