summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-03-30 07:48:59 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-03-30 07:48:59 +0000
commitabc718f2ca5cfe66c838e1324c1c153a085fea8b (patch)
tree23211c9fc93b1552429344d0efc4a0a611dd54ac
parent37723ebb3f0f145b85438cb89891a2c80a5f149e (diff)
downloadperl-abc718f2ca5cfe66c838e1324c1c153a085fea8b.tar.gz
Add two deprecation warnings:
Opening dirhandle %s also as a file Opening filehandle %s also as a directory p4raw-id: //depot/perl@30780
-rw-r--r--pod/perldiag.pod14
-rw-r--r--pp_sys.c8
-rw-r--r--t/lib/warnings/pp_sys26
-rw-r--r--t/op/chdir.t7
4 files changed, 53 insertions, 2 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index b80331d555..eeef207c14 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2836,6 +2836,20 @@ that isn't open. Check your control flow. See also L<perlfunc/-X>.
(S internal) An internal warning that the grammar is screwed up.
+=item Opening dirhandle %s also as a file
+
+(W io deprecated) You used open() to associate a filehandle to
+a symbol (glob or scalar) that already holds a dirhandle.
+Although legal, this idiom might render your code confusing
+and is deprecated.
+
+=item Opening filehandle %s also as a directory
+
+(W io deprecated) You used opendir() to associate a dirhandle to
+a symbol (glob or scalar) that already holds a filehandle.
+Although legal, this idiom might render your code confusing
+and is deprecated.
+
=item Operation "%s": no method found, %s
(F) An attempt was made to perform an overloaded operation for which no
diff --git a/pp_sys.c b/pp_sys.c
index 5693d5063c..aa36bef9aa 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -538,10 +538,15 @@ PP(pp_open)
if (!isGV(gv))
DIE(aTHX_ PL_no_usym, "filehandle");
+
if ((io = GvIOp(gv))) {
MAGIC *mg;
IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
+ if (IoDIRP(io) && ckWARN2(WARN_IO, WARN_DEPRECATED))
+ Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+ "Opening dirhandle %s also as a file", GvENAME(gv));
+
mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar);
if (mg) {
/* Method's args are same as ours ... */
@@ -3769,6 +3774,9 @@ PP(pp_open_dir)
if (!io)
goto nope;
+ if ((IoIFP(io) || IoOFP(io)) && ckWARN2(WARN_IO, WARN_DEPRECATED))
+ Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+ "Opening filehandle %s also as a directory", GvENAME(gv));
if (IoDIRP(io))
PerlDir_close(IoDIRP(io));
if (!(IoDIRP(io) = PerlDir_open(dirname)))
diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys
index 0dd3efea7a..2e9c613b02 100644
--- a/t/lib/warnings/pp_sys
+++ b/t/lib/warnings/pp_sys
@@ -494,3 +494,29 @@ chdir() on unopened filehandle FOO at - line 20.
chdir() on closed filehandle BAR at - line 21.
chdir() on unopened filehandle $dh at - line 22.
chdir() on closed filehandle $fh at - line 23.
+########
+# pp_sys.c [pp_open]
+use warnings;
+opendir FOO, ".";
+opendir my $foo, ".";
+open FOO, "TEST";
+open $foo, "TEST";
+no warnings qw(io deprecated);
+open FOO, "TEST";
+open $foo, "TEST";
+EXPECT
+Opening dirhandle FOO also as a file at - line 5.
+Opening dirhandle $foo also as a file at - line 6.
+########
+# pp_sys.c [pp_open_dir]
+use warnings;
+open FOO, "TEST";
+open my $foo, "TEST";
+opendir FOO, ".";
+opendir $foo, ".";
+no warnings qw(io deprecated);
+opendir FOO, ".";
+opendir $foo, ".";
+EXPECT
+Opening filehandle FOO also as a directory at - line 5.
+Opening filehandle $foo also as a directory at - line 6.
diff --git a/t/op/chdir.t b/t/op/chdir.t
index 79b91fffa1..db58e126de 100644
--- a/t/op/chdir.t
+++ b/t/op/chdir.t
@@ -78,8 +78,11 @@ SKIP: {
ok(-d "op", "verify that we are back");
# And now the ambiguous case
- ok(opendir(H, "op"), "opendir op") or diag $!;
- ok(open(H, "<", "base"), "open base") or diag $!;
+ {
+ no warnings qw<io deprecated>;
+ ok(opendir(H, "op"), "opendir op") or diag $!;
+ ok(open(H, "<", "base"), "open base") or diag $!;
+ }
if (($Config{d_dirfd} || "") eq "define") {
ok(chdir(H), "fchdir to op");
ok(-f "chdir.t", "verify that we are in 'op'");