Re: Widget class loading (was: Re: relase plan, 1st draft)



On Tue, Nov 12, 2002 at 01:26:56PM +0100, Joern Reder wrote:
What about such a solution: each widget class is derived from 
Gtk2::Loader (probably a bad name, but Ok for this mail ;)

There is a base global class: "Gtk2::_Object"

It has a 'new' subroutine (and probably other different named 
constructor subroutines) like this:

  sub new {
    my $class = shift;
    require $class; # or: eval "use $class"; die $@ if $@;
    $class->new(@_);
  }

Gtk2.pm sets the @ISA array of all widget classes to qw(Gtk2::Loader) 
and loads Gtk2::Loader. So when constructing a widget object, 
Gtk2::Loader's constructor is accessed first, which loads the real code
and then executes the widget's constructor. Subsequent calls will find 
the widget's constructor first, and everything should work with good 
performance and as expected.

Just a quick born idea, maybe it doesn't work, because I missed 
something essential (also I don't know much about Gtk2's internals). 
Just tell me ;)

How do you know what @ISA contains before the module is loaded?

BTW: how did the Gtk module solved this problem?

There is a lazyloader mechanism in the old Gnome-Perl,
but AFAIK all code in lazy-loaded module must be compiled code in the main .so
(I could be wrong, just had a quick glance)
We want to use perl as far as possible.

/göran





 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]