develooper Front page | perl.perl5.porters | Postings from August 2012

Re: [perl #114460] RFE: class as conditional self-defining keywordfor package

Thread Previous | Thread Next
Eirik Berg Hanssen
August 13, 2012 11:45
Re: [perl #114460] RFE: class as conditional self-defining keywordfor package
Message ID:
On Mon, Aug 13, 2012 at 2:37 AM, David Golden <> wrote:

> For example, let's hypothesize such a global called %PACKAGES and a
> new hypothetical keyword "ensure".  Then we could imagine something
> like this:
>     ensure Foo;
> Here, "ensure" would check if Foo exists in %PACKAGES.  If so, it
> would do nothing.  If not, it would act like "use Foo".

  Sounds good to me, except one amendment/clarification:

  As described, it will call C<< Foo->import >> or not, depending on
whether Foo exists in %PACKAGES.  That's not good.

  If should either act like C<< use Foo (); >> when the package is not
already loaded (i.e. never call C<< Foo->import >>), or else always call
C<< Foo->import >> (at compile time) whether or not the package was already

  (Gut feeling says the latter.  This could well be used not only for
purely OO packages, but also those that implement new syntax.  They're the
ones that most need compile time effects, after all.  And then it
generalizes as C<< ensure Foo (); >> would be the don't-call-import syntax.)

  And while I cannot say I personally have missed this functionality much
(tried use-ing a package from a different module once, found it didn't
work, found another WTDI), I do recall seeing others ask for something
similar.  And I think it will make it easier to teach/learn Perl,
highlighting the difference between module and package, and so making it
less inaccessible to the uninitiated.  (A kind of language design "show,
don't tell"?  The documentation clearly tells us packages and modules are
not the same, but that does not stop otherwise sane and intelligent people
from confusing them.)

  However, I'm not going to make this, and this is not a vote – but
perhaps, rather, a cheer from the peanut gallery?  With the above
amendment/clarification, it sounds good to me.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About