package attributes;
-our $VERSION = 0.11;
+our $VERSION = 0.12;
@EXPORT_OK = qw(get reftype);
@EXPORT = ();
goto &Carp::carp;
}
+sub _modify_attrs_and_deprecate {
+ my $svtype = shift;
+ # Now that we've removed handling of locked from the XS code, we need to
+ # remove it here, else it ends up in @badattrs. (If we do the deprecation in
+ # 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 {
+ require warnings;
+ warnings::warnif('deprecated', 'Attribute "locked" is deprecated');
+ 0;
+ } : 1
+ } _modify_attrs(@_);
+}
+
sub import {
@_ > 2 && ref $_[2] or do {
require Exporter;
if defined $home_stash && $home_stash ne '';
my @badattrs;
if ($pkgmeth) {
- my @pkgattrs = _modify_attrs($svref, @attrs);
+ my @pkgattrs = _modify_attrs_and_deprecate($svtype, $svref, @attrs);
@badattrs = $pkgmeth->($home_stash, $svref, @pkgattrs);
if (!@badattrs && @pkgattrs) {
require warnings;
}
}
else {
- @badattrs = _modify_attrs($svref, @attrs);
+ @badattrs = _modify_attrs_and_deprecate($svtype, $svref, @attrs);
}
if (@badattrs) {
croak "Invalid $svtype attribute" .
continue;
}
break;
- case 'k':
- if (memEQ(name, "locked", 6)) {
- if (negated)
- CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LOCKED;
- else
- CvFLAGS(MUTABLE_CV(sv)) |= CVf_LOCKED;
- continue;
- }
- break;
case 'h':
if (memEQ(name, "method", 6)) {
if (negated)
used as an lvalue, which is pretty strange. Perhaps you forgot to
dereference it first. See L<perlfunc/substr>.
+=item Attribute "locked" is deprecated
+
+(D deprecated) You have used the attributes pragam to modify the "locked"
+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 Bad arg length for %s, is %d, should be %s
(F) You passed a buffer of the wrong size to one of msgctl(), semctl()
like $@, qr/Can't declare scalar dereference in "my"/;
-my @code = qw(lvalue locked method);
+my @code = qw(lvalue method);
my @other = qw(shared unique);
+my @deprecated = qw(locked);
my %valid;
$valid{CODE} = {map {$_ => 1} @code};
$valid{SCALAR} = {map {$_ => 1} @other};
$valid{ARRAY} = $valid{HASH} = $valid{SCALAR};
+my %deprecated;
+$deprecated{CODE} = { locked => 1 };
our ($scalar, @array, %hash);
foreach my $value (\&foo, \$scalar, \@array, \%hash) {
my $type = ref $value;
foreach my $negate ('', '-') {
- foreach my $attr (@code, @other) {
+ foreach my $attr (@code, @other, @deprecated) {
my $attribute = $negate . $attr;
eval "use attributes __PACKAGE__, \$value, '$attribute'";
- if ($valid{$type}{$attr}) {
+ if ($deprecated{$type}{$attr}) {
+ like $@, qr/^Attribute "$attr" is deprecated at \(eval \d+\)/,
+ "$type attribute $attribute deprecated";
+ } elsif ($valid{$type}{$attr}) {
if ($attribute eq '-shared') {
like $@, qr/^A variable may not be unshared/;
} else {