File: dispatchex.cgi

package info (click to toggle)
libweb-simple-perl 0.033-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 1,622; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 603 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Web::Simple 'DispatchEx';

package DispatchEx;

dispatch {
  response_filter {
    [ 200, [ 'Content-type' => 'text/plain' ], $_[1] ];
  },
  subdispatch sub (.html) {
    [
      response_filter { [ @{$_[1]}, '.html' ] },
      sub (/foo) { [ '/foo' ] },
    ]
  },
  subdispatch sub (/domain/*/...) {
    return unless (my $domain_id = $_[1]) =~ /^\d+$/;
    [
      sub (/) {
        [ "Domain ${domain_id}" ]
      },
      sub (/user/*) {
        return unless (my $user_id = $_[1]) =~ /^\d+$/;
        [ "Domain ${domain_id} user ${user_id}" ]
      }
    ]
  }
};

DispatchEx->run_if_script;