From: Nicholas Clark Date: Sun, 12 Apr 2009 15:28:49 +0000 (+0100) Subject: Deprecate using "unique" with the attributes pragma. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1a3ce43fb80c48e414d9b35caf0ac62cb80ff4e;p=p5sagit%2Fp5-mst-13.2.git Deprecate using "unique" with the attributes pragma. --- diff --git a/ext/attributes/attributes.pm b/ext/attributes/attributes.pm index ac5ef09..e94282c 100644 --- a/ext/attributes/attributes.pm +++ b/ext/attributes/attributes.pm @@ -18,6 +18,11 @@ sub carp { goto &Carp::carp; } +my %deprecated; +$deprecated{CODE} = qr/\A-?(locked)\z/; +$deprecated{ARRAY} = $deprecated{HASH} = $deprecated{SCALAR} + = qr/\A-?(unique)\z/; + sub _modify_attrs_and_deprecate { my $svtype = shift; # Now that we've removed handling of locked from the XS code, we need to @@ -25,9 +30,9 @@ sub _modify_attrs_and_deprecate { # XS, we can't control the warning based on *our* caller's lexical settings, # and the warned line is in this package) grep { - $svtype eq 'CODE' && /\A-?locked\z/ ? do { + $deprecated{$svtype} && /$deprecated{$svtype}/ ? do { require warnings; - warnings::warnif('deprecated', 'Attribute "locked" is deprecated'); + warnings::warnif('deprecated', "Attribute \"$1\" is deprecated"); 0; } : 1 } _modify_attrs(@_); diff --git a/ext/attributes/attributes.xs b/ext/attributes/attributes.xs index dceef68..7a86cd7 100644 --- a/ext/attributes/attributes.xs +++ b/ext/attributes/attributes.xs @@ -68,31 +68,12 @@ modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs) } break; default: - switch ((int)len) { - case 6: - switch (name[5]) { - case 'd': - if (memEQ(name, "share", 5)) { + if (memEQs(name, 6, "shared")) { if (negated) Perl_croak(aTHX_ "A variable may not be unshared"); SvSHARE(sv); continue; - } - break; - case 'e': - if (memEQ(name, "uniqu", 5)) { - if (isGV_with_GP(sv)) { - if (negated) { - GvUNIQUE_off(sv); - } else { - GvUNIQUE_on(sv); - } - } - /* Hope this came from toke.c if not a GV. */ - continue; - } - } - } + } break; } /* anything recognized had a 'continue' above */ @@ -238,4 +219,4 @@ usage: * End: * * ex: set ts=8 sts=4 sw=4 noet: - */ \ No newline at end of file + */ diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 746c3b9..f2a4a1a 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -313,6 +313,13 @@ attribute on a code reference. The :locked attribute is obsolete, has had no effect since 5005 threads were removed, and will be removed in the next major release of Perl 5. +=item Attribute "unique" is deprecated + +(D deprecated) You have used the attributes pragam to modify the "unique" +attribute on a array, hash or scalar reference. The :unique attribute is has +had no no effect since Perl 5.8.8, and will be removed in the next major +release of Perl 5. + =item Bad arg length for %s, is %d, should be %s (F) You passed a buffer of the wrong size to one of msgctl(), semctl() diff --git a/t/op/attrs.t b/t/op/attrs.t index f124e8d..5ba0fda 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -149,14 +149,15 @@ like $@, qr/Can't declare scalar dereference in "my"/; my @code = qw(lvalue method); -my @other = qw(shared unique); -my @deprecated = qw(locked); +my @other = qw(shared); +my @deprecated = qw(locked unique); my %valid; $valid{CODE} = {map {$_ => 1} @code}; $valid{SCALAR} = {map {$_ => 1} @other}; $valid{ARRAY} = $valid{HASH} = $valid{SCALAR}; my %deprecated; $deprecated{CODE} = { locked => 1 }; +$deprecated{ARRAY} = $deprecated{HASH} = $deprecated{SCALAR} = { unique => 1 }; our ($scalar, @array, %hash); foreach my $value (\&foo, \$scalar, \@array, \%hash) {