Re: Glib::Object::Subclass and Exporter
- From: Kevin Ryde <user42 zip com au>
- To: Domovoy <domovoy errlock org>
- Cc: gtk-perl-list gnome org
- Subject: Re: Glib::Object::Subclass and Exporter
- Date: Mon, 10 Sep 2012 09:07:15 +1000
Domovoy <domovoy errlock org> writes:
So, i finally took a look at Glib::Object::Subclass.pm, and saw that it
was doing its job by defining an import sub.
And putting itself at the start of the caller's @ISA ...
      use Glib::Object::Subclass
          Gtk2::ScrolledWindow::;
 
      BEGIN {
          require Exporter;
          our @ISA = qw(Exporter);
This is a store to @ISA, replacing the bits Glib::Object::Subclass put
there, hence those bits not working.
I get some joy from changing it to
    unshift @ISA, qw(Exporter);
so that Exporter is at the start of @ISA and everything from
Glib::Object::Subclass follows.
Perhaps the way Glib::Object::Subclass pushes itself onto @ISA to get a
perlish new() could be better done by pushing a separate class which had
only new().  Then any import() in the caller, or the caller's
inheritance, wouldn't be affected in the way you struck.
In practice I suspect Exporter is not much used with oopery.  Constants
can be offered as class methods
    $c = Foo::Bar->SOME_CONST;
which has the advantage of working from instances too
    $c = $foo->SOME_CONST;
Such a call is a very tiny bit slower (and won't constant-fold), but has
the advantage that further subclasses can override.
          bless($self, $class);
This ought to be unnecessary.  If it is necessary then you're either
doing something wrong, or something very advanced :-).
-- 
It's a long way to the shop if you want a sausage roll.
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]