Plans: New module for event registering and raising.

Hi Guys,

I'm about to start work on what should (initially) be a fairly simple
API for allowing modules to register for events within an application. I
think it's best explained with a simple code example, based on the
intended use for this application.

I haven't worked out all the details on this, including how each plug in
will pass back information on why it was unsuccessful, but that should
give you a general idea of my plan.

So, I have a couple of questions:

1. Does anyone know of a package on CPAN that does something similar to
this already?

2. Has anyone considered working on something similar in the past,
and/or have anything they'd like to contribute?

3. (last, but least) any suggestions on the namespace that this would
fall under?

Look forward to your replies :)

Thanks!

----
package Account::Event::Business;
use Account::Event;

Account::Event->register('ACCOUNT_CLOSE', &closeAccount );

sub closeAccount {
my ($account) = [at] _;
if ($account->someproperty eq 'somevalue') {
return 0; # Not allowed to close
}
return 1; # Didn't fail any checks in this plugin
}

----
package Account;
use Account::Event;

sub close {
my ($self) = [at] _;
$self->active(0); # For example;
if (! Account::Event->raise('ACCOUNT_CLOSE')) {
$self->rollback;
die "Can't close account";
} else {
$self->commit;
}
}

__END__
Lee Standen [ Mo, 30 April 2007 10:20 ] [ ID #1701632 ]

Re: Plans: New module for event registering and raising.

Never mind, the helpful lads in #Catalyst have pointed me towards
Class::Publisher :)

Lee Standen wrote:
> Hi Guys,
>
> I'm about to start work on what should (initially) be a fairly simple
> API for allowing modules to register for events within an application. I
> think it's best explained with a simple code example, based on the
> intended use for this application.
>
> I haven't worked out all the details on this, including how each plug in
> will pass back information on why it was unsuccessful, but that should
> give you a general idea of my plan.
>
> So, I have a couple of questions:
>
> 1. Does anyone know of a package on CPAN that does something similar to
> this already?
>
> 2. Has anyone considered working on something similar in the past,
> and/or have anything they'd like to contribute?
>
> 3. (last, but least) any suggestions on the namespace that this would
> fall under?
>
> Look forward to your replies :)
>
> Thanks!
>
> ----
> package Account::Event::Business;
> use Account::Event;
>
> Account::Event->register('ACCOUNT_CLOSE', &closeAccount );
>
> sub closeAccount {
> my ($account) = [at] _;
> if ($account->someproperty eq 'somevalue') {
> return 0; # Not allowed to close
> }
> return 1; # Didn't fail any checks in this plugin
> }
>
> ----
> package Account;
> use Account::Event;
>
> sub close {
> my ($self) = [at] _;
> $self->active(0); # For example;
> if (! Account::Event->raise('ACCOUNT_CLOSE')) {
> $self->rollback;
> die "Can't close account";
> } else {
> $self->commit;
> }
> }
>
> __END__
Lee Standen [ Mo, 30 April 2007 11:00 ] [ ID #1701633 ]
Perl » comp.lang.perl.modules » Plans: New module for event registering and raising.

Vorheriges Thema: Template Toolkit dropping errors
Nächstes Thema: LWP With Privoxy