Browse Source

Experimental refactor of handle()

pull/1/head
Brennen Bearnes 18 years ago
parent
commit
1be59b0147
1 changed files with 60 additions and 49 deletions
  1. +60
    -49
      Display.pm

+ 60
- 49
Display.pm View File

@ -136,23 +136,19 @@ For no bigger than this thing is, it gets a little convoluted.
=item handle()
Handle queries. At the moment, expects a query object from CGI.pm or
CGI::Fast.
Handle a given request, either in the form of a CGI query object
or a date/entry string.
=cut
sub handle {
my ($query) = @_;
my (@options) = @_;
# Get the time, format the couple of variables I'll actually use.
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday,
$isdst) = localtime(time);
$mon++;
$year += 1900;
# grab parameters:
my @options = $query->param('keywords');
# This is experimental.
unless ($options[0]) { $options[0] = 'new' };
@options = map { expand_query($_) } @options;
@options = map { expand_option($_) } @options;
# now that we have some metadata,
# set some variables to be used in fragment interpretation.
@ -166,39 +162,14 @@ sub handle {
$print_footer = 1;
}
# take care of "all" alias in options
# get everything in the archive root directory
my @old_options = @options;
for (@old_options) {
if ($_ eq 'all') {
push (@options, dir_list ($DISPLAY_CONF{ROOT_DIR},
"high_to_low",
"^[0-9]{1,4}\$") );
}
}
# do appropriate things:
foreach my $option (@options) {
# take care of trailing slashes
chop ($option) if (substr($option, -1, 1) eq '/');
# This just provides an alias for the most recent month.
if ($option =~ m/^(feed|new)/) {
my $special_page = $1;
if (-e "$DISPLAY_CONF{ROOT_DIR}/$year/$mon") {
$option = "$year/$mon";
} else {
$option = recent_month();
}
# Handle feed generation using XML::Atom::SimpleFeed.
if ($special_page eq 'feed') {
feed_print($option);
exit;
}
# Handle feed with XML::Atom::SimpleFeed:
if ($option eq 'feed') {
feed_print(recent_month());
exit;
}
if ( $option =~ m'^[0-9/]{5,11}[a-z_/]+$' ) {
@ -238,17 +209,57 @@ sub handle {
}
# If handle got a CGI object, return 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;
}
}
sub expand_option {
my ($option) = shift;
# take care of trailing slashes
chop ($option) if (substr($option, -1, 1) eq '/');
if ($option eq 'all') {
return dir_list($DISPLAY_CONF{ROOT_DIR},
"high_to_low",
"^[0-9]{1,4}\$");
} elsif ($option eq 'new') {
return recent_month();
} else {
return $option;
}
}
sub recent_month {
my (@year_files) = dir_list ("$DISPLAY_CONF{ROOT_DIR}",
'high_to_low',
'^[0-9]{1,4}$');
# Get the time, format the couple of variables I'll actually use.
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$mon++;
$year += 1900;
if (-e "$DISPLAY_CONF{ROOT_DIR}/$year/$mon") {
return "$year/$mon";
}
else {
my (@month_files) = dir_list ("$DISPLAY_CONF{ROOT_DIR}/$year_files[0]",
'high_to_low',
'^[0-9]{1,2}');
my (@year_files) = dir_list ("$DISPLAY_CONF{ROOT_DIR}",
'high_to_low',
'^[0-9]{1,4}$');
return "$year_files[0]/$month_files[0]";
my (@month_files) = dir_list ("$DISPLAY_CONF{ROOT_DIR}/$year_files[0]",
'high_to_low',
'^[0-9]{1,2}');
return "$year_files[0]/$month_files[0]";
}
}
@ -367,12 +378,12 @@ Prints the entries in a given month (nnnn/nn). Calls dir_list(), datestamp().
=cut
sub month_print {
my ($month) = @_;
my ($year_digits, $month_digits, $calendar);
# If a directory exists for $month, use dir_list to grab
# the entry files it contains into @entry_files, sorted
# numerically. Then send each entry to entry_print.
my ($month) = @_;
if (-d "$DISPLAY_CONF{ROOT_DIR}/$month") {
if (-T "$DISPLAY_CONF{ROOT_DIR}/$month/index") {
print entry_print($month, "index");


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