use strict; use warnings; package ImpWrap; sub import { my $this = shift; my $class = shift; my $method = shift; my $caller = (caller)[0]; warn "Importing $class/$method from $caller\n"; my $obj = $class->$method(@_); { no strict 'refs'; my $autoload = sub { our $AUTOLOAD; my ($al_method) = $AUTOLOAD =~ /::([^:]*)$/g; if ( $class->can( $al_method ) ) { *{ $AUTOLOAD } = sub { $obj->$al_method( @_ ); }; goto &{$AUTOLOAD}; } else { require Carp; Carp::croak "Undefined subroutine $AUTOLOAD"; } }; # Insert AUTOLOAD function; warn "Setting autoload\n"; *{ "$caller\::AUTOLOAD" } = $autoload; } } package Fuz; use Data::Dumper; sub bizzle { my $self = shift; print "bizzle: $self\n"; print Dumper $self; } sub new { my $class = shift; bless {@_}, $class; } package Foo; our @ISA = ('Fuz'); package IW::Foo; import ImpWrap 'Foo', 'new', (1..4); package IW::Fuz; import ImpWrap 'Fuz', 'new', (11..20); package main; IW::Foo::bizzle(); IW::Fuz::bizzle(); IW::Foo::Grazzle();