Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Creating packages on the fly

by Gilimanjaro (Hermit)
on Jun 06, 2006 at 13:38 UTC ( #553814=note: print w/ replies, xml ) Need Help??


in reply to Creating packages on the fly

I would think that a UNIVERSAL::AUTOLOAD method would be the only way to catch this, if you want to avoid any predefinitions...

Another approach maybe to find all Wx:: classes and subclass them at startup... This may subclass a whole bunch of classes that you won't be using, but it avoids AUTOLOAD nastiness... Something like the following maybe:

use Wx; my $symbol_table = Symbol::Table->New(PACKAGE=>'main::Wx'); while(my $package = each %$symbol_table) { eval "package Groninger::Wx::$package; use base 'Wx::$package;"; }

This code doesn't recurse (so only packages directly in the Wx:: namespace will be subclassed) and it only works if the packages in that namespace have already been use'd. But that could be done automatically I suppose...

But perhaps it would then make more sense to generate them specifically for the packages you want to subclass using a syntax like:

use Class::SubclassSet Groninger => qw(Wx::App Wx::Frame Wx::Menu); package Class::SubclassSet; sub import { my ($this,$into,@classes); for my $class (@classes) { eval "package ${into}::$class; use base '$class';"; } }

That would reduce the duplicate code you'd be typing, prevent redundant subclassing and avoid UNIVERSAL::AUTOLOAD;

(All code untested; just brainstorming here...)

Regards, Giel


Comment on Re: Creating packages on the fly
Select or Download Code
Re^2: Creating packages on the fly
by Jouke (Curate) on Jun 06, 2006 at 18:38 UTC
    Hey Giel,
    Thanks for this. If I can't achieve what I want using the UNIVERSAL::AUTOLOADER idea (although it looks like it), I'm going to try this one.


    Jouke Visser
    Using Perl to enable the disabled: pVoice

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://553814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-12-28 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls