-
-
Save anonymous/28dd60678081739d2899 to your computer and use it in GitHub Desktop.
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
diff --git a/README.md b/README.md | |
index 91cd751..702557a 100644 | |
--- a/README.md | |
+++ b/README.md | |
@@ -66,16 +66,16 @@ app->start; | |
applications. | |
```perl | |
+use 5.20.0; | |
+use experimental 'signatures'; | |
use Mojolicious::Lite; | |
# Render template "index.html.ep" from the DATA section | |
get '/' => {template => 'index'}; | |
# WebSocket service used by the template to extract the title from a web site | |
-websocket '/title' => sub { | |
- my $c = shift; | |
- $c->on(message => sub { | |
- my ($c, $msg) = @_; | |
+websocket '/title' => sub ($c) { | |
+ $c->on(message => sub ($c, $msg) { | |
my $title = $c->ua->get($msg)->res->dom->at('title')->text; | |
$c->send($title); | |
}); | |
diff --git a/lib/Mojolicious.pm b/lib/Mojolicious.pm | |
index 0df66ac..dbb7824 100644 | |
--- a/lib/Mojolicious.pm | |
+++ b/lib/Mojolicious.pm | |
@@ -218,21 +218,23 @@ Mojolicious - Real-time web framework | |
# Application | |
package MyApp; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
use Mojo::Base 'Mojolicious'; | |
# Route | |
- sub startup { | |
- my $self = shift; | |
+ sub startup ($self) { | |
$self->routes->get('/hello')->to('foo#hello'); | |
} | |
# Controller | |
package MyApp::Controller::Foo; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
use Mojo::Base 'Mojolicious::Controller'; | |
# Action | |
- sub hello { | |
- my $self = shift; | |
+ sub hello ($self) { | |
$self->render(text => 'Hello World!'); | |
} | |
@@ -249,8 +251,9 @@ L<Mojolicious> will emit the following hooks in the listed o | |
Emitted right after the transaction is built and before the HTTP request gets | |
parsed. | |
- $app->hook(after_build_tx => sub { | |
- my ($tx, $app) = @_; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(after_build_tx => sub ($tx, $app) { | |
... | |
}); | |
@@ -263,8 +266,9 @@ application object) | |
Emitted right before the static file server and router start their work. | |
- $app->hook(before_dispatch => sub { | |
- my $c = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(before_dispatch => sub ($c) { | |
... | |
}); | |
@@ -276,8 +280,9 @@ Very useful for rewriting incoming requests and other prepro | |
Emitted after a static file response has been generated by the static file | |
server. | |
- $app->hook(after_static => sub { | |
- my $c = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(after_static => sub ($c) { | |
... | |
}); | |
@@ -289,8 +294,9 @@ controller object) | |
Emitted after the static file server determined if a static file should be | |
served and before the router starts its work. | |
- $app->hook(before_routes => sub { | |
- my $c = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(before_routes => sub ($c) { | |
... | |
}); | |
@@ -304,8 +310,9 @@ to manually forward to the next hook if you want to continue | |
Default action dispatching is the last hook in the chain, yours will run | |
before it. | |
- $app->hook(around_action => sub { | |
- my ($next, $c, $action, $last) = @_; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(around_action => sub ($next, $c, $action, $last) { | |
... | |
return $next->(); | |
}); | |
@@ -322,8 +329,9 @@ Emitted before content is generated by the renderer. Note th | |
trigger out of order due to its dynamic nature, and with embedded applications | |
will only work for the application that is rendering. | |
- $app->hook(before_render => sub { | |
- my ($c, $args) = @_; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(before_render => sub ($c, $args) { | |
... | |
}); | |
@@ -337,8 +345,9 @@ to the response. Note that this hook can trigger out of orde | |
dynamic nature, and with embedded applications will only work for the | |
application that is rendering. | |
- $app->hook(after_render => sub { | |
- my ($c, $output, $format) = @_; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(after_render => sub ($c, $output, $format) { | |
... | |
}); | |
@@ -351,8 +360,9 @@ Emitted in reverse order after a response has been rendered. | |
hook can trigger out of order due to its dynamic nature, and with embedded | |
applications will only work for the application that is rendering. | |
- $app->hook(after_dispatch => sub { | |
- my $c = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(after_dispatch => sub ($c) { | |
... | |
}); | |
@@ -368,8 +378,9 @@ L<Mojolicious::Plugin::DefaultHelpers/"reply-E<gt>exception" | |
hook in the chain and a call to L</"dispatch"> the last, yours will be in | |
between. | |
- $app->hook(around_dispatch => sub { | |
- my ($next, $c) = @_; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(around_dispatch => sub ($next, $c) { | |
... | |
$next->(); | |
... | |
@@ -610,8 +621,9 @@ Extend L<Mojolicious> with hooks, which allow code to be sha | |
requests indiscriminately, for a full list of available hooks see L</"HOOKS">. | |
# Dispatchers will not run if there's already a response code defined | |
- $app->hook(before_dispatch => sub { | |
- my $c = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ $app->hook(before_dispatch => sub ($c) { | |
$c->render(text => 'Skipped static file server and router!') | |
if $c->req->url->path->to_route =~ /do_not_dispatch/; | |
}); | |
@@ -659,8 +671,9 @@ commands available by default see L<Mojolicious::Commands/"C | |
This is your main hook into the application, it will be called at application | |
startup. Meant to be overloaded in a subclass. | |
- sub startup { | |
- my $self = shift; | |
+ use 5.20.0; | |
+ use experimental 'signatures'; | |
+ sub startup ($self) { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment