| | 117 | } |
| | 118 | } |
| | 119 | } |
| | 120 | |
| | 121 | sub 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; |
| | 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 | |
| | 355 | This method registers a plugin and functions with the methods. |
| | 356 | |
| | 357 | The specification of arguments is same as L<"register_hook"> method. |
| | 358 | |
| | 359 | The method is different from B<hook> and only a set of plugin and function are kept about one method. |
| | 360 | When specifying the method name which exists already, the old method is replaced with the new method. |
| | 361 | |
| | 362 | Only when C<$hook-E<gt>hookable_call_filter( 'register_method', $method, $action )> has returned truth, |
| | 363 | this method registers a plugin and function. |
| | 364 | |
| | 365 | Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. |
| | 366 | |
| | 367 | B<Arguments of C<$hook-E<gt>hookable_call_filter>>: |
| | 368 | |
| | 369 | =over 3 |
| | 370 | |
| | 371 | =item C<'register_method'> |
| | 372 | |
| | 373 | C<'run_hook'> is filter name. |
| | 374 | |
| | 375 | =item C<$method> |
| | 376 | |
| | 377 | The method name specified as the register_method method. |
| | 378 | |
| | 379 | =item C<$action> |
| | 380 | |
| | 381 | my ( $plugin, $function ) = @{ $action }{qw( plugin function )}; |
| | 382 | |
| | 383 | The hash reference including plugin and function. |
| | 384 | |
| | 385 | =back |
| | 386 | |