Skip to content

Commit

Permalink
remove use of ' as a package separator
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Aug 12, 2024
2 parents 3e14b2f + 83d4e74 commit 0c81a5c
Show file tree
Hide file tree
Showing 33 changed files with 147 additions and 319 deletions.
8 changes: 8 additions & 0 deletions cpan/Scalar-List-Utils/ListUtil.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,8 +1947,10 @@ PREINIT:
STRLEN namelen;
const char* nameptr = SvPV(name, namelen);
int utf8flag = SvUTF8(name);
#if PERL_VERSION_LT(5, 41, 3)
int quotes_seen = 0;
bool need_subst = FALSE;
#endif
PPCODE:
if (!SvROK(sub) && SvGMAGICAL(sub))
mg_get(sub);
Expand All @@ -1971,18 +1973,23 @@ PPCODE:
if (s > nameptr && *s == ':' && s[-1] == ':') {
end = s - 1;
begin = ++s;
#if PERL_VERSION_LT(5, 41, 3)
if (quotes_seen)
need_subst = TRUE;
#endif
}
#if PERL_VERSION_LT(5, 41, 3)
else if (s > nameptr && *s != '\0' && s[-1] == '\'') {
end = s - 1;
begin = s;
if (quotes_seen++)
need_subst = TRUE;
}
#endif
}
s--;
if (end) {
#if PERL_VERSION_LT(5, 41, 3)
SV* tmp;
if (need_subst) {
STRLEN length = end - nameptr + quotes_seen - (*end == '\'' ? 1 : 0);
Expand All @@ -2002,6 +2009,7 @@ PPCODE:
stash = gv_stashpvn(left, length, GV_ADD | utf8flag);
}
else
#endif
stash = gv_stashpvn(nameptr, end - nameptr, GV_ADD | utf8flag);
nameptr = begin;
namelen -= begin - nameptr;
Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/lib/List/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ our @EXPORT_OK = qw(
sample shuffle uniq uniqint uniqnum uniqstr zip zip_longest zip_shortest mesh mesh_longest mesh_shortest
head tail pairs unpairs pairkeys pairvalues pairmap pairgrep pairfirst
);
our $VERSION = "1.63";
our $VERSION = "1.63_01";
our $XS_VERSION = $VERSION;
$VERSION =~ tr/_//d;

Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/lib/List/Util/XS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;
use List::Util;

our $VERSION = "1.63"; # FIXUP
our $VERSION = "1.63_01"; # FIXUP
$VERSION =~ tr/_//d; # FIXUP

1;
Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/lib/Scalar/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ our @EXPORT_OK = qw(
dualvar isdual isvstring looks_like_number openhandle readonly set_prototype
tainted
);
our $VERSION = "1.63";
our $VERSION = "1.63_01";
$VERSION =~ tr/_//d;

require List::Util; # List::Util loads the XS
Expand Down
2 changes: 1 addition & 1 deletion cpan/Scalar-List-Utils/lib/Sub/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ our @EXPORT_OK = qw(
subname set_subname
);

our $VERSION = "1.63";
our $VERSION = "1.63_01";
$VERSION =~ tr/_//d;

require List::Util; # as it has the XS
Expand Down
5 changes: 3 additions & 2 deletions cpan/Scalar-List-Utils/t/exotic_names.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sub caller3_ok {
),
);

$expected =~ s/'/::/g;
$expected =~ s/'/::/g if $] < 5.041_003;

# this is apparently how things worked before 5.16
utf8::encode($expected) if $] < 5.016 and $ord > 255;
Expand Down Expand Up @@ -83,7 +83,8 @@ push @ordinal,

plan tests => @ordinal * 2 * 3;

my $legal_ident_char = "A-Z_a-z0-9'";
my $legal_ident_char = "A-Z_a-z0-9";
$legal_ident_char .= "'" if $] < 5.041_003;
$legal_ident_char .= join '', map chr, 0x100, 0x498
unless $] < 5.008;

Expand Down
2 changes: 1 addition & 1 deletion cpan/parent/lib/parent.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package parent;
use strict;

our $VERSION = '0.241';
our $VERSION = '0.241_001';

