View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Ivan Tubert-Brohman > AnnoCPAN > AnnoCPAN::Control



Annotate this POD


New  17
Open  6
View/Report Bugs
Module Version: 0.22   Source  


AnnoCPAN::Control - Main AnnoCPAN Web Interface Control Module


    # in the simplest case, this is all you need...
    use AnnoCPAN::Control;


This is the main module that handles the AnnoCPAN web application. It handles getting the CGI parameters, running the appropriate handlers, and making sure that the appropriate templates are processed.



Create a new AnnoCPAN control object. Options:

 cgi => cgi object
 tt  => template object

Process the request. This includes figuring out the runmode, checking if the user is logged in, running the handler, printing the headers, and processing the template.


Return the runmode. Runmodes must be made of word characters, begin with an uppercase letter, and be a method in $obj.


Returns the CGI object.


Returns the Template object.


Get CGI parameters. Delegated to $self->cgi.


Return HTTP headers as a string. Delegated to $self->cgi.


Print a 303 HTTP redirect header, including the cookies in $obj->cookies.

$obj->process($template_file, \%vars [, \$ret])

Process a template. Delegated to $self->tt.


Return a hashref with the default template variables, common to all runmodes (for example, the user object).


Returns the value for a given user preference.


Return an arrayref with the current cookies (which are CGI::Cookie objects).

$obj->add_cookie($name, $value)

Create a cookie. It will be later pushed to the client with the HTTP headers, and it is immediately available via $obj->cookies.


Issue an expired cookie with a given name, forcing the client to forget it (one use is for logging out).


Check if the user is logged in (by checking the login, time, and key cookies); Returns an AnnoCPAN::DBI::User object if logged in, or false if not.


Creates the login cookies for $user (which should be an AnnoCPAN::DBI::User object).


May be used to set an arbitrary user (to force a login). If no $user is provided (and none has been provided before), returns whatever check_login would return (a user object or false).

$obj->key($login, $time)

Returns a login key as a string. Depends on the "secret" configuration option.

Runmode methods

A runmode method has the following characteristics:

1) Its name matches /[A-Z]\w+/

2) Returns a list ($vars, $template, $type). $vars is a hash reference of variables that should be passed to the template; $template is the name of the template that should be processed (sans the extension). $type is the MIME type that should be given in the header. $type is optional; it defaults to text/html. If $template is false, no headers will be printed and no template will be processed.

3) Takes an optional parameter $vars. If given, it is expected to be a hash reference which will be appended to the variables normally returned by the method. It is used when one mode decides to fall back to another but wants to add or override some variables of its own.

For example, the Main method could be:

    sub Main {
        my ($self, $vars) = @_;
        $vars ||= {};
        my @recent = AnnoCPAN::DBI::Note->search_recent;
        ({recent => \@recent, %$vars}, "main");

Warning: the documentation below may be slighly incomplete or outdated:


The front page. Provides the "recent notes" list.


Displays one POD page. Uses the pid CGI parameter.


Displays the POD page that is the "main reference" for a given note. Uses the id CGI parameter.


Displays one distribution (distver) page. Uses the id CGI parameter or $vars->{distver}.


The edit screen (like Show, but includes the edit form).


The "about" page. Uses the about.pod file.


Save a new note (comes from the Edit mode). Uses the pid, pos, id, and note CGI parameters.


"Create new user" screen.


Coming from the New_user form, create a new account. Uses the login, passwd, passwd2, and email CGI parameters. Checks that the login and password are not blank, that the passwords match, and that the login is not already taken.


Log in; comes from the login form on login_form.html. Uses the login and passwd CGI parameters.


Log out. Clears the authentication key.


AnnoCPAN::DBI, AnnoCPAN::Config


Ivan Tubert-Brohman <>


Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: