Changeset 4622

Show
Ignore:
Timestamp:
01/15/08 12:17:26 (6 years ago)
Author:
nyarla
Message:

lang/perl/Class-Hooakble: I made various changes.

Location:
lang/perl/Class-Hookable/trunk
Files:
5 added
5 removed
3 modified
3 copied
3 moved

Legend:

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

    r4418 r4622  
    1212sub new { bless {}, shift } 
    1313 
    14 sub hookable_stash { 
     14sub class_hookable_stash { 
    1515    my ( $self ) = @_; 
    1616 
    17     if ( ref $self->{'Class::Hookable'} ne 'HASH' ) { 
    18         $self->{'Class::Hookable'} = { 
    19             hooks   => {}, 
    20             methods => {}, 
    21             filters => {}, 
    22         }; 
    23     } 
     17    $self->{'Class::Hookable'} = { 
     18        hooks   => {}, 
     19        methods => {}, 
     20        filters => {}, 
     21    } if ( ref $self->{'Class::Hookable'} ne 'HASH' ); 
    2422 
    2523    return $self->{'Class::Hookable'}; 
     
    2725 
    2826 
    29 sub hookable_context { 
     27sub class_hookable_context { 
    3028    my $self = shift; 
    3129 
    3230    if ( my $context = shift ) { 
    33         $self->hookable_stash->{'context'} = $context; 
    34     } 
    35  
    36     return $self->hookable_stash->{'context'}; 
    37 } 
    38  
    39 sub hookable_all_hooks      { shift->hookable_stash->{'hooks'}      } 
    40 sub hookable_all_methods    { shift->hookable_stash->{'methods'}    } 
    41 sub hookable_all_filters    { shift->hookable_stash->{'filters'}    } 
    42  
    43 sub hookable_set_filter { 
     31        $self->class_hookable_stash->{'context'} = $context; 
     32    } 
     33 
     34    return $self->class_hookable_stash->{'context'}; 
     35} 
     36 
     37sub class_hookable_hooks      { shift->class_hookable_stash->{'hooks'}      } 
     38sub class_hookable_methods    { shift->class_hookable_stash->{'methods'}    } 
     39sub class_hookable_filters    { shift->class_hookable_stash->{'filters'}    } 
     40 
     41sub class_hookable_set_filter { 
    4442    my ( $self, @filters ) = @_; 
    4543 
     
    5149            if ( ref $filter ne 'CODE' ); 
    5250 
    53         $self->hookable_all_filters->{$method} = $filter; 
    54     } 
    55  
    56 } 
    57  
    58 sub hookable_filter_prefix { 
     51        $self->class_hookable_filters->{$method} = $filter; 
     52    } 
     53 
     54} 
     55 
     56sub class_hookable_filter_prefix { 
    5957    my $self = shift; 
    6058 
    61     if ( @_ ) { 
    62         my $prefix = shift; 
     59    if ( my $prefix = shift ) { 
    6360        Carp::croak "Invalid filter prefix. you can use [a-zA-Z_]" 
    64             if ( $prefix =~ m{[^a-zA-Z_]} ); 
    65         $self->hookable_stash->{'filter_prefix'} = $prefix; 
     61            if ( $prefix =~ m{^a-zA-Z_} ); 
     62        $self->class_hookable_stash->{'filter_prefix'} = $prefix; 
    6663    } 
    6764    else { 
    68         return $self->hookable_stash->{'filter_prefix'}; 
    69     } 
    70 } 
    71  
    72 sub hookable_call_filter { 
     65        my $prefix = $self->class_hookable_stash->{'filter_prefix'} 
     66                   || 'class_hookable_filter'; 
     67        return $prefix; 
     68    } 
     69} 
     70 
     71sub class_hookable_filter { 
    7372    my ( $self, $name, @args ) = @_; 
    7473 
     
    7675        if ( ! $name ); 
    7776 
    78     my $prefix = $self->hookable_filter_prefix 
    79               || 'hookable_filter'; 
    80  
    81     my $filter   = $self->hookable_all_filters->{$name}; 
    82        $filter ||= $self->can("${prefix}_${name}"); 
    83        $filter ||= sub { return 1 }; 
     77    my $prefix  = $self->class_hookable_filter_prefix; 
     78 
     79    my $filter  = $self->can("${prefix}_${name}") 
     80               || $self->class_hookable_filters->{$name} 
     81               || sub { 1 }; 
    8482 
    8583    return $filter->( $self, $name, @args ); 
     
    10199        }; 
    102100 
    103         if ( $self->hookable_call_filter( 'register_hook', $hook, $action ) ) { 
    104             $self->hookable_all_hooks->{$hook} = [] 
    105                 if ( ref $self->hookable_all_hooks->{$hook} ne 'ARRAY' ); 
    106  
    107             push @{ $self->hookable_all_hooks->{$hook} }, $action; 
     101        if ( $self->class_hookable_filter( 'register_hook', $hook, $action ) ) { 
     102            $self->class_hookable_hooks->{$hook} = [] 
     103                if ( ref $self->class_hookable_hooks->{$hook} ne 'ARRAY' ); 
     104 
     105            push @{ $self->class_hookable_hooks->{$hook} }, $action; 
    108106        } 
    109107    } 
     
    125123        }; 
    126124 
    127         if ( $self->hookable_call_filter( 'register_method', $method, $action ) ) { 
    128             $self->hookable_all_methods->{$method} = $action; 
     125        if ( $self->class_hookable_filter( 'register_method', $method, $action ) ) { 
     126            $self->class_hookable_methods->{$method} = $action; 
    129127        } 
    130128    } 
    131129} 
    132130 
    133 sub registered_hooks { 
    134     my $self = shift; 
    135  
    136     my @hooks; 
    137  
    138     if ( @_ > 0 ) { 
    139         my $object = shift; 
    140  
    141         if ( ref $object && ! Scalar::Util::blessed( $object ) ) { 
    142             Carp::croak "Argument is not blessed object or class name."; 
    143         } 
    144  
    145         my $is_class = ( ! ref $object ) ? 1 : 0 ; 
    146  
    147         for my $hook ( keys %{ $self->hookable_all_hooks } ) { 
    148             for my $action ( @{ $self->hookable_all_hooks->{$hook} } ) { 
    149                 my $plugin = $action->{'plugin'}; 
    150                 my $class  = ref $plugin || $plugin; 
    151                 if ( $is_class ) { 
    152                     push @hooks, $hook if ( $class eq $object ); 
    153                 } 
    154                 else { 
    155                     push @hooks, $hook if ( $plugin eq $object ); 
    156                 } 
    157             } 
    158         } 
    159     } 
    160     else { 
    161         @hooks = keys %{ $self->hookable_all_hooks }; 
    162     } 
    163  
    164     @hooks = sort { $a cmp $b } @hooks; 
    165     return @hooks; 
    166 } 
    167  
    168 sub registered_callbacks { 
    169     my ( $self, $hook ) = @_; 
    170  
    171     Carp::croak "Hook name is not specified." if ( ! defined $hook ); 
    172  
    173     my $list = $self->hookable_all_hooks->{$hook}; 
    174        $list ||= []; 
    175  
    176     return @{ $list }; 
    177 } 
    178  
    179 sub registered_methods { 
    180     my $self    = shift; 
    181     my @methods = (); 
    182  
    183     if ( @_ > 0 ) { 
    184         my $object = shift; 
    185  
    186         if ( ref $object && ! Scalar::Util::blessed($object) ) { 
    187             Carp::croak "Argument is not blessed object or class name."; 
    188         } 
    189  
    190         my $is_class = ( ! ref $object ) ? 1 : 0 ; 
    191  
    192         for my $method ( keys %{ $self->hookable_all_methods } ) { 
    193             my $plugin  = $self->hookable_all_methods->{$method}->{'plugin'}; 
    194             next if ( ! defined $plugin ); 
    195             my $class   = ref $plugin || $plugin; 
    196             if ( $is_class ) { 
    197                 push @methods, $method if ( $class eq $object ); 
    198             } 
    199             else { 
    200                 push @methods, $method if ( $plugin eq $object ); 
    201             } 
    202         } 
    203     } 
    204     else { 
    205         @methods = keys %{ $self->hookable_all_methods }; 
    206     } 
    207  
    208     @methods = sort { $a cmp $b } @methods; 
    209     return @methods; 
    210 } 
    211  
    212 sub registered_function { 
    213     my ( $self, $method ) = @_; 
    214  
    215     Carp::croak "Method name is not specified" 
    216         if ( ! $method ); 
    217  
    218     my $action = $self->hookable_all_methods->{$method}; 
    219  
    220     return if ( ! $action ); 
    221     return $action; 
    222 } 
    223  
    224 sub delete_hook { 
    225     my ( $self, $hook, @plugins ) = @_; 
    226  
    227     Carp::croak "Hook is not specified." if ( ! defined $hook ); 
    228  
    229     if ( @plugins == 0 ) { 
    230         $self->hookable_all_hooks->{$hook} = []; 
    231     } 
    232     else { 
    233         my @new; 
    234         for my $action ( $self->registered_callbacks( $hook ) ) { 
    235             my $plugin = $action->{'plugin'}; 
    236             my $class  = ref $plugin || $plugin; 
    237             for my $object ( @plugins ) { 
    238                 if ( ref $object && ! Scalar::Util::blessed($object) ) { 
    239                     Carp::croak "Argument is not blessed object or class name."; 
    240                 } 
    241  
    242                 my $is_class = ( ! ref $object ) ? 1 : 0 ; 
    243                 if ( $is_class ) { 
    244                     push @new, $action if ( $class ne $object ); 
    245                 } 
    246                 else { 
    247                     push @new, $action if ( $plugin ne $object ); 
    248                 } 
    249             } 
    250         } 
    251         $self->hookable_all_hooks->{$hook} = \@new; 
    252     }  
    253 } 
    254  
    255 sub delete_callback { 
    256     my ( $self, $callback, @hooks ) = @_; 
    257  
    258     Carp::croak "Callback is not CODE reference." 
    259         if ( ref $callback ne 'CODE' ); 
    260  
    261     @hooks = $self->registered_hooks 
    262         if ( @hooks == 0 ); 
    263  
    264     for my $hook ( @hooks ) { 
    265         my @new; 
    266         for my $action ( $self->registered_callbacks( $hook ) ) { 
    267             if ( $action->{'callback'} ne $callback ) { 
    268                 push @new, $action; 
    269             } 
    270         } 
    271         $self->hookable_all_hooks->{$hook} = \@new; 
    272     } 
    273 } 
    274  
    275 sub delete_method { 
    276     my ( $self, $method, @plugins ) = @_; 
    277  
    278     Carp::croak "Method name is not specified." 
    279         if ( ! defined $method ); 
    280  
    281     return if ( ! defined $self->hookable_all_methods->{$method} ); 
    282  
    283     my $plugin = $self->hookable_all_methods->{$method}->{'plugin'}; 
    284     my $class  = ref $plugin || $plugin; 
    285  
    286     if ( @plugins == 0 ) { 
    287         delete $self->hookable_all_methods->{$method}; 
    288     } 
    289     else { 
    290         for my $object ( @plugins ) { 
    291             my $is_class = ( ! ref $object ) ? 1 : 0 ; 
    292             if ( $is_class ) { 
    293                 delete $self->hookable_all_methods->{$method} 
    294                     if ( $class eq $object ); 
    295             } 
    296             else { 
    297                 delete $self->hookable_all_methods->{$method} 
    298                     if ( $plugin eq $object ); 
    299             } 
    300         } 
    301     } 
    302 } 
    303  
    304 sub delete_function { 
    305     my ( $self, $function, @methods ) = @_; 
    306  
    307     Carp::croak "Function is not CODE reference." 
    308         if ( ref $function ne 'CODE' ); 
    309  
    310     @methods = $self->registered_methods 
    311         if ( @methods == 0 ); 
    312  
    313     for my $method ( @methods ) { 
    314         my $action = $self->registered_function( $method ); 
    315         if ( $action->{'function'} eq $function ) { 
    316             $self->delete_method( $method ); 
    317         } 
    318     } 
    319 } 
    320  
    321 sub delete_plugin { 
    322     my ( $self, $object, @points ) = @_; 
    323  
    324     if ( ref $object && ! Scalar::Util::blessed($object) ) { 
    325         Carp::croak "Argument is not blessed object or class name."; 
    326     } 
    327  
    328     if ( @points == 0 ) { 
    329         push @points, $self->registered_hooks( $object ); 
    330         push @points, $self->registered_methods( $object ); 
    331     } 
    332  
    333     for my $point ( @points ) { 
    334         $self->delete_hook( $point => $object ); 
    335         $self->delete_method( $point => $object ); 
    336     } 
    337 } 
    338131 
    339132sub run_hook { 
     
    460253and one after that is specified by the order of C<'hook' =E<gt> \&callabck>. 
    461254 
    462 Only when C<$hook-E<gt>hookable_call_filter( 'run_hook', $hook, $action )> has returned truth, 
     255Only when C<$hook-E<gt>class_hookable_filter( 'run_hook', $hook, $action )> has returned truth, 
    463256the callback specified by this method is registered with a hook. 
    464257 
    465 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 
    466  
    467 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 
    468  
    469   $hook->hookable_call_filter( 'run_hook', $hook, $action ); 
    470  
    471 =over 
    472  
    473 =item 'run_hook' 
    474  
    475 C<'run_hook'> is filter name. 
    476  
    477 =item $hook 
    478  
    479 The hook name specified as the register_hook method. 
    480  
    481 =item $action 
    482  
    483   my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 
    484  
    485 The hash reference including plugin and callback. 
    486  
    487 =back 
     258Please see L<"class_hookable_filter"> about C<$hook-E<gt>class_hookable_filter>. 
    488259 
    489260=head2 register_method 
     
    502273When specifying the method name which exists already, the old method is replaced with the new method. 
    503274 
    504 Only when C<$hook-E<gt>hookable_call_filter( 'register_method', $method, $action )> has returned truth, 
     275Only when C<$hook-E<gt>class_hookable_filter( 'register_method', $method, $action )> has returned truth, 
    505276this method registers a plugin and function. 
    506277 
    507 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 
    508  
    509 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 
    510  
    511 =over 
    512  
    513 =item C<'register_method'> 
    514  
    515 C<'run_hook'> is filter name. 
    516  
    517 =item C<$method> 
    518  
    519 The method name specified as the register_method method. 
    520  
    521 =item C<$action> 
    522  
    523   my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
    524  
    525 The hash reference including plugin and function. 
    526  
    527 =back 
     278Please see L<"class_hookable_filter"> about C<$hook-E<gt>class_hookable_filter>. 
    528279 
    529280=head1 CALL METHODS 
     
    729480=head1 FILTER METHODS 
    730481 
    731 =head2 hookable_set_filter 
    732  
    733   $hook->hookable_set_filter( 
     482=head2 class_hookable_set_filter 
     483 
     484  $hook->class_hookable_set_filter( 
    734485      register_hook => \&filterA 
    735486      run_hook      => \&filterB, 
     
    744495a old filter is replaced with a new filter. 
    745496 
    746 Please see L<"hookable_call_filter"> about a calling of the filter. 
    747  
    748 =head2 hookable_call_filter 
    749  
    750   my $bool = $hook->hookable_call_filter( $name => @args ); 
     497Please see L<"class_hookable_filter"> about a calling of the filter. 
     498 
     499=head2 class_hookable_filter_prefix 
     500 
     501  $hook->class_hookable_filter_prefix('myfilter_prefix'); 
     502 
     503This method is accessor of filter prefix. 
     504 
     505When finding filter in C<$hook-E<gt>class_hookable_filter> method, 
     506prefix specified by this method is used. 
     507 
     508The character which can be used for the filter prefix is C<[a-zA-Z_]>. 
     509 
     510When prefix is not specified, this method returns C<'class_hookable_filter'> by default. 
     511 
     512=head2 class_hookable_filter 
     513 
     514  my $result = $hook->hookable_call_filter( $filter => @args ); 
    751515 
    752516This method calls a specified filter. 
     
    759523This method searches for a filter from several places. 
    760524 
    761 First, when a specified filter is specified by C<$hook-E<gt>hookable_set_filter> method,  
     525First, when C<$hook-E<gt>can("${prefix}_${filter_name}")> is defined, 
     526its method is used as a filter. 
     527 
     528C<${prefix}> is return value of C<$hook-E<gt>class_hookable_filter_prefix>, 
     529and C<${filter_name}> is the filter name specified as this method. 
     530 
     531Please see L<"class_hookable_filter_prefix"> about C<$hook-E<gt>class_hookable_filter_prefix>. 
     532 
     533Next when a specified filter is specified by C<$hook-E<gt>class_hookable_set_filter> method, 
    762534the filter is used. 
    763535 
    764 Next when C<$hook-E<gt>can("${prefix}_${filter_name}")> is defined, 
    765 its method is used as a filter. 
    766  
    767 C<${prefix}> is return value of $hook->hookable_filter_prefix, 
    768 and C<${filter_name}> is the filter name specified as this method. 
    769  
    770 When C<$hook-E<gt>hookble_filter_perfix> is not specified,  
    771 C<${prefix}> will be C<'hookable_filter'>. 
    772  
    773 Please see L<"hookable_filter_prefix"> about C<$hook-E<gt>hookable_filter_prefix>. 
    774  
    775 When a filter wasn't found, this method uses the filter to which truth is just always returned. 
     536When a filter was not found, this method uses the filter to which truth is just always returned. 
    776537 
    777538B<Arguments of filter>: 
    778539 
    779   $hook->hookable_set_filter( 
    780       'run_hook' => sub { 
    781           my ( $hook, $filter, @args ) = @_; 
     540  $hook->class_hookable_set_filter( 
     541      register_hook    => sub { 
     542          my ( $hook, $filter, $hook, $action ) = @_; 
    782543      }, 
    783   ); 
     544      register_method   => sub { 
     545          my ( $hook, $filter, $method, $action ) = @_; 
     546      }, 
     547      run_hook          => sub { 
     548          my ( $hook, $filter, $hook, $action, $args ) = @_; 
     549      }, 
     550      call_method       => sub { 
     551          my ( $hook, $filter, $method, $action, $args ) = @_; 
     552      }, 
     553  ) 
     554 
     555The filters Class::Hookable calls are C<'register_hook'>, C<'register_method'>, 
     556C<'run_hook'> and C<'call_method'>, and the argument to which it's passed is as follows. 
    784557 
    785558=over 
     
    787560=item C<$hook> 
    788561 
    789 Instance of Class::Hookable (or the class inheriting to Class::Hookable). 
     562Instance of Class::Hookable ( or the class inheriting to Class::Hookable ). 
     563 
     564This argument is passed to all filters. 
    790565 
    791566=item C<$filter> 
    792567 
    793 The filter name called in C<$hook-E<gt>hookable_call_filter>. 
     568The filter name called in C<$hook-E<gt>class_hookable_filter>. 
     569 
     570This argument is passed to all filters. 
    794571 
    795572=item C<@args> 
    796573 
    797 Arguments to the filter to which it was passed by C<$hook-E<gt>hookable_call_filter>. 
     574Arguments to the filter to which it was passed by C<$hook-E<gt>class_hookable_filter>. 
     575 
     576The argument when Class::Hookable calls a filter, is as follows. 
     577 
     578=over 
     579 
     580=item C<$hook> or C<$method> 
     581 
     582the hook name or the method name. 
     583 
     584This argument is passed to all C<'register_hook'>, C<'reigster_method'>, C<'run_hook'> and C<'call_method'>. 
     585 
     586=item C<$action> 
     587 
     588  # In case of hook 
     589  my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 
     590 
     591  # In case of method 
     592  my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
     593 
     594The hash reference including the plugin and the callback or function. 
     595 
     596This argument is passed to all C<'register_hook'>, C<'reigster_method'>, C<'run_hook'> and C<'call_method'>. 
     597 
     598=item C<$args> 
     599 
     600The argument specified by the L<run_hook> or L<call_method> method. 
     601 
     602This argument is passed to C<'run_hook'> and C<'call_method'>. 
    798603 
    799604=back 
    800605 
    801 =head2 hookable_filter_prefix 
    802  
    803   $hook->hookable_filter_prefix('myfilter_prefix'); 
    804  
    805 This method is accessor of filter prefix; 
    806  
    807 When finding filter in call_filer_method, 
    808 prefix specified by this method is used. 
    809  
    810 The character which can be used for the filter prefix is C<[a-zA-Z_]>. 
    811  
    812606=head1 UTILITY METHODS 
    813607 
    814 =head2 registered_hooks 
    815  
    816   my @hooks = $hook->registered_hooks( $plugin ); 
    817   my @hooks = $hook->registered_hooks( 'ClassName' ); 
    818  
    819 This method returns a registered hook name. 
    820  
    821 When calling without arguments, all registered hook name is returned. 
    822  
    823 And when specifying plugin obejct (or Class name) as an argument, 
    824 the hook name with which a plugin is registered is returned. 
    825  
    826 =head2 registered_callbacks 
    827  
    828   for my $action ( $hook->registered_callbacks('hook.name') ) { 
    829       my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 
    830       # some code 
    831   } 
    832  
    833 This method returns plugin and callback registered with a hook. 
    834  
    835 Return value is a list of hash reference including plugin and callback. 
    836 When there are no registered plugin and callback, this method returns empty list. 
    837  
    838 =head2 registered_methods 
    839  
    840   my @methods = $hook->registered_methods( $plugin ); 
    841   my @methods = $hook->registered_methods( 'ClassName' ); 
    842  
    843 This method returns a registered method names. 
    844  
    845 When calling without arguments, all registered method name is returned. 
    846 and When specifying plugin object (or class name) as an arguments, 
    847 the method name with which a plugin is registered is returned. 
    848  
    849 =head2 registered_function 
    850  
    851   my $action = $hook->registered_function('method.name'); 
    852   my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
    853  
    854 This method returns plugin and callback registered with a method. 
    855  
    856 Return value is a hash reference including plugin and callback. 
    857 When nothing is registered, no this methods are returned. 
    858  
    859 =head2 delete_hook 
    860  
    861   $hook->delete_hook( 'hook.name' ); 
    862   $hook->delete_hook( 'hook.name' => ( $pluginA, 'ClassName' ) ); 
    863  
    864 This method deletes a registered hook. 
    865  
    866 Hook name is specified as the first argument, 
    867 and plugin object or class name is specified as an argument after that. 
    868  
    869 When specifying only a hook as an argument, 
    870 all plugin registered with the hook are deleted. 
    871  
    872 And when specifying a hook and plugin object (or class name) as arguments, 
    873 specified plugins are deleted from specified hooks. 
    874  
    875 =head2 delete_callback 
    876  
    877   $hook->delete_callback( $plugin->can('callback') ); 
    878   $hook->delete_callback( \&callback => qw( hook.A hook.B ) ); 
    879  
    880 This method deletes a registered callback. 
    881  
    882 Callback (CODE reference) is specified as the first argument, 
    883 and some hook names are specified after that. 
    884  
    885 When specifying only a callback as an argument, 
    886 all callbacks registered with the hook are deleted. 
    887  
    888 And When specifying callback and hook names as arguments, 
    889 specified callbacks are deleted from specified hooks. 
    890  
    891 =head2 delete_method 
    892  
    893   $hook->delete_method('method.name'); 
    894  
    895 This method deleted a registered hookable method. 
    896 The method name is specified as an argument. 
    897  
    898 =head2 delete_function 
    899  
    900   $hook->delete_function( $plugin->can('function') );: 
    901   $hook->delete_function( \&function => qw( method.A method.B ) ); 
    902  
    903 This method deletes a registered function. 
    904  
    905 Function (CODE reference) is specified as the first argument. 
    906 and some method names are specified after that. 
    907  
    908 When specifying only a function as an argument, 
    909 all functions registered with the method are deleted. 
    910  
    911 And when specifying function and method names as arguments, 
    912 specified functions are deleted from specified methods.  
    913  
    914 =head2 delete_plugin 
    915  
    916   $hook->delete_plugin( $plugin ); 
    917   $hook->delete_plugin( ClassName => qw( hook.A method.A ) ); 
    918  
    919 This method deletes a registered plugin. 
    920  
    921 A plugin object or class name is specified as the first argument, 
    922 and hook names or method names are specified as an argument after that. 
    923  
    924 When specifying only a plugin object (or class name) as an argument, 
    925 a plugin is deleted from all hooks and all methods. 
    926  
    927 And when specifying a plugin object (or class name) and hook names or method names as arguments, 
    928 a plugin is deleted from specified hooks and specified methods. 
     608=head2 remove_hook 
     609 
     610=head2 remove_method 
     611 
     612=head2 clear_hooks 
     613 
     614=head2 clear_methods 
    929615 
    930616=head1 ACCESSOR METOHDS 
    931617 
    932 =head2 hookable_stash 
    933  
    934   my $data = $hook->hookable_stash; 
     618=head2 class_hookable_stash 
     619 
     620  my $data = $hook->class_hookable_stash; 
    935621 
    936622This method is stash in Class::Hookable. 
     
    940626and return hash reference includes all variables. 
    941627 
    942 =head2 hookable_context 
     628=head2 class_hookable_context 
    943629 
    944630  # set 
    945   $hook->hookable_context( $context ); 
     631  $hook->class_hookable_context( $context ); 
    946632  # get 
    947   my $context = $hook->hookable_context; 
     633  my $context = $hook->class_hookable_context; 
    948634 
    949635This method is accessor of context object. 
     
    954640see also L<"run_hook"> and L<"call_method">. 
    955641 
    956 =head2 hookable_all_hooks 
    957  
    958   my $hooks = $hook->hookable_all_hooks; 
     642=head2 class_hookable_hooks 
     643 
     644  my $hooks = $hook->class_hookable_hooks; 
    959645 
    960646This method is accessor to hash reference which keeps hooks. 
    961647all method of Class::Hookable is accessing hooks through this method. 
    962648 
    963 =head2 hookable_all_methods 
    964  
    965   my $methods = $hook->hookable_all_methods; 
     649=head2 class_hookable_methods 
     650 
     651  my $methods = $hook->class_hookable_methods; 
    966652 
    967653This method is accesor to hash reference which keeps methods. 
    968654all method of Class::Hookable is accessing methods through this method. 
    969655 
    970 =head2 hookable_all_filters 
    971  
    972   my $filters = $hook->hookable_all_filters; 
     656=head2 class_hookable_filters 
     657 
     658  my $filters = $hook->class_hookable_filters; 
    973659 
    974660This method is accessor to hash reference which keeps filters. 
  • lang/perl/Class-Hookable/trunk/t/10_accessor/01_class_hookable_context.t

    r4056 r4622  
    1212 
    1313is( 
    14     $hook->hookable_context, 
     14    $hook->class_hookable_context, 
    1515    undef, 
    1616); 
    1717 
    18 $hook->hookable_context('Class::Hookable'); 
     18$hook->class_hookable_context('Class::Hookable'); 
    1919 
    2020is( 
    21     $hook->hookable_context, 
     21    $hook->class_hookable_context, 
    2222    'Class::Hookable', 
    2323); 
    2424 
    25 $hook->hookable_context( Context->new ); 
     25$hook->class_hookable_context( Context->new ); 
    2626 
    2727isa_ok( 
    28     $hook->hookable_context, 
     28    $hook->class_hookable_context, 
    2929    'Context', 
    3030); 
  • lang/perl/Class-Hookable/trunk/t/20_filter/00_class_hookable_set_filter.t

    r2021 r4622  
    99my $hook = Class::Hookable->new; 
    1010 
    11 $hook->hookable_set_filter( 
     11$hook->class_hookable_set_filter( 
    1212    run_hook => \&filter, 
    1313); 
    1414 
    1515is( 
    16     $hook->hookable_stash->{'filters'}->{'run_hook'}, 
     16    $hook->class_hookable_filters->{'run_hook'}, 
    1717    \&filter, 
    1818); 
  • lang/perl/Class-Hookable/trunk/t/20_filter/01_class_hookable_filter_perfix.t

    r2097 r4622  
    1010 
    1111is( 
    12     $hook->hookable_filter_prefix, 
    13     undef, 
     12    $hook->class_hookable_filter_prefix, 
     13    'class_hookable_filter', 
    1414); 
    1515 
    16 $hook->hookable_filter_prefix('myfilter_prefix'); 
     16$hook->class_hookable_filter_prefix('myfilter_prefix'); 
    1717 
    1818is( 
    19     $hook->hookable_filter_prefix, 
     19    $hook->class_hookable_filter_prefix, 
    2020    'myfilter_prefix', 
    2121); 
  • lang/perl/Class-Hookable/trunk/t/20_filter/02_class_hookable_filter.t

    r3391 r4622  
    99my $hook = Class::Hookable->new; 
    1010 
    11 ok( $hook->hookable_call_filter('run_hook') ); 
     11ok( $hook->class_hookable_filter('run_hook') ); 
     12 
     13$hook->class_hookable_set_filter( 
     14    run_hook => sub { 'foo' }, 
     15); 
     16 
     17is( 
     18    $hook->class_hookable_filter('run_hook'), 
     19    'foo', 
     20); 
    1221 
    1322{ 
    1423    package Class::Hookable; 
    1524    no warnings; 
    16     *hookable_filter_run_hook = sub { 
    17         return 'false'; 
    18     }; 
    19     *filter_run_hook = sub { 
    20         return 'true'; 
    21     } 
     25    *class_hookable_filter_run_hook = sub { 'bar' }; 
     26    *filter_run_hook                = sub { 'baz' }; 
    2227} 
    2328 
    2429is( 
    25     $hook->hookable_call_filter('run_hook'), 
    26     'false', 
     30    $hook->class_hookable_filter('run_hook'), 
     31    'bar', 
    2732); 
    2833 
    29 $hook->hookable_filter_prefix('filter'); 
     34$hook->class_hookable_filter_prefix('filter'); 
    3035 
    3136is( 
    32     $hook->hookable_call_filter('run_hook'), 
    33     'true', 
     37    $hook->class_hookable_filter('run_hook'), 
     38    'baz', 
    3439); 
    35  
    36 $hook->hookable_set_filter( 
    37     'run_hook' => sub { 
    38         return 0; 
    39     } 
    40 ); 
    41  
    42 is( 
    43     $hook->hookable_call_filter('run_hook'), 
    44     0, 
    45 ); 
  • lang/perl/Class-Hookable/trunk/t/30_register/00_register_hook.t

    r4056 r4622  
    1818 
    1919is( 
    20     $hook->hookable_all_hooks->{'foo.bar'}->[0]->{'plugin'}, 
     20    $hook->class_hookable_hooks->{'foo.bar'}->[0]->{'plugin'}, 
    2121    $plugin, 
    2222); 
    2323 
    2424is( 
    25     $hook->hookable_all_hooks->{'foo.bar'}->[0]->{'callback'}, 
     25    $hook->class_hookable_hooks->{'foo.bar'}->[0]->{'callback'}, 
    2626    $plugin->can('foo'), 
    2727); 
    2828 
    29 $hook->hookable_set_filter( 
     29$hook->class_hookable_set_filter( 
    3030    'register_hook' => sub { 
    3131        my ( $self, $filter, $hook, $action ) = @_; 
     
    4949 
    5050is( 
    51     $hook->hookable_all_hooks->{'foo.bar'}->[1], 
     51    $hook->class_hookable_hooks->{'foo.bar'}->[1], 
    5252    undef, 
    5353); 
  • lang/perl/Class-Hookable/trunk/t/30_register/01_register_method.t

    r4056 r4622  
    1818 
    1919is_deeply( 
    20     $hook->hookable_all_methods->{'foo.bar'}, 
     20    $hook->class_hookable_methods->{'foo.bar'}, 
    2121    { 
    2222        plugin      => $plugin, 
     
    2525); 
    2626 
    27 $hook->hookable_set_filter( 
     27$hook->class_hookable_set_filter( 
    2828    'register_method' => sub { 
    2929        my ( $self, $filter, $method, $action ) = @_; 
     
    4848 
    4949is( 
    50     $hook->hookable_all_methods->{'bar.baz'}, 
     50    $hook->class_hookable_methods->{'bar.baz'}, 
    5151    undef, 
    5252);