Created
November 18, 2011 16:45
-
-
Save Akron/1376998 to your computer and use it in GitHub Desktop.
Filtering in Mojolicious
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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