위키로그:2019/03/18 - Mojolicious의 around action() 훅

From PGWiki
Mojolicious
162 sub hook { shift->plugins->on(@_) }
Mojolicious::EventEmitter
27 sub on { push @{$_[0]{events}{$_[1]}}, $_[2] and return $_[2] }
Mojolicious::Plugin
 9 sub emit_chain {
10   my ($self, $name, @args) = @_;
11 
12   my $wrapper;
13   for my $cb (reverse @{$self->subscribers($name)}) {
14     my $next = $wrapper;
15     $wrapper = sub { $cb->($next, @args) };
16   }
17 
18   !$wrapper ? return : return $wrapper->();
19 }
Mojolicious::Routes
87 sub _action { shift->plugins->emit_chain(around_action => @_) }
88 
89 sub _callback {
90   my ($self, $c, $cb, $last) = @_;
91   $c->stash->{'mojo.routed'} = 1 if $last;
92   my $app = $c->app;
93   $app->log->debug('Routing to a callback');
94   return _action($app, $c, $cb, $last);
95 }

바깥 고리