- Timestamp:
- 11/28/07 13:13:20 (5 years ago)
- Location:
- lang/perl/Class-Hookable/trunk
- Files:
-
- 4 modified
-
Changes (modified) (1 diff)
-
lib/Class/Hookable.pm (modified) (10 diffs)
-
t/02_register/00_register_hook.t (modified) (2 diffs)
-
t/04_call/00_run_hook.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Class-Hookable/trunk/Changes
r2020 r2101 3 3 0.03 4 4 * Substantial change * 5 * renamed method 6 context -> hookable_context 7 * added new method 8 hookable_stash : stash in Class::Hookable. 9 hookable_set_filter : 5 * Change in the filtering of plugin 6 It was changed substantially about a way of filtering of a plugin. 7 It was possible to rewrite a filter only by inheriting of Class::Hookable before, 8 but this change could change it now every instance. 9 The previous filter_register_hook and filter_run_hook method 10 weren't used any more by this change. 11 added methods: 12 hookable_set_filter 13 hookable_call_filter 14 hookable_filter_prefix 10 15 11 16 0.02 Wed Nov 11 13:00:00 JST 2007 -
lang/perl/Class-Hookable/trunk/lib/Class/Hookable.pm
r2100 r2101 112 112 }; 113 113 114 if ( $self-> filter_register_hook($hook, $action ) ) {114 if ( $self->hookable_call_filter( 'register_hook', $hook, $action ) ) { 115 115 $self->hooks->{$hook} = [] 116 116 if ( ref $self->hooks->{$hook} ne 'ARRAY' ); … … 120 120 } 121 121 } 122 123 sub filter_register_hook { 1 }124 122 125 123 sub registered_hooks { … … 218 216 219 217 for my $action ( $self->registered_plugins( $hook ) ) { 220 if ( $self-> filter_run_hook($hook, $args, $action ) ) {218 if ( $self->hookable_call_filter( 'run_hook', $hook, $args, $action ) ) { 221 219 my $plugin = $action->{'plugin'}; 222 220 my $result = $action->{'callback'}->( $plugin, $context, $args ); … … 239 237 return $self->run_hook( $hook, $args, 1, $callback ); 240 238 } 241 242 sub filter_run_hook { 1 }243 239 244 240 1; … … 271 267 I thank Tatsuhiko Miyagawa and Plagger contributors. 272 268 273 B<NOTE>:274 275 B<I made substantial changes in Class::Hookable> from 0.02 to 0.03.276 277 When using Class::Hookable, B<please be careful of Class::Hookable version>.278 279 269 =head1 BASIC METHOD 280 270 … … 310 300 the subroutine registered with hook and method. 311 301 312 see also L<"run_hook"> and L<"call_method">.302 see also L<"run_hook">. 313 303 314 304 =head1 REGISTER METOHDS … … 327 317 and one after that is specified by the order of C<'hook' =E<gt> \&callabck>. 328 318 329 =head2 filter_register_hook 330 331 sub filter_register_hook { 332 my ( $self, $hook, $action ) = @_; 333 my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 334 # your filter code 335 } 336 337 When registering a plugin, this method is filtered a plugin. 338 Arguments are passed by the order of C<$hook> and C<$action>. 339 340 =over 2 341 342 =item C<$hook> 343 344 The hook name specified as the run_hook method. 345 346 =item C<$action> 319 Only when C<$hook-E<gt>hookable_call_filter( 'run_hook', $hook, $action )> has returned truth, 320 the callback specified by this method is registered with a hook. 321 322 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 323 324 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 325 326 $hook->hookable_call_filter( 'run_hook', $hook, $action ); 327 328 =over 3 329 330 =item 'run_hook' 331 332 C<'run_hook'> is filter name. 333 334 =item $hook 335 336 The hook name specified as the register_hook method. 337 338 =item $action 339 340 my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 347 341 348 342 The hash reference including plugin and callback. 349 343 350 344 =back 351 352 When this method has returned ture, plugin and hook are registered,353 and when having returned false, it isn't registered.354 355 This method exists to rewrite when inheriting.356 345 357 346 =head1 CALL METHODS … … 403 392 =back 404 393 405 B<Argument to callback of the registered plugin>:394 B<Arguments of registered callback>: 406 395 407 396 sub callback { … … 433 422 =back 434 423 424 425 Only when C<$hook-E<gt>hookable_call_filter( 'run_hook', $hook, $args, $action )> has returned truth, 426 this method calls callback. 427 428 Please see L<"hookable_call_filter"> about C<$hook-E<gt>hookable_call_filter>. 429 430 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 431 432 $hook->hookable_call_filter( 'run_hook', $hook, $args, $action ); 433 434 =over 4 435 436 =item 'run_hook' 437 438 C<'run_hook'> is filter name. 439 440 =item C<$hook> 441 442 The hook name specified by the run_hook method. 443 444 =item C<$args> 445 446 The argument specified by the run_hook method. 447 448 =item C<$action> 449 450 my ( $plugin, $callback ) = @{ $action }{qw( plugin callback )}; 451 452 The hash reference including the plugin and the callback. 453 454 =back 455 435 456 =head2 run_hook_once 436 457 … … 438 459 439 460 This method is an alias of C<$hook-E<gt>run_hook( $hook, $args, 1, \&callback )>. 440 441 =head2 filter_run_hook442 443 sub filter_run_hook {444 my ( $self, $hook, $args, $action ) = @_;445 my ( $plugin, $callabck ) = @{ $action }{qw( plugin callback )};446 # some code447 }448 449 When calling a hook, this method is filtered a plugin.450 Argument are passed by the order of C<$hook>, C<$args>, C<$action>.451 452 =over 3453 454 =item C<$hook>455 456 The hook name specified by the run_hook method.457 458 =item C<$args>459 460 The argument specified by the run_hook method.461 462 =item C<$action>463 464 The hash reference including the plugin and the callback.465 466 =back467 468 When this method has returned true, callback of a plugin is called,469 and when having returned false, callback isn't called.470 471 This method exists to rewrite when inheriting.472 461 473 462 =head1 FILTER METHODS -
lang/perl/Class-Hookable/trunk/t/02_register/00_register_hook.t
r1878 r2101 4 4 use warnings; 5 5 6 use Test::More tests => 3;6 use Test::More tests => 7; 7 7 use Class::Hookable; 8 8 … … 25 25 ); 26 26 27 { 28 no warnings 'redefine'; 29 *Class::Hookable::filter_register_hook = sub { 0 }; 30 } 27 $hook->hookable_set_filter( 28 'register_hook' => sub { 29 my ( $self, $filter, $hook, $action ) = @_; 30 isa_ok( $self, 'Class::Hookable' ); 31 is( $filter, 'register_hook' ); 32 is( $hook, 'AAA.BBB' ); 33 is_deeply( 34 $action, 35 { 36 plugin => $plugin, 37 callback => $plugin->can('bar'), 38 }, 39 ); 40 }, 41 ); 31 42 32 43 $hook->register_hook( -
lang/perl/Class-Hookable/trunk/t/04_call/00_run_hook.t
r1959 r2101 4 4 use warnings; 5 5 6 use Test::More tests => 5 + 2 + 4;6 use Test::More tests => 5 + 2 + 6; 7 7 use Class::Hookable; 8 8 … … 62 62 # -- dispatch_plugin test ------------ # 63 63 64 no warnings 'redefine';65 *Class::Hookable::filter_run_hook = sub {66 my ( $self, $hook, $args, $action ) = @_;67 64 68 is( $hook, 'dispatch' ); 69 is( $args, undef ); 70 is_deeply( 71 $action, 72 { 73 plugin => $plugin, 74 callback => $plugin->can('foo'), 75 } 76 ); 65 $hook->hookable_set_filter( 66 'run_hook' => sub { 67 my ( $self, $filter, $hook, $args, $action ) = @_; 77 68 78 return 0; 79 }; 69 isa_ok( $self, 'Class::Hookable' ); 70 is( $filter, 'run_hook' ); 71 is( $hook, 'dispatch' ); 72 is( $args, undef ); 73 is_deeply( 74 $action, 75 { 76 plugin => $plugin, 77 callback => $plugin->can('foo'), 78 } 79 ); 80 81 return 0; 82 }, 83 ); 80 84 81 85 is(
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)