Re: subclassing problem...
- From: "Ross McFarland" <rwmcfa1 neces com>
- To: bboett adlp org
- Cc: gtk-perl-list gnome org
- Subject: Re: subclassing problem...
- Date: Tue, 14 Oct 2003 12:42:35 -0400 (EDT)
Bruno Boettcher said:
our @ISA = qw(Gtk2::TextBuffer);
sub new
{
my ($fs,$hashref,$tagtable) = @_;
my $obj_ref;
$obj_ref = Gtk2::TextBuffer->new($tagtable);
#$obj_ref = SUPER::new($tagtable);
bless $obj_ref, "POE::Helper::LogView";
return $obj_ref;
}# sub new
now like this it works, but its highly unsatisfactory that the version
with SUPER doesn't.... anyone care to explain me why?
unrelated but possible problem, $fs should be the class name, $tagtable will
be the third parameter, but what's $hashref?
the reason the SUPER method above won't work is two fold: 1) SUPER is an
object method, and you're not calling it on an object. 2) you need to bless
the object before you could even call SUPER on it which in the case of a
constructor is a chicken and egg problem. in short you don't really use SUPER
to create objects.
in it's simpliest form, the above code should probably be something like:
our @ISA = qw(Gtk2::TextBuffer);
sub new
{
my $class = shift; # shift this off first, then pass the rest of the args to
# our parent's new, if we have specific things we're
# interested in we should get them out here too
return bless Gtk2::TextBuffer->new(@_), $class;
}# sub new
the faq entry describing all of this is here, have a look at it for how SUPER
can be used.:
http://gtk2-perl.sourceforge.net/faq/#16
i just updated it to include passing the parameters on down to the parent
class too.
-rm
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]