develooper Front page | perl.perl5.porters | Postings from November 2011

[perl #104506] BUG or RFE: use manpage is misleading; enhance 'use' to fix preferable

Thread Previous
From:
Father Chrysostomos via RT
Date:
November 26, 2011 22:31
Subject:
[perl #104506] BUG or RFE: use manpage is misleading; enhance 'use' to fix preferable
Message ID:
rt-3.6.HEAD-5084-1322375479-1635.104506-15-0@perl.org
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About