summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-04-12 16:28:49 +0100
committerNicholas Clark <nick@ccl4.org>2009-04-12 16:30:04 +0100
commitf1a3ce43fb80c48e414d9b35caf0ac62cb80ff4e (patch)
tree791e875cd154b0eb151d6b456d80a77ed5d3d507
parentc32124fea7b8ddab6f359599ed11fec4ff102451 (diff)
downloadperl-f1a3ce43fb80c48e414d9b35caf0ac62cb80ff4e.tar.gz
Deprecate using "unique" with the attributes pragma.
-rw-r--r--ext/attributes/attributes.pm9
-rw-r--r--ext/attributes/attributes.xs25
-rw-r--r--pod/perldiag.pod7
-rw-r--r--t/op/attrs.t5
4 files changed, 20 insertions, 26 deletions
diff --git a/ext/attributes/attributes.pm b/ext/attributes/attributes.pm
index ac5ef09647..e94282c79b 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 dceef68b50..7a86cd76c1 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 746c3b9b63..f2a4a1a72f 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 f124e8dded..5ba0fdacf9 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) {