Any-Daemon-HTTP

 view release on metacpan or  search on metacpan

lib/Any/Daemon/HTTP/VirtualHost.pod  view on Meta::CPAN

When only CODE is given, then this will be the default handler for all
paths (under '/', top). [0.21] CODE may also be a $method name.

Usually, you pass some PAIRS or a HASH, relating PATH names inside
the virtual host into function references or method names to be used for
that tree.

example: 

  $vhost->addHandler('/' => \&default_handler
     , '/upload' => \&upload_handler);

  $vhost->addHandler(\&default_handler);

  # [0.21] will call $vhost->formHandle
  $vhost->addHandler('/form' => 'formHandler');

=item $obj-E<gt>B<addHandlers>($params)

Alias for L<addHandler()|Any::Daemon::HTTP::VirtualHost/"Handler">.

lib/Any/Daemon/HTTP/VirtualHost.pod  view on Meta::CPAN

=head2 Handlers

Handlers are called to dynamically generate responses, for instance
to fill-in templates.  In other frameworks, they are called 'routes'
or 'get'.

When a request for an URI is received, it is first checked whether
a static file can fulfil the request.  If not, a search is started
for the handler with the longest path.

  # /upload($|/*) goes to the upload_handler
  $vhost->addHandlers
    ( '/'       => \&default_handler
    , '/upload' => \&upload_handler
    );

  # Missing files go to the default_handler
  # which is actually replacing the existing one
  $vhost->addHandler(\&default_handler);

  # [0.21] This will call $vhost->formHandle(...), especially
  # useful in your virtual host sub-class.
  $vhost->addHandler('/form' => 'formHandler');

The handlers are called with many arguments, and should return an
HTTP::Response object:

  $vhost->addHandler('/upload' => $handler);
  my $resp = $hander->($vhost, $session, $req, $uri, $tree);

  $vhost->addHandler('/form' => $method);
  my $resp = $vhost->$method($session, $req, $uri, $tree);

In which

=over 4

=item * C<$vhost> is an C<Any::Daemon::HTTP::VirtualHost>,



( run in 2.186 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )