This is a question about a perl5 feature I could find no documentation about so far. I would be glad to know whether it is intended this way and safe to use or even recommended.

A bareword ending in a double colon, such as Foo::Bar::, evaluates to a string without the double colon suffix, "Foo::Bar" in this example. Using such a bareword is not prohibited under strict 'subs', but it triggers a warning if perl hasn't seen a package of that name yet.

Example:

use strict; use warnings; package Foo::Bar; package main; my $p = Foo::Bar::; print "$p\n"; # prints Foo::Bar my $q = Baz::Qux::; # warns: # Bareword "Baz::Qux::" refers to nonexistent package print "$q\n"; # prints Baz::Qux

I'll call this feature package-name-quoting, as appending two colons has the effect of quoting plus package name validation. I could use it where package name strings are needed, such as in arguments for isa or DOES. The warning would help me to catch typos.

So, after all, it is a useful feature. Is it documented? I would have expected perlmod to say something about it. Maybe I looked in the wrong place.


In reply to Bareword Package Names by martin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.