The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

PGXN::Site::Controller - The PGXN::Site request controller

Synopsis

  use PGXN::Site::Controller;
  use Router::Resource;

  my $controller = PGXN::Site::Controller->new(url => 'http://api.pgxn.org');
  my $router = router {
      resource '/' => sub {
          GET { $controller->home(@_) };
      };
  };

Description

This class defines controller actions for PGXN::Site requests. It's designed to be called from within Router::Resource HTTP methods.

Interface

Constructor

new

  my $controller = PGXN::Site::Controller->new(url => $private_api_url);

Constructs and returns a new controller. The parameters are the same as those supported by WWW::PGXN, which will be used to fetch the data needed to serve pages.

Accessors

api

  my $api = $controller->api;

Returns a WWW::PGXN object used to access the PGXN API.

api_url

  my $api_url = $controller->api_url;

Returns the URL used to link to the API in the UI. If private_api_url is not passed to new(), this URL is also used for communicating with the API via the WWW::PGXN object returned by api.

errors_to

  my $errors_to = $controller->errors_to;

Returns the email address to which error messages will be sent.

errors_from

  my $errors_from = $controller->errors_from;

Returns the email address from which error messages will be sent to errors_to.

feedback_to

  my $feedback_to = $controller->feedback_to;

Returns the email address listed in the UI for sending feedback.

Actions

home

  PGXN::Site::Controller->home($env);

Displays the HTML for the home page.

feedback

  PGXN::Site::Controller->feedback($env);

Displays the HTML for the feedback page.

art

  PGXN::Site::Controller->art($env);

Displays the HTML for the identity page.

about

  PGXN::Site::Controller->about($env);

Displays the HTML for the about page.

donors

  PGXN::Site::Controller->donors($env);

Displays the HTML for the donors page.

recent

  PGXN::Site::Controller->recent($env);

Displays the HTML for the recent releases page.

mirroring

  PGXN::Site::Controller->mirroring($env);

Displays the HTML for the mirroring page.

spec

  PGXN::Site::Controller->spec($env, $format);

Displays the HTML or plain text for the PGXN Meta Spec.

faq

  PGXN::Site::Controller->faq($env);

Displays the HTML for the FAQ page.

distribution

  PGXN::Site::Controller->distribution($env);

Displays the HTML for the distribution page.

document

  PGXN::Site::Controller->document($env);

Displays the HTML for the document page.

user

  PGXN::Site::Controller->user($env);

Displays the HTML for the user page.

users

  PGXN::Site::Controller->users($env);

Displays the HTML for the users search page.

tag

  PGXN::Site::Controller->tag($env);

Displays the HTML for the tag page.

extension

  PGXN::Site::Controller->extension($env);

Displays the HTML for the extension page.

  PGXN::Site::Controller->search($env);

Displays the HTML for the search page.

server_error

Handles subrequests from Plack::Middleware::ErrorDocument when a 500 is returned. Best way to set it up is to add these three middlewares to the production configuration file:

    "middleware": [
        ["ErrorDocument", 500, "/error", "subrequest", 1],
        ["HTTPExceptions"],
        ["StackTrace", "no_print_errors", 1]
    ],

Methods

render

  $controller->render('/home', $req, @template_args);

Renders the response to the request using PGXN::Site::Templates.

redirect

  $controller->render('/home', $req);

Redirect the request to a new page.

missing

  $controller->missing($env, $data);

Handles 404 and 405 errors from Router::Resource.

success
forbidden
notfound

Author

David E. Wheeler <david.wheeler@pgexperts.com>

Copyright and License

Copyright (c) 2010-2011 David E. Wheeler.

This module is free software; you can redistribute it and/or modify it under the PostgreSQL License.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.

In no event shall David E. Wheeler be liable to any party for direct, indirect, special, incidental, or consequential damages, including lost profits, arising out of the use of this software and its documentation, even if David E. Wheeler has been advised of the possibility of such damage.

David E. Wheeler specifically disclaims any warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The software provided hereunder is on an "as is" basis, and David E. Wheeler has no obligations to provide maintenance, support, updates, enhancements, or modifications.