sub import {
my $class = shift;
Expand Down
6 changes: 5 additions & 1 deletion cpan/parent/t/compile-time-file.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use lib 't/lib';

{
package Child3;
use parent "Dummy'Outside";
use if $] < 5.041_003, parent => "Dummy'Outside";
}

my $obj = {};
Expand All @@ -39,9 +39,13 @@ isa_ok $obj, 'Dummy::InlineChild';
can_ok $obj, 'exclaim';
is $obj->exclaim, "I CAN FROM Dummy::InlineChild", 'Inheritance is set up correctly for inlined classes';

SKIP:
{
skip "No ' in names from 5.041_003", 3 if $] >= 5.041_003;
$obj = {};
bless $obj, 'Child3';
isa_ok $obj, 'Dummy::Outside';
can_ok $obj, 'exclaim';
is $obj->exclaim, "I CAN FROM Dummy::Outside", "Inheritance is set up correctly for classes inherited from via '";

}
9 changes: 1 addition & 8 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -2995,12 +2995,6 @@ EXpx |char * |scan_word |NN char *s \
|STRLEN destlen \
|int allow_package \
|NN STRLEN *slp
EXpx |char * |scan_word6 |NN char *s \
|NN char *dest \
|STRLEN destlen \
|int allow_package \
|NN STRLEN *slp \
|bool warn_tick
Cp |U32 |seed
: Only used by perl.c/miniperl.c, but defined in caretx.c
ep |void |set_caret_X
Expand Down Expand Up @@ -5894,8 +5888,7 @@ S |void |parse_ident |NN char **s \
|NN char * const e \
|int allow_package \
|bool is_utf8 \
|bool check_dollar \
|bool tick_warn
|bool check_dollar
S |int |pending_ident
RS |char * |scan_const |NN char *start
RS |char * |scan_formline |NN char *s
Expand Down
3 changes: 1 addition & 2 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@
# define lop(a,b,c) S_lop(aTHX_ a,b,c)
# define missingterm(a,b) S_missingterm(aTHX_ a,b)
# define no_op(a,b) S_no_op(aTHX_ a,b)
# define parse_ident(a,b,c,d,e,f,g) S_parse_ident(aTHX_ a,b,c,d,e,f,g)
# define parse_ident(a,b,c,d,e,f) S_parse_ident(aTHX_ a,b,c,d,e,f)
# define pending_ident() S_pending_ident(aTHX)
# define scan_const(a) S_scan_const(aTHX_ a)
# define scan_formline(a) S_scan_formline(aTHX_ a)
Expand Down Expand Up @@ -1765,7 +1765,6 @@
# define report_uninit(a) Perl_report_uninit(aTHX_ a)
# define scan_str(a,b,c,d,e) Perl_scan_str(aTHX_ a,b,c,d,e)
# define scan_word(a,b,c,d,e) Perl_scan_word(aTHX_ a,b,c,d,e)
# define scan_word6(a,b,c,d,e,f) Perl_scan_word6(aTHX_ a,b,c,d,e,f)
# define skipspace_flags(a,b) Perl_skipspace_flags(aTHX_ a,b)
# define sv_magicext_mglob(a) Perl_sv_magicext_mglob(aTHX_ a)
# define sv_only_taint_gmagic Perl_sv_only_taint_gmagic
Expand Down
28 changes: 3 additions & 25 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
* method name.
*
* leaves last_separator pointing to the beginning of the
* last package separator (either ' or ::) or 0
* last package separator (::) or 0
* if none was found.
*
* leaves name pointing at the beginning of the
Expand All @@ -1188,11 +1188,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le
const char *name_cursor = name;
const char * const name_em1 = name_end - 1; /* name_end minus 1 */
for (name_cursor = name; name_cursor < name_end ; name_cursor++) {
if (*name_cursor == '\'') {
last_separator = name_cursor;
name = name_cursor + 1;
}
else if (name_cursor < name_em1 && *name_cursor == ':' && name_cursor[1] == ':') {
if (name_cursor < name_em1 && *name_cursor == ':' && name_cursor[1] == ':') {
last_separator = name_cursor++;
name = name_cursor + 1;
}
Expand Down Expand Up @@ -1802,7 +1798,6 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
const char *name_cursor;
const char *const name_end = nambeg + full_len;
const char *const name_em1 = name_end - 1;
char smallbuf[64]; /* small buffer to avoid a malloc when possible */

PERL_ARGS_ASSERT_PARSE_GV_STASH_NAME;

Expand All @@ -1816,8 +1811,7 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,

for (name_cursor = *name; name_cursor < name_end; name_cursor++) {
if (name_cursor < name_em1 &&
((*name_cursor == ':' && name_cursor[1] == ':')
|| *name_cursor == '\''))
(*name_cursor == ':' && name_cursor[1] == ':'))
{
if (!*stash)
*stash = PL_defstash;
Expand All @@ -1832,22 +1826,6 @@ S_parse_gv_stash_name(pTHX_ HV **stash, GV **gv, const char **name,
key = *name;
*len += 2;
}
else { /* using ' for package separator */
/* use our pre-allocated buffer when possible to save a malloc */
char *tmpbuf;
if ( *len+2 <= sizeof smallbuf)
tmpbuf = smallbuf;
else {
/* only malloc once if needed */
if (tmpfullbuf == NULL) /* only malloc&free once, a little more than needed */
Newx(tmpfullbuf, full_len+2, char);
tmpbuf = tmpfullbuf;
}
Copy(*name, tmpbuf, *len, char);
tmpbuf[(*len)++] = ':';
tmpbuf[(*len)++] = ':';
key = tmpbuf;
}
gvp = (GV**)hv_fetch(*stash, key, is_utf8 ? -((I32)*len) : (I32)*len, add);
*gv = gvp ? *gvp : NULL;
if (!*gv || *gv == (const GV *)&PL_sv_undef) {
Expand Down
2 changes: 1 addition & 1 deletion lib/overload.t
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ is eval {"$a"}, overload::StrVal($a),
{
package mane;
use overload q\""\ => "bear::strength";
use overload bool => "bear'bouillon";
use overload bool => "bear::bouillon";
}
@bear::ISA = 'food';
sub food::strength { 'twine' }
Expand Down
2 changes: 1 addition & 1 deletion mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
* access to a known hint bit in a known OP, we can't
* tell whether HINT_STRICT_REFS is in force or not.
*/
if (!memchr(s, ':', len) && !memchr(s, '\'', len))
if (!memchr(s, ':', len))
Perl_sv_insert_flags(aTHX_ sv, 0, 0, STR_WITH_LEN("main::"),
SV_GMAGIC);
if (i)
Expand Down
11 changes: 1 addition & 10 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10758,7 +10758,7 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
ec ? GV_NOADD_NOINIT
: (IN_PERL_RUNTIME && PL_curstash != CopSTASH(PL_curcop))
|| PL_curstash != PL_defstash
|| memchr(name, ':', namlen) || memchr(name, '\'', namlen)
|| memchr(name, ':', namlen)
? gv_fetch_flags
: GV_ADDMULTI | GV_NOINIT | GV_NOTQUAL;
gv = gv_fetchsv(cSVOPo->op_sv, flags, SVt_PVCV);
Expand Down Expand Up @@ -13419,7 +13419,6 @@ Perl_ck_method(pTHX_ OP *o)
{
SV *sv, *methsv, *rclass;
const char* method;
char* compatptr;
int utf8;
STRLEN len, nsplit = 0, i;
OP* new_op;
Expand All @@ -13430,14 +13429,6 @@ Perl_ck_method(pTHX_ OP *o)

sv = kSVOP->op_sv;

/* replace ' with :: */
while ((compatptr = (char *) memchr(SvPVX(sv), '\'',
SvEND(sv) - SvPVX(sv) )))
{
*compatptr = ':';
sv_insert(sv, compatptr - SvPVX_const(sv), 0, ":", 1);
}

method = SvPVX_const(sv);
len = SvCUR(sv);
utf8 = SvUTF8(sv) ? -1 : 1;
Expand Down
21 changes: 8 additions & 13 deletions pod/perldata.pod
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,17 @@ generic characters, and identifiers should match
That is, any word character in the ASCII range, as long as the first
character is not a digit.

There are two package separators in Perl: A double colon (C<::>) and a single
quote (C<'>). Use of C<'> as the package separator is deprecated and will be
removed in Perl 5.40. Normal identifiers can start or end with a double
colon, and can contain several parts delimited by double colons. Single
quotes have similar rules, but with the exception that they are not legal at
the end of an identifier: That is, C<$'foo> and C<$foo'bar> are legal, but
C<$foo'bar'> is not.
There is one package separator in Perl: A double colon (C<::>).
Normal identifiers can start or end with a double colon, and can
contain several parts delimited by double colons.

Previously you could use C<'> as a package separator, this was removed
in Perl 5.42.

Additionally, if the identifier is preceded by a sigil --
that is, if the identifier is part of a variable name -- it
may optionally be enclosed in braces.

While you can mix double colons with singles quotes, the quotes must come
after the colons: C<$::::'foo> and C<$foo::'bar> are legal, but C<$::'::foo>
and C<$foo'::bar> are not.

Put together, a grammar to match a basic identifier becomes

/
Expand All @@ -164,9 +159,9 @@ Put together, a grammar to match a basic identifier becomes
)
)
(?<normal_identifier>
(?: :: )* '?
(?: :: )*
(?&basic_identifier)
(?: (?= (?: :: )+ '? | (?: :: )* ' ) (?&normal_identifier) )?
(?: (?= :: ) (?&normal_identifier) )?
(?: :: )*
)
(?<basic_identifier>
Expand Down
18 changes: 1 addition & 17 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ results.
of Perl. Check the #! line, or manually feed your script into
Perl yourself.

=item Bad name after %s
=item Bad name after %s::

(F) You started to name a symbol by using a package prefix, and then
didn't finish the symbol. In particular, you can't interpolate outside
Expand Down Expand Up @@ -4797,22 +4797,6 @@ C<sysread()>ing a file, or when seeking past the end of a scalar opened
for I/O (in anticipation of future reads and to imitate the behavior
with real files).

=item Old package separator "'" deprecated

(D deprecated::apostrophe_as_package_separator, syntax) You used the old package
separator "'" in a variable, subroutine or package name. Support for the
old package separator will be removed in Perl 5.42.

=item Old package separator used in string

(D deprecated::apostrophe_as_package_separator, syntax) You used the old package
separator, "'", in a variable named inside a double-quoted string; e.g.,
C<"In $name's house">. This is equivalent to C<"In $name::s house">. If
you meant the former, put a backslash before the apostrophe
(C<"In $name\'s house">).

Support for the old package separator will be removed in Perl 5.42.

=item Only scalar fields can take a :param attribute

(F) You tried to apply the C<:param> attribute to an array or hash field.
Expand Down
18 changes: 3 additions & 15 deletions pod/perlmod.pod
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,6 @@ colon: C<$Package::Variable>. If the package name is null, the
C<main> package is assumed. That is, C<$::sail> is equivalent to
C<$main::sail>.

The old package delimiter was a single quote, but double colon is now the
preferred delimiter, in part because it's more readable to humans, and
in part because it's more readable to B<emacs> macros. It also makes C++
programmers feel like they know what's going on--as opposed to using the
single quote as separator, which was there to make Ada programmers feel
like they knew what was going on. Because the old-fashioned syntax is still
supported for backwards compatibility, if you try to use a string like
C<"This is $owner's house">, you'll be accessing C<$owner::s>; that is,
the $s variable in package C<owner>, which is probably not what you meant.
Use braces to disambiguate, as in C<"This is ${owner}'s house">.
X<::> X<'>

Using C<'> as a package separator is deprecated and will be removed in
Perl 5.40.

Packages may themselves contain package separators, as in
C<$OUTER::INNER::var>. This implies nothing about the order of
name lookups, however. There are no relative packages: all symbols
Expand All @@ -94,6 +79,9 @@ C<$OUTER::INNER::var>. C<INNER> refers to a totally
separate global package. The custom of treating package names as a
hierarchy is very strong, but the language in no way enforces it.

Previously you could use C<'> as a package separator, this was removed
in Perl 5.42.

Only identifiers starting with letters (or underscore) are stored
in a package's symbol table. All other symbols are kept in package
C<main>, including all punctuation variables, like $_. In addition,
Expand Down
Loading

0 comments on commit 0c81a5c

Please sign in to comment.