From: Nicholas Clark Date: Sat, 24 Oct 2009 09:25:28 +0000 (+0100) Subject: Make defined %hash on a non-lexical (also) generate a deprecated warning. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d47e1c27dd43d7b79216c58864a5e539f612e974;p=p5sagit%2Fp5-mst-13.2.git Make defined %hash on a non-lexical (also) generate a deprecated warning. Tk has been fixed, and no longer uses defined %stash:: to determine if a package has been loaded. --- diff --git a/op.c b/op.c index e629a42..8741337 100644 --- a/op.c +++ b/op.c @@ -7225,11 +7225,6 @@ Perl_ck_defined(pTHX_ OP *o) /* 19990527 MJD */ "\t(Maybe you should just omit the defined()?)\n"); break; case OP_RV2HV: - /* This is needed for - if (defined %stash::) - to work. Do not break Tk. - */ - break; /* Globals via GV can be undef */ case OP_PADHV: Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED), "defined(%%hash) is deprecated"); diff --git a/t/lib/strict/refs b/t/lib/strict/refs index 6237d6d..075ca49 100644 --- a/t/lib/strict/refs +++ b/t/lib/strict/refs @@ -321,4 +321,6 @@ use strict 'refs'; my $x = "foo"; defined %$x; EXPECT +defined(%hash) is deprecated at - line 4. + (Maybe you should just omit the defined()?) Can't use string ("foo") as a HASH ref while "strict refs" in use at - line 4. diff --git a/t/op/gv.t b/t/op/gv.t index e04c2ca..1b705ef 100644 --- a/t/op/gv.t +++ b/t/op/gv.t @@ -167,7 +167,10 @@ is (*{*x{GLOB}}, "*main::STDOUT"); ok(!defined @{$a}); ok(!defined *{$a}); - ok(!defined %{$a}); + { + no warnings 'deprecated'; + ok(!defined %{$a}); + } ok(!defined *{$a}); ok(!defined ${$a}); diff --git a/t/op/stash.t b/t/op/stash.t index 57c8659..8ea829b 100644 --- a/t/op/stash.t +++ b/t/op/stash.t @@ -25,14 +25,17 @@ fresh_perl_is( q(Insert a non-GV in a stash, under warnings 'once'), ); -ok( !defined %oedipa::maas::, q(stashes aren't defined if not used) ); -ok( !defined %{"oedipa::maas::"}, q(- work with hard refs too) ); +{ + no warnings 'deprecated'; + ok( !defined %oedipa::maas::, q(stashes aren't defined if not used) ); + ok( !defined %{"oedipa::maas::"}, q(- work with hard refs too) ); -ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) ); -ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) ); + ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) ); + ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) ); -ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) ); -ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) ); + ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) ); + ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) ); +} package tyrone::slothrop; $bongo::shaftsbury::scalar = 1; @@ -53,13 +56,14 @@ package main; # now tests in eval -ok( !eval { defined %achtfaden:: }, 'works in eval{}' ); -ok( !eval q{ defined %schoenmaker:: }, 'works in eval("")' ); +ok( !eval { no warnings 'deprecated'; defined %achtfaden:: }, 'works in eval{}' ); +ok( !eval q{ no warnings 'deprecated'; defined %schoenmaker:: }, 'works in eval("")' ); # now tests with strictures { use strict; + no warnings 'deprecated'; ok( !defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) ); ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) ); } diff --git a/t/op/undef.t b/t/op/undef.t index 7afaf9c..ff45c2a 100644 --- a/t/op/undef.t +++ b/t/op/undef.t @@ -10,7 +10,7 @@ use strict; use vars qw(@ary %ary %hash); -plan 37; +plan 40; ok !defined($a); @@ -45,15 +45,27 @@ undef $ary{'foo'}; ok !defined($ary{'foo'}); ok defined(@ary); -ok defined(%ary); +{ + no warnings 'deprecated'; + ok defined(%ary); +} +ok %ary; undef @ary; ok !defined(@ary); undef %ary; -ok !defined(%ary); +{ + no warnings 'deprecated'; + ok !defined(%ary); +} +ok !%ary; @ary = (1); ok defined @ary; %ary = (1,1); -ok defined %ary; +{ + no warnings 'deprecated'; + ok defined %ary; +} +ok %ary; sub foo { pass; 1 }