* Eric Wilhelm <[EMAIL PROTECTED]> [2007-02-18 18:35]:
> # from A. Pagaltzis
> # on Sunday 18 February 2007 07:45 am:
> >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.
>
> True, that is what it does *under the hood*, but what it is
> used for is more like Package::TODO or Package::Orphan. Naming
> it for an implementation detail seems less findable.
Good point. But you seem to have a good idea of where to head
now. Maybe Package::PretendModule? Package::AsModule?
Module::Inline?
> > BEGIN {
> > package Foo::Bar;
> > use Package::FakeIncEntry;
>
> I'm specifically trying to avoid labeling it BEGIN. The reason
> being that it is less specific/too generic looking.
Put a label in front; or put the `package` statement on the same
line.
> Also, with the 'use Unicorn' after the package declaration, the
> lines between the curlies are no longer
> ready-to-go-be-in-a-file
Move the `use` statement to where your version’s `__PACKAGE__`
line is, then their copypastability is identical.
> (plus, it embeds the magic rather than stating it out front.)
That is a reasonable argument. Hmm.
> use Package::Orphan sub {
> package Foo::Bar;
> ...
> __PACKAGE__;
> };
>
> Stands out more than just-another BEGIN block. Also, it allows
> one to turn it off and see what breaks :-D. Plus, it would be
> easily editable with PPI (or less.)
Syntactic sugar is nice when its effect is self-explanatory,
else it’s just an obscure shortcut. I don’t like magic for
magic’s sake; that way lies Ruby. The cost of magic should be
offset by an obvious and dramatic benefit. I don’t see that in
your case, and especially so because you haven’t managed to
encapsulate your magic completely. The user has to remember to
add that `__PACKAGE__` incantation. With the less magical
approach, there is nothing to forget. If you found a way to make
your interface sufficiently advanced, I would be more inclined to
deem it good.
> >Package/FakeIncEntry.pm is trivial:
> >...
> > sub import { my ( $p ) = caller; $INC{ $p } ||= _pkg2path $p }
>
> Trivial, but the "Foo/Bar.pm" form is the key, and caller's
> filename is the value. Implementation with the subref is just
> as trivial.
Sorry, it’s been a long time since I last dabbled in that corner
of Perl. I completely forgot the actual semantics.
--
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}
&Just->another->Perl->hack;
#Aristotle