Browse Source

Added a display() method to wrap handle(), tweaked conf.pl for new

Wala.pm interface.
pull/1/head
Brennen Bearnes 17 years ago
parent
commit
61b4ff886e
4 changed files with 73 additions and 54 deletions
  1. +51
    -33
      Display.pm
  2. +20
    -19
      conf.pl
  3. +1
    -1
      display.fcgi
  4. +1
    -1
      display.pl

+ 51
- 33
Display.pm View File

@ -3,7 +3,7 @@ package Display;
our ($VERSION) = '$Revision$' =~ m{ \$Revision: \s+ (\S+) }x;
# $Author$
# $Date$
# $Id:$
# $Id$
use strict;
use warnings;
@ -146,50 +146,70 @@ sub walaconf {
return;
}
=item handle
=item display($entry1, $entry2, ...)
Handle a given request, either in the form of a CGI query object
or a date/entry string.
Return a string containing the given entries, which can be in the form of CGI
query objects or date/entry strings. If no parameters are given, default to
default_entry().
display() expands aliases ("new" and "all") and CGI query objects as necessary,
collects input from handle($entry), and wraps the whole thing in header and
footer files.
=cut
sub handle {
sub display {
my $self = shift;
my (@options) = @_;
my $output;
# Get parameters from any CGI objects we've been given,
# and make sure we at least have the default (usually "new"):
# Get parameters from any CGI queries, make sure we have at least the
# default, and expand on any aliases:
@options = map { expand_query($_) } @options;
$options[0] ||= $self->default_entry;
$self->title(join ' ', @options); # title for head/foot
@options = map { $self->expand_option($_) } @options;
# Title for head/foot template:
$self->title(join ' ', @options);
# Wrap entries in header/footer:
return $self->fragment_slurp($self->header)
. collect( sub { $self->handle($_[0]) }, @options ),
. $self->fragment_slurp($self->footer);
# Maps 'all' and 'new' to appropriate entries:
@options = map { $self->expand_option($_) } @options;
}
my %entry_map = %{ $self->entry_map };
sub collect {
my ($routine, @list) = @_;
my $output;
for my $item (@list) {
$output .= $routine->($item);
}
for my $option (@options) {
return $output;
}
# Atom feed:
return $self->feed_print() if $option eq 'feed';
=item handle($entry)
# Dispatch entries to appropriate output routines:
for my $pattern (keys %entry_map) {
if ($option =~ $pattern) {
$output .= $entry_map{$pattern}->($self, $option);
}
}
Return the text of an individual entry.
=cut
sub handle {
my $self = shift;
my ($option) = @_;
# Dispatch entries to output routines:
my $output;
return $self->feed_print() if $option eq 'feed';
while ( my ($pattern, $dispatch) = each %{ $self->entry_map() } ) {
if ($option =~ $pattern) {
$output .= $dispatch->($self, $option);
}
}
# Wrap entries in header/footer:
return $self->fragment_slurp($self->header)
. $output
. $self->fragment_slurp($self->footer);
return $output;
}
@ -202,11 +222,13 @@ appropriate list of parameters.
sub expand_query {
my ($option) = shift;
if ( (ref $option eq 'CGI::Fast') or (ref $option eq 'CGI') ) {
return $option->param('keywords');
} else {
return $option;
}
}
@ -223,13 +245,9 @@ sub expand_option {
chop $option if substr($option, -1, 1) eq q{/};
if ($option eq 'all') {
return dir_list(
$self->root_dir,
'high_to_low',
qr/^[0-9]{1,4}$/
);
return dir_list($self->root_dir, 'high_to_low', qr/^[0-9]{1,4}$/);
} elsif ($option eq 'new') {
return $self->recent_month();
return $self->recent_month;
} else {
return $option;
}


+ 20
- 19
conf.pl View File

@ -1,3 +1,21 @@
########################
# display.pl options #
########################
our %DISPLAY_CONF = (
root_dir => "/home/bbearnes/p1k3.com/archives",
url_root => "http://p1k3.com/",
image_url_root => "http://p1k3.com/",
header => 'header',
footer => 'footer',
stylesheet_url => 'http://p1k3.com/p1k3.css',
favicon_url => 'http://p1k3.com/favicon.png',
feed_url => 'http://p1k3.com/feed',
author => 'Brennen Bearnes',
description => '',
license => '',
);
##################
# WALA OPTIONS #
##################
@ -18,28 +36,11 @@ our %WalaConf = (
FeedURL => "http://p1k3.com/wala/wala_feed.pl",
ShowSearchlinks => 1,
UseCache => 1,
DisplayRootDir => $DISPLAY_CONF{root_dir},
DisplayURL => $DISPLAY_CONF{url_root},
);
$WalaConf{LogFile} = $WalaConf{RootDir} . '/log';
$WalaConf{PagesDir} = '/home/bbearnes/wala/pages';
$WalaConf{CacheDir} = '/home/bbearnes/wala/cache';
$WalaConf{DiffDir} = '/home/bbearnes/wala/diffs';
########################
# display.pl options #
########################
our %DISPLAY_CONF = (
root_dir => "/home/bbearnes/p1k3.com/archives",
url_root => "http://p1k3.com/",
image_url_root => "http://p1k3.com/",
header => 'header',
footer => 'footer',
stylesheet_url => 'http://p1k3.com/p1k3.css',
favicon_url => 'http://p1k3.com/favicon.png',
feed_url => 'http://p1k3.com/feed',
author => 'Brennen Bearnes',
description => '',
license => '',
);

+ 1
- 1
display.fcgi View File

@ -33,7 +33,7 @@ $d->walaconf(%WalaConf);
# Handle input from FastCGI:
while (my $query = new CGI::Fast) {
print $d->handle($query);
print $d->display($query);
}
exit;

+ 1
- 1
display.pl View File

@ -29,4 +29,4 @@ do 'conf.pl' if (-e 'conf.pl');
my $d = Display->new(%DISPLAY_CONF);
$d->walaconf(%WalaConf);
print $d->handle(@ARGV);
print $d->display(@ARGV);

|||||||
x
 
000:0
Loading…
Cancel
Save