Created
October 15, 2009 11:22
-
-
Save hidek/210896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment