Skip to content

Instantly share code, notes, and snippets.

@hidek
Created October 15, 2009 11:22
Show Gist options
  • Select an option

  • Save hidek/210896 to your computer and use it in GitHub Desktop.

Select an option

Save hidek/210896 to your computer and use it in GitHub Desktop.
{
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