AnnoCPAN
view release on metacpan or search on metacpan
lib/AnnoCPAN/Control.pm view on Meta::CPAN
sub set_login_cookies {
my ($self, $user) = @_;
$self->user($user);
my $login = $user->username;
my $time = time;
my $key = $self->key($login, $time);
$self->add_cookie(login => $login);
$self->add_cookie(key => $key);
$self->add_cookie('time' => $time);
}
=item $obj->user($user)
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).
=cut
sub user {
my ($self, $user) = @_;
if (@_ > 1) {
$self->{user} = $user;
} else {
$self->{user} = $self->check_login unless exists $self->{user};
}
$self->{user};
}
=item $obj->key($login, $time)
Returns a login key as a string. Depends on the "secret" configuration option.
=cut
sub key {
my ($self, $login, $time) = @_;
my $secret = AnnoCPAN::Config->option('secret');
md5_hex("$login $time $secret");
}
############# MODES ###############
=back
=head2 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");
}
B<Warning>: the documentation below may be slighly incomplete or outdated:
=over
=item $obj->Main($vars)
The front page. Provides the "recent notes" list.
=cut
sub Main {
my ($self, $vars) = @_;
$vars ||= {};
my $page = ($self->param('page') * 1) || 1;
my $page_size = AnnoCPAN::Config->option('recent_notes') || 25;
my $start = ($page - 1) * $page_size;
my @recent = AnnoCPAN::DBI::Note->recent($start, $page_size);
my $n = AnnoCPAN::DBI::Note->count_all;
my $pages = ceil($n / $page_size);
({
recent => \@recent,
note_count => $n,
page => $page,
pages => $pages,
%$vars
}, "main");
}
=item $obj->Show($vars)
Displays one POD page. Uses the pid CGI parameter.
=cut
sub Show {
my ($self, $vars) = @_;
$vars ||= {};
my $podver = $vars->{podver} || $self->param_obj('PodVer');
({
podver => $podver,
%$vars,
}, "show");
}
=item $obj->Show_note
Displays the POD page that is the "main reference" for a given note. Uses the
id CGI parameter.
( run in 2.617 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )