El Módulo HTTP::Server::Simple::Dispatched

pp2@nereida:~/src/testing$ cat -n simpledispatch.pl
 1      use HTTP::Server::Simple::Dispatched qw(static);
 2
 3      my $server = HTTP::Server::Simple::Dispatched->new(
 4        hostname => 'localhost',
 5        port     => 8081,
 6        debug    => 1,
 7        dispatch => [
 8          qr{^/hello/} => sub {
 9            my ($response) = @_;
10            $response->content_type('text/plain');
11            $response->content("Hello, world!");
12            return 1;
13          },
14          qr{^/say/(\w+)/} => sub {
15            my ($response) = @_;
16            $response->content_type('text/plain');
17            $response->content("You asked me to say $1.");
18            return 1;
19          },
20          qr{^/counter/} => sub {
21            my ($response, $request, $context) = @_;
22            my $num = ++$context->{counter};
23            $response->content_type('text/plain');
24            $response->content("Called $num times.");
25            return 1;
26          },
27          qr{^/static/(.*\.(?:png|gif|jpg))} => static("t/"),
28          qr{^/error/} => sub {
29            die "This will cause a 500!";
30          },
31        ],
32      );
33
34      $server->run();

Casiano Rodríguez León
Licencia de Creative Commons
Programación Distribuida y Mejora del Rendimiento
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=44.
2012-06-19