* Eric Wilhelm <[EMAIL PROTECTED]> [2007-02-18 09:20]:
> I've tried to come up with something that doesn't need the
> trailing __PACKAGE__ or require typing BlahBlahBlah twice, but
> can't think of anything that doesn't involve DB or B::*.
Easily possible if you change your interface to something less
magical-looking.
> Better name than Package::Unicorn or Acme::RealSoonNow?
Well, what does the module really do? It populates %INC with the
proper bits for a given package name. That’s what I’d put in the
name. Package::FakeIncEntry maybe.
So here you are:
BEGIN {
package Foo::Bar;
use Package::FakeIncEntry;
sub wibble { ... }
sub wobble { ... }
}
Package/FakeIncEntry.pm is trivial:
package Package::FakeIncEntry;
sub _pkg2path { s!::!/!g, return "/fake/$_.pm" for shift }
sub import { my ( $p ) = caller; $INC{ $p } ||= _pkg2path $p }
(If I had a nickel for every time I’ve wished Perl had an
s///-like function that returned a modified copy instead of
modifying the original string in place…)
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>