Changeset 2390 for lang/perl/Class-Hookable
- Timestamp:
- 12/04/07 11:23:01 (13 months ago)
- Location:
- lang/perl/Class-Hookable/trunk
- Files:
-
- 1 added
- 2 modified
-
lib/Class/Hookable.pm (modified) (4 diffs)
-
t/03_utility/00_registered_hooks.t (modified) (1 diff)
-
t/03_utility/02_registered_methods.t (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Class-Hookable/trunk/lib/Class/Hookable.pm
r2279 r2390 7 7 use Scalar::Util(); 8 8 9 our $VERSION = '0.02'; 9 use vars qw( $VERSION ); 10 $VERSION = '0.03'; 10 11 11 12 sub new { bless {}, shift } … … 171 172 } 172 173 174 @hooks = sort { $a cmp $b } @hooks; 173 175 return @hooks; 174 176 } … … 183 185 184 186 return @{ $list }; 187 } 188 189 sub registered_methods { 190 my $self = shift; 191 my @methods = (); 192 193 if ( @_ > 0 ) { 194 my $object = shift; 195 196 if ( ref $object && ! Scalar::Util::blessed($object) ) { 197 Carp::croak "Argument is not blessed object or class name."; 198 } 199 200 my $is_class = ( ! ref $object ) ? 1 : 0 ; 201 202 for my $method ( keys %{ $self->hookable_all_methods } ) { 203 my $plugin = $self->hookable_all_methods->{$method}->{'plugin'}; 204 my $class = ref $plugin || $plugin; 205 if ( $is_class ) { 206 push @methods, $method if ( $class eq $object ); 207 } 208 else { 209 push @methods, $method if ( $plugin eq $object ); 210 } 211 } 212 } 213 else { 214 @methods = keys %{ $self->hookable_all_methods }; 215 } 216 217 @methods = sort { $a cmp $b } @methods; 218 return @methods; 185 219 } 186 220 … … 606 640 Return value is a list of hash reference including plugin and callback. 607 641 642 =head2 registered_methods 643 644 my @methods = $hook->registered_methods( $plugin ); 645 my @methods = $hook->registered_methods( 'ClassName' ); 646 647 This method returns a registered method name. 648 649 When calling without arguments, all registered method name is returned. 650 and When specifying plugin object (or class name) as an arguments, 651 the method name with which a plugin is registered is returned. 652 608 653 =head2 delete_plugin 609 654 -
lang/perl/Class-Hookable/trunk/t/03_utility/00_registered_hooks.t
r2120 r2390 25 25 is_deeply( 26 26 [ $hook->registered_hooks ], 27 [ qw( foo.bar bar.baz baz.foo) ],27 [ qw( bar.baz baz.foo foo.bar ) ], 28 28 ); 29 29 30 30 is_deeply( 31 31 [ $hook->registered_hooks( $pluginA ) ], 32 [ qw( foo.bar bar.baz) ],32 [ qw( bar.baz foo.bar) ], 33 33 ); 34 34 35 35 is_deeply( 36 36 [ $hook->registered_hooks('PluginB') ], 37 [ qw( foo.bar baz.foo) ],37 [ qw( baz.foo foo.bar ) ], 38 38 ); 39 39
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)