home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / DB_File.pm < prev    next >
Encoding:
Perl POD Document  |  2002-11-27  |  3.8 KB  |  169 lines

  1. package CGI::Session::DB_File;
  2.  
  3. # $Id: DB_File.pm,v 3.2 2002/11/27 12:26:03 sherzodr Exp $
  4.  
  5. use strict;
  6. use base qw(
  7.     CGI::Session
  8.     CGI::Session::ID::MD5
  9.     CGI::Session::Serialize::Default
  10. );
  11.  
  12. use DB_File;
  13. use File::Spec;
  14. use Fcntl (':DEFAULT', ':flock');
  15.  
  16. # Load neccessary libraries below
  17.  
  18. use vars qw($VERSION $FILE_NAME);
  19. $FILE_NAME = 'cgisess.db';
  20.  
  21. $VERSION = '0.1';
  22.  
  23. sub store {
  24.     my ($self, $sid, $options, $data) = @_;
  25.  
  26.     my $storable_data = $self->freeze($data);
  27.  
  28.     my $args = $options->[1];
  29.     my $file = File::Spec->catfile($args->{Directory}, $args->{FileName} || $FILE_NAME);
  30.  
  31.     tie my %db, "DB_File", $file, O_RDWR|O_CREAT, 0644 or die $!;
  32.     $db{$sid} = $storable_data;
  33.     untie(%db) or die $!;
  34.  
  35.     return 1;
  36.  
  37. }
  38.  
  39.  
  40. sub retrieve {
  41.     my ($self, $sid, $options) = @_;
  42.  
  43.     # you will need to retrieve the stored data, and
  44.     # deserialize it using $self->thaw() method
  45.  
  46.     my $args = $options->[1];
  47.     my $file = File::Spec->catfile($args->{Directory}, $args->{FileName} || $FILE_NAME);
  48.  
  49.     tie my %db, "DB_File", $file, O_RDWR|O_CREAT, 0644 or die $!;
  50.     my $data = $self->thaw($db{$sid});
  51.     untie(%db);
  52.  
  53.     return $data;
  54. }
  55.  
  56.  
  57.  
  58. sub remove {
  59.     my ($self, $sid, $options) = @_;
  60.  
  61.     # you simply need to remove the data associated
  62.     # with the id
  63.  
  64.     my $args = $options->[1];
  65.     my $file = File::Spec->catfile($args->{Directory}, $args->{FileName} || $FILE_NAME);
  66.     tie my %db, "DB_File", $file, O_RDWR|O_CREAT, 0644 or die $!;
  67.     delete $db{$sid};
  68.     untie(%db) or die $!;
  69.  
  70.     return 1;
  71.  
  72.  
  73. }
  74.  
  75.  
  76.  
  77. sub teardown {
  78.     my ($self, $sid, $options) = @_;
  79.  
  80.     # this is called just before session object is destroyed
  81. }
  82.  
  83.  
  84.  
  85.  
  86. # $Id: DB_File.pm,v 3.2 2002/11/27 12:26:03 sherzodr Exp $
  87.  
  88. 1;
  89.  
  90. =pod
  91.  
  92. =head1 NAME
  93.  
  94. CGI::Session::DB_File - DB_File driver for CGI::Session
  95.  
  96. =head1 SYNOPSIS
  97.  
  98.     use CGI::Session;
  99.     $session = new CGI::Session("driver:DB_File", undef, {Directory=>'/tmp'});
  100.  
  101. For more details, refer to L<CGI::Session> manual
  102.  
  103. =head1 DESCRIPTION
  104.  
  105. CGI::Session::DB_File is a CGI::Session driver to store session data in BerkeleyDB.
  106. Filename to store the session data is by default 'cgisess.db'. If you want different
  107. name, you can either specify it with the "FileName" option as below:
  108.  
  109.     $s = new CGI::Session::DB_File(undef, {Directory=>'/tmp', FileName=>'sessions.db'});
  110.  
  111. or by setting the value of the $CGI::Session::DB_File::NAME variable before creating
  112. the session object:
  113.  
  114.     $CGI::Session::DB_File::NAME = 'sessions.db';
  115.     $s = new CGI::Session("driver:DB_File", undef, {Directory=>'/tmp'});
  116.  
  117. The only driver option required, as in the above examples, is "Directory", which tells the
  118. driver where the session file and lock files should be created.
  119.  
  120. "FileName" option is also available, but not required.
  121.  
  122. =head1 COPYRIGHT
  123.  
  124. Copyright (C) 2001-2002 Sherzod Ruzmetov. All rights reserved.
  125.  
  126. This library is free software and can be modified and distributed under the same
  127. terms as Perl itself.
  128.  
  129. Bug reports should be directed to sherzodr@cpan.org, or posted to Cgi-session@ultracgis.com
  130. mailing list.
  131.  
  132. =head1 AUTHOR
  133.  
  134. CGI::Session::DB_File is written and maintained by Sherzod Ruzmetov <sherzodr@cpan.org>
  135.  
  136. =head1 SEE ALSO
  137.  
  138. =over 4
  139.  
  140. =item *
  141.  
  142. L<CGI::Session|CGI::Session> - CGI::Session manual
  143.  
  144. =item *
  145.  
  146. L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual
  147.  
  148. =item *
  149.  
  150. L<CGI::Session::CookBook|CGI::Session::CookBook> - practical solutions for real life problems
  151.  
  152. =item *
  153.  
  154. B<RFC 2965> - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt
  155.  
  156. =item *
  157.  
  158. L<CGI|CGI> - standard CGI library
  159.  
  160. =item *
  161.  
  162. L<Apache::Session|Apache::Session> - another fine alternative to CGI::Session
  163.  
  164. =back
  165.  
  166. =cut
  167.  
  168. # $Id: DB_File.pm,v 3.2 2002/11/27 12:26:03 sherzodr Exp $
  169.