|
|
@ -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; |
|
|
|
} |
|
|
|