You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by jo...@apache.org on 2003/05/01 17:21:33 UTC

cvs commit: httpd-apreq/Request Request.pm

joes        2003/05/01 08:21:33

  Modified:    Request  Request.pm
  Log:
  Update Steve Hay's subclass docs.
  
  Revision  Changes    Path
  1.24      +12 -7     httpd-apreq/Request/Request.pm
  
  Index: Request.pm
  ===================================================================
  RCS file: /home/cvs/httpd-apreq/Request/Request.pm,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Request.pm	30 Apr 2003 17:46:48 -0000	1.23
  +++ Request.pm	1 May 2003 15:21:33 -0000	1.24
  @@ -272,18 +272,23 @@
   	}
   	sub AUTOLOAD {
   		my $proto = shift;
  +		return unless ref $proto;
   		our $AUTOLOAD;
   		my $name = $AUTOLOAD;
   		$name =~ s/^.*:://;
  -		return $proto->$name(@_);
  +		return $proto->{r}->$name(@_);
   	}
   
  -In fact, the aggregate/delegate solution is made easier by some magic in the
  -Apache::Request class. If the instances of your subclass are hash references
  -then you can actually inherit from Apache::Request as long as the
  -Apache::Request object is stored in an attribute called "r" or "_r". (The
  -Apache::Request class effectively does the delegation for you automagically, as
  -long as it knows where to find the Apache::Request object to delegate to.)
  +A fancier AUTOLOAD() subroutine could be written to handle class methods too if
  +required, but we leave that as an exercise for the reader because in fact the
  +Apache::Request class provides some magic that makes the aggregate/delegate
  +solution much easier.
  +
  +If the instances of your subclass are hash references then you can actually
  +inherit from Apache::Request as long as the Apache::Request object is stored in
  +an attribute called "r" or "_r". (The Apache::Request class effectively does the
  +delegation for you automagically, as long as it knows where to find the
  +Apache::Request object to delegate to.)
   
   Thus, the second example above can be simplified as: