Skip to content

Instantly share code, notes, and snippets.

@Akron
Created November 18, 2011 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akron/1376998 to your computer and use it in GitHub Desktop.
Save Akron/1376998 to your computer and use it in GitHub Desktop.
Filtering in Mojolicious
# Some values.
my ($a, $b, $c) = ('hallo', 'foo', 'bar');
# Emit a filter hook
$c->filter(
'on_database_access' =>
\$a, \$b, \$c =>
sub { # Do whenever all subscribers are done.
print $a,"\n";
}
);
# Establish a filter on an event.
# This can be async
$c->hook_on_filter(
'on_database_access' => sub {
my ($filter, $a_ref, $b_ref, $c_ref) = @_;
$$a_ref =~ s/a/e/;
# I don't know if this is needed.
# Just a next tick thing,
# executing the callback of the next filter in chain
$filter->next;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment