hidek (owner)

Revisions

gist: 210896 Download_button fork
public
Public Clone URL: git://gist.github.com/210896.git
Embed All Files: show embed
test.pl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
 
    package Bar;
    use strict;
    use warnings;
 
    use base qw(Class::Accessor::Fast);
 
    sub register_hook {
        my ($self, $context) = @_;
 
        $context->add_trigger(
            name => 'hook',
            callback => $self->can('bar'),
        );
    }
 
    sub bar {
        my ($self, $bar) = @_;
 
        warn $self;
        warn $bar;
    }
}
 
{
 
    package Foo;
    use strict;
    use warnings;
 
    use base qw(Class::Accessor::Fast);
    use Class::Trigger;
 
    sub new {
        my $class = shift;
 
        my $self = bless {}, $class;
        my $plugin = Bar->new;
        $plugin->register_hook($self);
        return $self;
    }
 
    sub run {
        my $self = shift;
 
        $self->call_trigger('hook', 'BAR');
    }
}
 
my $foo = Foo->new;
$foo->run;