|
Revision 1833, 0.7 kB
(checked in by nyarla, 6 years ago)
|
|
lang/perl/Class-Hookable: Tagged version 0.01 release.
|
| Line | |
|---|
| 1 | #!perl -T
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 | use warnings;
|
|---|
| 5 |
|
|---|
| 6 | use Test::More tests => 3;
|
|---|
| 7 | use Class::Hookable;
|
|---|
| 8 |
|
|---|
| 9 | my $hook = Class::Hookable->new;
|
|---|
| 10 | my $plugin = Plugin->new;
|
|---|
| 11 |
|
|---|
| 12 | $hook->register_hook(
|
|---|
| 13 | $plugin,
|
|---|
| 14 | 'foo.bar' => $plugin->can('foo'),
|
|---|
| 15 | );
|
|---|
| 16 |
|
|---|
| 17 | is(
|
|---|
| 18 | $hook->hooks->{'foo.bar'}->[0]->{'plugin'},
|
|---|
| 19 | $plugin,
|
|---|
| 20 | );
|
|---|
| 21 |
|
|---|
| 22 | is(
|
|---|
| 23 | $hook->hooks->{'foo.bar'}->[0]->{'callback'},
|
|---|
| 24 | $plugin->can('foo'),
|
|---|
| 25 | );
|
|---|
| 26 |
|
|---|
| 27 | {
|
|---|
| 28 | no warnings 'redefine';
|
|---|
| 29 | *Class::Hookable::filter_plugin = sub { 0 };
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | $hook->register_hook(
|
|---|
| 33 | $plugin,
|
|---|
| 34 | 'AAA.BBB' => $plugin->can('bar'),
|
|---|
| 35 | );
|
|---|
| 36 |
|
|---|
| 37 | is(
|
|---|
| 38 | $hook->hooks->{'foo.bar'}->[1],
|
|---|
| 39 | undef,
|
|---|
| 40 | );
|
|---|
| 41 |
|
|---|
| 42 | package Plugin;
|
|---|
| 43 |
|
|---|
| 44 | sub new { bless {}, shift }
|
|---|
| 45 | sub foo {}
|
|---|
| 46 | sub bar {}
|
|---|
| 47 |
|
|---|
| 48 | 1;
|
|---|
| 49 | __END__
|
|---|