Changeset 2102 for lang/perl/Class-Hookable
- Timestamp:
- 11/28/07 13:34:40 (14 months ago)
- Location:
- lang/perl/Class-Hookable/trunk
- Files:
-
- 2 modified
-
lib/Class/Hookable.pm (modified) (12 diffs)
-
t/02_register/00_register_hook.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Class-Hookable/trunk/lib/Class/Hookable.pm
r2101 r2102 10 10 11 11 sub new { bless {}, shift } 12 13 sub hooks {14 my ( $self ) = @_;15 16 if ( ref $self->{'Class::Hookable'} ne 'HASH' ) {17 $self->{'Class::Hookable'} = {18 hooks => {},19 };20 }21 22 return $self->{'Class::Hookable'}->{'hooks'};23 }24 12 25 13 sub hookable_stash { … … 52 40 } 53 41 42 sub hookable_all_hooks { 43 my $self = shift; 44 return $self->hookable_stash->{'hooks'}; 45 } 46 54 47 sub hookable_set_filter { 55 48 my ( $self, @filters ) = @_; … … 113 106 114 107 if ( $self->hookable_call_filter( 'register_hook', $hook, $action ) ) { 115 $self->hook s->{$hook} = []116 if ( ref $self->hook s->{$hook} ne 'ARRAY' );117 118 push @{ $self->hook s->{$hook} }, $action;108 $self->hookable_all_hooks->{$hook} = [] 109 if ( ref $self->hookable_all_hooks->{$hook} ne 'ARRAY' ); 110 111 push @{ $self->hookable_all_hooks->{$hook} }, $action; 119 112 } 120 113 } … … 131 124 my @hooks = (); 132 125 133 for my $hook ( keys %{ $self->hook s } ) {134 for my $action ( @{ $self->hook s->{$hook} } ) {126 for my $hook ( keys %{ $self->hookable_all_hooks } ) { 127 for my $action ( @{ $self->hookable_all_hooks->{$hook} } ) { 135 128 my $plugin = $action->{'plugin'}; 136 129 my $class = ref $plugin || $plugin; … … 152 145 Carp::croak "Hook name is not specified." if ( ! defined $hook ); 153 146 154 my $list = $self->hook s->{$hook};147 my $list = $self->hookable_all_hooks->{$hook}; 155 148 $list ||= []; 156 149 … … 166 159 167 160 my $is_class = ( ! ref $object ) ? 1 : 0 ; 168 @hooks = keys %{ $self->hook s } if ( @hooks == 0 );161 @hooks = keys %{ $self->hookable_all_hooks } if ( @hooks == 0 ); 169 162 170 163 for my $hook ( $self->registered_hooks( $object ) ) { … … 183 176 } 184 177 185 $self->hook s->{$hook} = \@actions;178 $self->hookable_all_hooks->{$hook} = \@actions; 186 179 } 187 180 … … 194 187 195 188 if ( @plugins == 0 ) { 196 $self->hook s->{$hook} = [];189 $self->hookable_all_hooks->{$hook} = []; 197 190 } 198 191 else { … … 276 269 Nothing but that is being done. 277 270 278 =head2 hookable_stash279 280 my $data = $hook->hookable_stash;281 282 This method is stash in Class::Hookable.283 All variables Class::Hookable needs are put here.284 285 This method does not get arguments,286 and return hash reference includes all variables.287 288 =head2 hookable_context289 290 # set291 $hook->hookable_context( $context );292 # get293 my $context = $hook->hookable_context;294 295 This method is accessor of context object.296 297 blessed object or class name is specified as the context object.298 299 Context object specified by this method is passed as the second argument of300 the subroutine registered with hook and method.301 302 see also L<"run_hook">.303 304 271 =head1 REGISTER METOHDS 305 272 … … 418 385 =item C<$args> 419 386 420 C<$args>specified by the run_hook method.387 the argument specified by the run_hook method. 421 388 422 389 =back 423 390 391 B<Arguments of C<$hook-E<gt>hookable_call_filter>>: 392 393 $hook->hookable_call_filter( 'run_hook', $hook, $args, $action ); 424 394 425 395 Only when C<$hook-E<gt>hookable_call_filter( 'run_hook', $hook, $args, $action )> has returned truth, … … 427 397 428 398 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 399 434 400 =over 4 … … 591 557 =head1 ACCESSOR METOHDS 592 558 593 =head2 hooks 594 595 my $hooks = $hook->hooks; 559 =head2 hookable_stash 560 561 my $data = $hook->hookable_stash; 562 563 This method is stash in Class::Hookable. 564 All variables Class::Hookable needs are put here. 565 566 This method does not get arguments, 567 and return hash reference includes all variables. 568 569 =head2 hookable_context 570 571 # set 572 $hook->hookable_context( $context ); 573 # get 574 my $context = $hook->hookable_context; 575 576 This method is accessor of context object. 577 578 blessed object or class name is specified as the context object. 579 580 Context object specified by this method is passed as the second argument of 581 the subroutine registered with hook and method. 582 583 see also L<"run_hook">. 584 585 =head2 hookable_all_hooks 586 587 my $hooks = $hook->hookable_all_hooks; 596 588 597 589 This method is accessor to hash reference which keeps hooks. -
lang/perl/Class-Hookable/trunk/t/02_register/00_register_hook.t
r2101 r2102 16 16 17 17 is( 18 $hook->hook s->{'foo.bar'}->[0]->{'plugin'},18 $hook->hookable_all_hooks->{'foo.bar'}->[0]->{'plugin'}, 19 19 $plugin, 20 20 ); 21 21 22 22 is( 23 $hook->hook s->{'foo.bar'}->[0]->{'callback'},23 $hook->hookable_all_hooks->{'foo.bar'}->[0]->{'callback'}, 24 24 $plugin->can('foo'), 25 25 ); … … 47 47 48 48 is( 49 $hook->hook s->{'foo.bar'}->[1],49 $hook->hookable_all_hooks->{'foo.bar'}->[1], 50 50 undef, 51 51 );
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)