On Sat Nov 26 19:01:07 2011, LAWalsh wrote:
> Zefram via RT wrote:
> > This part now vaguely makes some sense. It appears that you're
> after
> > an importing mechanism that doesn't load a module if the package to
> be
> > imported from is already defined. We have "use base" which
> performs such
> > soft loading and then adds the target package to @ISA. You're
> asking
> > for a keyword that does something like
> >
> > BEGIN {
> > Module::Runtime::use_package_optimistically("PACKAGE");
> > "PACKAGE"->import(ARGS...);
> > }
> >
> > This is achievable, but it doesn't make sense as part of "use".
> > Strict module loading is the essence of "use".
>
> ---
>
> More precisely, strict loading is the essence of "use BAREWORD".
> As "use
> EXPR" is not defined in the language.
>
> As mentioned before, "BAREWORD" and "EXPR" are syntactically and
> semantically different.
>
> "use", only, uses the "require BAREWORD|VERSION" form of "require",
> but
> does NOT use it's "require EXPR" form.
>
> I'm proposing that in line with Perl's "use Module" syntax, where
> "Module" *must* be a BAREWORD, that
>
> "use EXPR"
>
> also be ADDED to the language with acknowledgement that it is
> processed at runtime:
>
> BEGIN {
> defined(Module = eval EXPR) || eval "require EXPR"
> }
>
> Then "use" and "require" would become more parallel functions, with
> focus on "Class/Package", and "File" (@Inc relative), respectively.
>
> Both would retain existing BAREWORD and VERSION semantics.
>
> Both would check for their objects' preexistence and only continue
> with inclusion on 'non-existence' (by object-specific test):
>
> "use" checks object's 'define' already being in memory.
But what does that mean exactly? That the package exists? Checking
whether a package exists is not reliable, as simply mentioning it in
compiled code will cause it to pop into existence:
print "yes\n" if exists $::{"Foo::"};
Foo::bar() if 0;
(That snippet gives positive output.)
It works that way so that Foo::bar can be bound to the subroutine (OK,
the typeglob holding the subroutine) at compile-time, even before the
package in question is ‘defined’ (whatever that means).
--
Father Chrysostomos
Thread Previous