examples/named-routes/app.pl

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 23 / 23 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« examples/lifespan-state/app.pl ↑ Summary examples/psgi-bridge/app.pl »
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 PAGI::Nano;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Named routes and link generation, including across a mount in both directions.
6 #
7 # A route is named with the name() marker; $c->uri_for('name', \%params, \%query)
8 # builds its URL. Names form one flat namespace across the whole app, so a
9 # mounted sub-app can link to a name in the parent and the parent can link to a
10 # name in the mount (mount prefixes are applied automatically).
11 #
12 # pagi-server app.pl
13 # curl http://127.0.0.1:5000/ # links to a mounted route
14 # curl http://127.0.0.1:5000/api/users/7 # links back to the parent's route
15  
16 1 ▶my $api = app {
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶ get '/users/:id' => name('user') => sub ($c, $id) {
Subroutine __ANON__: called CC=1 SCAR=0.0
18 {
19 1 id => $id,
20 self => $c->uri_for('user', { id => $id }), # own name
21 edit => $c->uri_for('user', { id => $id }, { edit => 1 }),
22 back_home => $c->uri_for('home'), # a name in the parent
23 };
24 1 };
25 1 };
26  
27 1 ▶my $app = app {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 1 ▶ get '/' => name('home') => sub ($c) {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 {
30 1 page => 'home',
31 first_user => $c->uri_for('user', { id => 1 }), # a name in the mount
32 };
33 1 };
34  
35 1 mount '/api' => $api;
36 1 };
37  
38 1 $app;
« examples/lifespan-state/app.pl ↑ Summary examples/psgi-bridge/app.pl »