perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Rosenthal <srosent...@northernlight.com>
Subject Small Apache::Session improvement
Date Fri, 24 Mar 2000 19:36:57 GMT
Hi:

Here'a a couple of small changes we've  made  here to Apache::Session which 
other people might find useful.

a) we didn't want to use the supplied generate_id function for various 
reasons, so we rolled our own, and put a reference to it in a new global, 
$Apache::Session::IdGenerator .

b) An efficiency tweak in the STORE method for the tied hash ; we found we 
were sometimes updating the session record unnecessarily  because we were 
too lazy to  consistently write code like

	$sesshash{'foo'}  = 'bar' unless ($sesshash('foo'} eq  'bar).

so, since Laziness is  said to be a  virtue for Perl programmers, we 
moved  that check into the STORE method.

context diffs follow:

- Simon
==================================================================
*** Session.pm.ORIG	Fri Mar 24 13:21:05 2000
--- Session.pm	Fri Mar 24 14:31:59 2000
***************
*** 284,293 ****
   package Apache::Session;

   use strict;
! use vars qw($VERSION);

   $VERSION = '1.03';
!
   use MD5; #yes, you need MD5.pm

   #State constants
--- 284,295 ----
   package Apache::Session;

   use strict;
! use vars qw($VERSION $IdGenerator);

   $VERSION = '1.03';
! # You can change the function used to generate ids by changing this 
global at startup time
! # e.g. $Apache::Session::IdGenerator = \&my_own_function;
! $IdGenerator = \&generate_id;
   use MD5; #yes, you need MD5.pm

   #State constants
***************
*** 371,377 ****
       }
       else {
           $self->{status} |= NEW;
!         $self->{data}->{_session_id} = generate_id();
           $self->save;
       }

--- 373,379 ----
       }
       else {
           $self->{status} |= NEW;
!         $self->{data}->{_session_id} =  &$IdGenerator();
           $self->save;
       }

***************
*** 389,399 ****
       my $self  = shift;
       my $key   = shift;
       my $value = shift;
!
!     $self->{data}->{$key} = $value;
!
!     $self->{status} |= MODIFIED;
!
       return $self->{data}->{$key};
   }

--- 391,403 ----
       my $self  = shift;
       my $key   = shift;
       my $value = shift;
! # to avoid unnecessary updates, only set MODIFIED flag if the variable 
really changed...
! 	my $prev = $self->{data}->{$key};
! 	return undef if (!defined($prev) && !defined($value));
!     if($prev ne $value) {
!       $self->{data}->{$key} = $value;
!       $self->{status} |= MODIFIED;
! 	}
       return $self->{data}->{$key};
   }








-----------------------------------------------------
Simon Rosenthal	(srosenthal@northernlight.com)    	
Web Systems Architect
Northern Light Technology 	222 Third Street, Cambridge MA 02142
Phone:  (617)577-2796  :       URL:  http://www.northernlight.com
"Northern Light - Just what you've been searching for"


Mime
View raw message