Commit 06431d71 authored by Xavier Guimard's avatar Xavier Guimard

New endpoint: afterSub

parent 1e3ab69b
......@@ -68,6 +68,9 @@ BEGIN {
}
}
# Endpoints inserted after any main sub
has 'afterSub' => ( is => 'rw', default => sub { {} } );
has spRules => (
is => 'rw',
default => sub { {} }
......@@ -369,6 +372,26 @@ sub findEP {
}
}
}
if ( $obj->can('afterSub') ) {
$self->logger->debug("Found afterSub in $plugin");
my $h = $obj->afterSub;
unless ( ref $h and ref($h) eq 'HASH' ) {
$self->logger->error(
'"afterSub" endpoint must be a hashref, skipped');
}
else {
foreach my $ep ( keys %$h ) {
my $callback = $h->{$ep};
push @{ $self->afterSub->{$ep} }, sub {
eval {
$obj->logger->debug(
"Launching ${plugin}::$callback afterSub $ep");
};
$obj->$callback( $_[0] );
};
}
}
}
$self->logger->debug("Plugin $plugin initializated");
# Rules for menu
......
......@@ -170,6 +170,18 @@ process
=item C<beforeLogout>: method called before logout
=item C<afterSub>: hash ref that give methods to call after given main method
is called. Example:
use constant afterSub => {
getUser => 'mysub',
}
sub mysub {
my ( $self ,$req ) = @_;
# Do something
return PE_OK;
}
=back
B<Note>: methods inserted so must return a PE_* constant. See
......
......@@ -28,6 +28,9 @@ sub process {
else {
$self->logger->debug("Processing $sub");
last if ( $err = $self->$sub( $req, %args ) );
if ( $self->afterSub->{$sub} ) {
unshift @{ $req->steps }, @{ $self->afterSub->{$sub} };
}
}
}
$self->logger->debug("Returned error: $err") if ($err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment