| 1 | 1 | ▶ | use v5.40; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use experimental 'signatures'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Future::AsyncAwait; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Future::IO; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use PAGI::Nano; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | # Ports PAGI's "mini-framework" example to PAGI::Nano. | ||
| 8 | # | ||
| 9 | # That example hand-rolls a ~50-line micro-framework to prove a framework is just | ||
| 10 | # a thin layer over the PAGI protocol. PAGI::Nano *is* that idea, finished: the | ||
| 11 | # same routes (a greeting, a path parameter, an async handler) with nothing to | ||
| 12 | # hand-roll. | ||
| 13 | # | ||
| 14 | # pagi-server app.pl | ||
| 15 | |||
| 16 | 1 | ▶ | my $app = app { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.8
| |||
| 17 | 1 | ▶ | get '/' => sub ($c) { 'PAGI::Nano is the mini-framework, finished.' }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | 1 | ▶ | get '/hello/:name' => sub ($c, $name) { "Hello, $name!" }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 20 | |||
| 21 | 0 | ▶ | get '/slow/:secs' => async sub ($c, $secs) { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 22 | 0 | await Future::IO->sleep($secs); # async handler; the loop stays free | |
| 23 | 0 | "waited ${secs}s"; | |
| 24 | 1 | }; | |
| 25 | 1 | }; | |
| 26 | |||
| 27 | 1 | $app; | |