If HTML::Parser is the only superclass, you don't need $self->SUPER::init()
in addition to $self->SUPER::new().  The reason HTML::Tree needs it is
because he is using multiple inheritance and had to figure out how to get
both superclasses' initializers called.
--
Mac :})
----- Original Message -----
From: "KIMURA Takeshi" <[EMAIL PROTECTED]>
To: "Randal L. Schwartz" <[EMAIL PROTECTED]>; "Michael A. Chase"
<[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, April 17, 2000 11:46 PM
Subject: Re: HTML::Parse overwriting sub parse


> Now I can clear the things a little bit.
>
> I originally had a sub new, which I didn't mention before.  I
> actually couldn't find them when I browsed my script.  What a shame.
>
> It was like this,
>
> sub new {
>     my $this = shift;
>     my $class = ref($this) || $this;
>     my $self = {};
>     bless $self, $class;
>     $self->initialize();
>     return $self;
> }
>
> So, Michael's first advise was already implemented in my script, but
> it was not working.  Sorry for confusing.
>
> And then I've changed it to,
>
> sub new
> {
>     my( $self ) = shift;
>     $self->SUPER::new(@_);
> }
>
> I reported it didn't work, but now it does.  The reason why it didn't
> work seems to depend on my macintosh environment.  It works on one
> machine, but not on other. I have to check this.
>
> Finally, I have,
>
> sub new
> {
>     my $class = shift;
>     my $self = $class->SUPER::new(@_);
>     $self->initialize( @_ );
>     $self;
> }
>
> as Randal advised. And this works!  Thanks.
>
> Now I also put,
>
>     $self->SUPER::init();
>
> in my initializing routine. Do you think it necessary?
>
>
> Randal L. Schwartz wrote on 00.4.17 4:10 AM:
> >>>>>> "Michael" == Michael A Chase <[EMAIL PROTECTED]> writes:
> >
> >Michael> He's trying to subclass HTML::Parser, so creating an HTML::
> Parser object is
> >Michael> not what he's wants to do, just add HTML::Parser
> capabilities to his own
> >Michael> class.  The init() method in HTML::Parser was added for that
purpose.
> >
> >But still, this subroutine should work for that:
> >
> >    package MyClass;
> >
> >    sub new {
> >       my $class = shift;
> >       my $self = $class->SUPER::new(@_);
> >       $self->my_init();
> >       $self;
> >    }
> >
> >If $self is not blessed into MyClass at this point, HTML::Parser is
> >*broken*.  And MyClass->my_init should be found as well.
> >
> >And please stop using that broken "$proto = " template.  That
> >mechanism adds unnecessary overhead and complexity to the 98% of uses
> >that don't need it.  Put the instance-cloning protocol into ->clone or
> >->copy, not ->new.


Reply via email to