BMaximus has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I'm trying to create a subclass to Apache::Cookie. Can someone please tell me why this is failing miserably?
package SessionCookie; @ISA = qw( Apache::Cookie ); # file util/SessionCookie.pm use strict; use Crypt::CBC; sub new { my ($class, @args) = @_; my $self = $class->SUPER::new(); return $self; } 1;
Is it because of the way that Apache::Cookie is built and that what I realy need to do is just use it and forget about subclassing it? I'd like to override some of the methods. Mainly new. When I look at the code for Apache::Cookie there is realy nothing to it. If its an interface to libapreq. Where is it loading the library? How does it work?

I pray for enlightenment,
BMaximus

Replies are listed 'Best First'.
Re: Apache::Cookie
by chromatic (Archbishop) on Mar 22, 2001 at 09:15 UTC
    My bet is that passing along arguments to the superclass constructor will help:
    sub new { my $class = shift; return $class->SUPER::new(@_); }
    Otherwise, there's no Apache::Request object from which to pull a cookie.
      Pardon my interjection, brother chromatic, but doesnt damian conway use
      sub new { return $class = $_[0] -> SUPER::new(@_[1..$#_]); }
      Doesnt that seem a little clearer and more concise?

      brother dep

      --
      Laziness, Impatience, Hubris, and Generosity.

        Whether it's clearer is subjective, I think. Note that the assignment to $class is unnecessary (and misleading).
      I misstated my problem. I was getting an error that it couldn't locate object 'new' via package "SessionCookie". It seems that I do need to put a
      use Apache::Cookie;
      before @SessionCookie::ISA = qw( Apache::Cookie );
      after I did that SUPER worked just fine.

      Thanks for the help though,
      BMaximus