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;