There are no barewords in Perl 6 in the sense that they exist in Perl 5, and the term isn't used in Perl 6 at all.
There are two cases that we might call a "bare identifier":
- An identifier immediately followed by zero or more horizontal whitespace characters (
\h*
), followed by the characters =>
. This takes the identifier on the left as a pair key, and the term parsed after the =>
as a pair value. This is an entirely syntactic decision; the existence of, for example, a sub or type with that identifier will not have any influence.
- An identifier followed by whitespace (or some other statement separator or terminator). If there is already a type of that name, then it is compiled into a reference to the type object. Otherwise, it will always be taken as a sub call. If no sub declaration of that name exists yet, it will be considered a call to a post-declared sub, and an error produced at CHECK-time if a sub with that name isn't later declared.
These two cases are only related in the sense that they are both cases of term
s in the Perl 6 grammar, and that they both look to parse an identifier
, which follow the standard rules linked in the question. Which wins is determined by Longest Token Matching semantics; the restriction that there may only be horizontal whitespace between the identifier and =>
exists to make sure that the identifier, whitespace, and =>
will together be counted as the declarative prefix, and so case 1 will always win over case 2.