|
Revision 4056, 1.0 kB
(checked in by nyarla, 5 years ago)
|
|
lang/perl/Class-Hookable: The dummy class was made a module.
|
| Line | |
|---|
| 1 | #!perl -T
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 | use warnings;
|
|---|
| 5 |
|
|---|
| 6 | use Test::More tests => 6;
|
|---|
| 7 | use Class::Hookable;
|
|---|
| 8 | use lib 't';
|
|---|
| 9 | use DummyClass;
|
|---|
| 10 |
|
|---|
| 11 | my $hook = Class::Hookable->new;
|
|---|
| 12 | my $plugin = Plugin->new;
|
|---|
| 13 |
|
|---|
| 14 | $hook->register_method(
|
|---|
| 15 | $plugin,
|
|---|
| 16 | 'foo.bar' => $plugin->can('foo'),
|
|---|
| 17 | );
|
|---|
| 18 |
|
|---|
| 19 | is_deeply(
|
|---|
| 20 | $hook->hookable_all_methods->{'foo.bar'},
|
|---|
| 21 | {
|
|---|
| 22 | plugin => $plugin,
|
|---|
| 23 | function => $plugin->can('foo'),
|
|---|
| 24 | },
|
|---|
| 25 | );
|
|---|
| 26 |
|
|---|
| 27 | $hook->hookable_set_filter(
|
|---|
| 28 | 'register_method' => sub {
|
|---|
| 29 | my ( $self, $filter, $method, $action ) = @_;
|
|---|
| 30 | isa_ok( $self, 'Class::Hookable' );
|
|---|
| 31 | is( $filter, 'register_method' );
|
|---|
| 32 | is( $method, 'bar.baz' );
|
|---|
| 33 | is_deeply(
|
|---|
| 34 | $action,
|
|---|
| 35 | {
|
|---|
| 36 | plugin => $plugin,
|
|---|
| 37 | function => $plugin->can('bar'),
|
|---|
| 38 | },
|
|---|
| 39 | );
|
|---|
| 40 | return 0;
|
|---|
| 41 | },
|
|---|
| 42 | );
|
|---|
| 43 |
|
|---|
| 44 | $hook->register_method(
|
|---|
| 45 | $plugin,
|
|---|
| 46 | 'bar.baz' => $plugin->can('bar'),
|
|---|
| 47 | );
|
|---|
| 48 |
|
|---|
| 49 | is(
|
|---|
| 50 | $hook->hookable_all_methods->{'bar.baz'},
|
|---|
| 51 | undef,
|
|---|
| 52 | );
|
|---|