Changeset 2279

Show
Ignore:
Timestamp:
12/02/07 11:40:33 (5 years ago)
Author:
nyarla
Message:

lang/perl/Class-Hookable: I implemented register_method 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

    r2278 r2279  
    4545} 
    4646 
     47sub hookable_all_methods { 
     48    my $self = shift; 
     49    return $self->hookable_stash->{'methods'}; 
     50} 
     51 
    4752sub hookable_set_filter { 
    4853    my ( $self, @filters ) = @_; 
     
    110115 
    111116            push @{ $self->hookable_all_hooks->{$hook} }, $action; 
     117        } 
     118    } 
     119} 
     120 
     121sub register_method { 
     122    my ( $self, $plugin, @methods ) = @_; 
     123 
     124    Carp::croak "Plugin object is not blessed obejct or class name." 
     125        if ( ref $plugin && ! Scalar::Util::blessed($plugin) ); 
     126 
     127    while ( my ( $method, $function ) = splice @methods, 0, 2 ) { 
     128        Carp::croak "Function is not CODE reference." 
     129            if ( ref $function ne 'CODE' ); 
     130 
     131        my $action = { 
     132            plugin      => $plugin, 
     133            function    => $function, 
     134        }; 
     135 
     136        if ( $self->hookable_call_filter( 'register_method', $method, $action ) ) { 
     137            $self->hookable_all_methods->{$method} = $action; 
    112138        } 
    113139    } 
     
    319345=back 
    320346 
     347=head2 register_method 
     348 
     349  $hook->register_method( 
     350      $plugin, 
     351      'method.A' => $plugin->can('methodA'), 
     352      'method.B' => $plugin->can('methodB'), 
     353  ); 
     354 
     355This method registers a plugin and functions with the methods. 
     356 
     357The specification of arguments is same as L<"register_hook"> method. 
     358 
     359The method is different from B<hook> and only a set of plugin and function are kept about one method. 
     360When specifying the method name which exists already, the old method is replaced with the new method. 
     361 
     362Only when C<$hook-E<gt>hookable_call_filter( 'register_method', $method, $action )> has returned truth, 
     363this method registers a plugin and function. 
     364 
     365Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 
     366 
     367B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 
     368 
     369=over 3 
     370 
     371=item C<'register_method'> 
     372 
     373C<'run_hook'> is filter name. 
     374 
     375=item C<$method> 
     376 
     377The method name specified as the register_method method. 
     378 
     379=item C<$action> 
     380 
     381  my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; 
     382 
     383The hash reference including plugin and function. 
     384 
     385=back 
     386 
    321387=head1 CALL METHODS 
    322388 
     
    601667all method of Class::Hookable is accessing hooks through this method. 
    602668 
     669=head1 hookable_all_methods 
     670 
     671  my $methods = $hook->hookable_all_methods; 
     672 
     673This method is accesor to hash reference which keeps methods. 
     674all method of Class::Hookable is accessing methods through this method. 
     675 
    603676=head1 AUTHOR 
    604677