For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > April 2007 > Plans: New module for event registering and raising.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Plans: New module for event registering and raising.
Lee Standen

2007-04-30, 3:57 am

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) = @_;
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) = @_;
$self->active(0); # For example;
if (! Account::Event->raise('ACCOUNT_CLOSE')) {
$self->rollback;
die "Can't close account";
} else {
$self->commit;
}
}

__END__
Lee Standen

2007-04-30, 6:58 pm

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) = @_;
> 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) = @_;
> $self->active(0); # For example;
> if (! Account::Event->raise('ACCOUNT_CLOSE')) {
> $self->rollback;
> die "Can't close account";
> } else {
> $self->commit;
> }
> }
>
> __END__

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com