At 5:33 AM +0200 4/26/00, Gerald Richter wrote:
> > Is there a way that I can make the cookie expire after say 15 minutes of
>> inactivity?
>>
>
>Currently not. You can only define a fixed time. Kee Hinckely has send a
>small module to the list, which should do this job. I plan to include
>support for this in EMbperl itself.
Thanks, I needed that nudge. I've cleaned up the code (do *not* release
software at three in the morning) and documented it. You can find it
at
http://www.somewhere.com/software/ or (since it's so small), below.
package Expires;
use strict;
use Date::Format;
sub TIESCALAR {
my ($pkg, @rest) = @_;
my $obj = 0;
$obj = $rest[0] if (@rest);
return (bless \$obj, $pkg);
}
sub FETCH {
my ($obj) = @_;
return '' if ($$obj == 0);
return time2str('%a, %e %h %Y %T %Z', time+($$obj*60), 'GMT');
}
sub STORE {
my ($obj, $val) = @_;
$$obj = $val;
}
1;
# Comment this out and run perl on this file for a quick test
__END__
package main;
use Date::Format;
print "Current Date: " . time2str('%a, %e %h %Y %T %Z', time, 'GMT') . "\n";
tie $ENV{'foo'}, 'Expires', 1;
print "1 minute: " . $ENV{'foo'}, "\n";
$ENV{'foo'} = 2;
print "2 minutes: " . $ENV{'foo'}, "\n";
$ENV{'foo'} = 60;
print "1 hour: " . $ENV{'foo'}, "\n";
print "Sleeping for ten seconds\n";
sleep(10);
print "1 hour again: " . $ENV{'foo'}, "\n";
=head1 NAME
Expires - Tie a Relative Expiration Date to a Variable
=head1 SYNOPSIS
This can be used anywhere, but it was written specifically for adding the
relative expiration dates to Embperl.
In httpd.conf or equivalent Apache config file the following code will ensure
that Embperl cookies expire 24 hours in the future.
<perl>
use Expires;
tie $ENV{'EMBPERL_COOKIE_EXPIRES'}, 'Expires', 60*24;
</perl>
=head1 DESCRIPTION
Expires is an object that can be tied to any scalar variable. At initialization
time, or any later point, it can be set to an integer M, indicating
the desired duration in minutes. When read, it returns a date string
that is M minutes after the read time. Each time the variable is read
the value is always that far in the future.
=head1 NOTES
Embperl caches the value of the EMBPERL_COOKIE_EXPIRES environment variable
prior to executing a given Embperl file, so it is not possible to change
the value anywhere outside of the Apache config files.
=head1 VERSION
This is version 1.0. The latest version can be found at
http://www.somewhere.com/software/ =head1 AUTHOR
Kee Hinckley
Somewhere.Com, LLC
25 Forest Circle
Winchester, MA 01890
nazgul@somewhere.com
=head1 COPYRIGHT
Copyright 2000, by Somewhere.Com, LLC.
All Rights Reserved
=head1 LICENSE
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that Somewhere's name not be used in
advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
If you make any modifications, bug-fixes or other changes to this software
we'd appreciate it if you could send a copy to us so we can keep things
up-to-date. Many thanks.
=head1 DISCLAIMER
Somewhere disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness, in no event shall
Somewhere be liable for any special, indirect or consequential damages or
any damages whatsoever resulting from loss of use, data or profits,
whether in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of this
software.
=cut
--
Kee Hinckley - Somewhere Consulting Group - Cyberspace Architects(rm)
I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.