Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Here's what I whipped up using UNIVERSAL::AUTOLOAD; it seems to actually work! It also attempts to store an already setup UNIVERSAL::AUTOLOAD and use it if the requested package isn't one that should be auto-generated, so it should be safe to use with other UNIVERSAL::AUTOLOAD'ing stuff, as long as this one is use'd last (or the others are smart too).

#!/usr/bin/perl use strict; use warnings; use lib '.'; use Wx; use Class::Generate::Auto 'Jouke::Wx' => 'Wx'; my $w = Jouke::Wx::App->new; exit; package Class::Generate::Auto; use strict; use warnings; our $AUTOLOAD; our %mapping; my $old_ua = undef; sub import { my $this = shift; while(@_) { my $prefix = shift; my $superclass = shift; $mapping{$prefix} = $superclass; } my $current_ua = UNIVERSAL->can('AUTOLOAD'); if($current_ua and $current_ua!=\&autoloader) { $old_ua = $current_ua; } *UNIVERSAL::AUTOLOAD=\&autoloader; } sub autoloader { my ($package,$method) = $AUTOLOAD =~ /^(.*)::(.*)$/; return if $method eq 'DESTROY'; keys %mapping; while(my ($prefix,$superclass) = each %mapping) { my ($extra) = $package =~ /^${prefix}::(.*)$/ or next; $superclass .= "::$extra" if $extra; eval "package $package; use base q{$superclass};"; die "Unable to auto-generate class $package as subclass from $ +superclass: $@" if $@; my $method_ref = $package->can($method); die "Freshly auto-generated class $package can't $method (prob +ably $superclass can't either)" unless $method_ref; goto $method_ref; } goto $old_ua if $old_ua; die "Class $package can't $method and no autoloader was present be +fore ".__PACKAGE__." was loaded"; } 1;

In reply to Re: Creating packages on the fly by Gilimanjaro
in thread Creating packages on the fly by Jouke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-16 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found