| 1 | 2 | ▶ | use v5.40; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 2 | ▶ | use experimental 'signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use Future::AsyncAwait; # handlers that use await must be `async sub` |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use PAGI::Nano; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | # Quickstart single-file app. Run it with: | ||
| 7 | # | ||
| 8 | # pagi-server app.pl | ||
| 9 | # | ||
| 10 | # The file's last expression is the assembled PAGI app, which pagi-server runs. | ||
| 11 | # (If you add a ./lib, put it on @INC the standard way with | ||
| 12 | # `use FindBin; use lib "$FindBin::Bin/lib";` — Nano never touches @INC.) | ||
| 13 | |||
| 14 | 2 | ▶ | my $app = app { |
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||
| 15 | 0 | ▶ | startup async sub ($state) { $state->{started} = 1 }; |
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||
| 16 | |||
| 17 | 2 | enable 'GZip'; | |
| 18 | |||
| 19 | 2 | ▶ | get '/' => sub ($c) { 'Hello from PAGI::Nano' }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 20 | |||
| 21 | 2 | ▶ | get '/hello/:name' => sub ($c, $name) { { hello => $name } }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 0 | ▶ | post '/echo' => async sub ($c) { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 24 | 0 | my $clean = await $c->params->permitted('message'); | |
| 25 | 0 | $c->json($clean, status => 201); | |
| 26 | 2 | }; | |
| 27 | 2 | }; | |
| 28 | |||
| 29 | 2 | $app; | |