Apache-HeavyCGI
view release on metacpan or search on metacpan
lib/Apache/HeavyCGI.pm view on Meta::CPAN
}
return $self->{DONE} if $self->{DONE}; # backwards comp now, will go away
$self->{CONTENT} = $self->layout->as_string($self);
$self->finish;
$self->deliver;
}
sub expires {
my Apache::HeavyCGI $self = shift;
my($set) = @_;
$set = Apache::HeavyCGI::Date->new(unix => $set)
if defined($set) and not ref($set); # allow setting to a number
$self->{EXPIRES} = $set if defined $set;
return $self->{EXPIRES}; # even if not defined $self->{EXPIRES};
}
sub finish {
my Apache::HeavyCGI $self = shift;
my $r = $self->{R};
my $content_type = "text/html";
lib/Apache/HeavyCGI.pm view on Meta::CPAN
push @l, qq{<html><head><title>Apache::HeavyCGI default page</title>
</head><body><pre>};
push @l, $self->instance_of("Apache::HeavyCGI::Debug");
push @l, qq{</pre></body></html>};
Apache::HeavyCGI::Layout->new(@l);
}
sub last_modified {
my Apache::HeavyCGI $self = shift;
my($set) = @_;
$set = Apache::HeavyCGI::Date->new(unix => $set)
if defined($set) and not ref($set); # allow setting to a number
$self->{LAST_MODIFIED} = $set if defined $set;
return $self->{LAST_MODIFIED} if defined $self->{LAST_MODIFIED};
$self->{LAST_MODIFIED} =
Apache::HeavyCGI::Date->new(unix => $self->time);
}
sub myurl {
my Apache::HeavyCGI $self = shift;
return $self->{MYURL} if defined $self->{MYURL};
require URI::URL;
my $r = $self->{R} or
return URI::URL->new("http://localhost");
my $script_name = substr(
$r->uri,
lib/Apache/HeavyCGI/Date.pm view on Meta::CPAN
use strict;
use vars qw($VERSION);
$VERSION = sprintf "%d.%03d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/;
use HTTP::Date ();
use overload '""' => "http";
sub new {
my($class,%arg) = @_;
$arg{unix} = time unless %arg;
my $self = bless {}, $class;
while (my($k,$v) = each %arg) {
$self->{$k} = $v;
}
$self;
}
sub unix {
my $self = shift;
my($set) = @_;
if (defined $set) {
$self->{unix} = $set;
$self->{http} = undef;
}
return $self->{unix} if defined $self->{unix}; # can be 0
$self->{unix} = HTTP::Date::str2time($self->{http});
}
sub http {
my $self = shift;
my($set) = @_;
if (defined $set) {
$self->{http} = $set;
$self->{unix} = undef;
}
unless (defined $self->{unix}) {
require Carp;
Carp::confess("No time in my object");
}
$self->{http} ||= HTTP::Date::time2str($self->{unix}); # can't be 0 or ""
}
1;
=head1 NAME
Apache::HeavyCGI::Date - represent a date as both unix time and HTTP time
=head1 SYNOPSIS
my $date = Apache::HeavyCGI::Date->new;
$date->unix(time); # set
print $date->unix; # get
print $date->http; # get as http
print $date; # same thing due to overloading
=head1 DESCRIPTION
This class implements a simple dual value date variable. There are
only two accessor methods that let you set and get dates. unix() sets
and gets the UNIX time, and http() gets and sets the HTTP time.
Whenever a time is set the other time gets undefined. Retrieving an
undefined time triggers a conversion from the other time. That way the
two times are always synced.
=head1 PREREQUISITES
The class uses HTTP::Date internally.
=head1 AUTHOR
lib/Apache/HeavyCGI/IfModified.pm view on Meta::CPAN
my $last_modified = $mgr->last_modified;
$r->header_out('Date', HTTP::Date::time2str($now));
if (my $ifmodisi = $r->header_in('If-Modified-Since')) {
# warn "Got ifmodisi[$ifmodisi]";
$ifmodisi =~ s/\;.*//;
my $ret;
if ($last_modified->http eq $ifmodisi) {
$ret = 304;
} else {
my $ifmodisi_unix = HTTP::Date::str2time($ifmodisi);
if (defined $ifmodisi_unix
&&
$ifmodisi_unix < $now
&&
$ifmodisi_unix >= $last_modified->unix
) {
$ret = 304;
}
}
return $mgr->{DONE} = $ret if $ret;
}
}
1;
( run in 1.941 second using v1.01-cache-2.11-cpan-39bf76dae61 )