summaryrefslogtreecommitdiff
path: root/ext/POSIX
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2014-10-02 13:40:22 +1000
committerTony Cook <tony@develop-help.com>2014-10-14 11:31:25 +1100
commitcae71c5daa29ee5b24cc6ad145eadb323c1e1612 (patch)
tree01118f9c54db895ca4ffd5a9a6d1d6e1e7b63a5a /ext/POSIX
parentcb93cfd8a42cd5393400053115e38b60d71174cc (diff)
downloadperl-cae71c5daa29ee5b24cc6ad145eadb323c1e1612.tar.gz
deprecate POSIX::tmpnam
This patch avoids repeating the deprecation warning if the same tmpnam() call is executed multiple times.
Diffstat (limited to 'ext/POSIX')
-rw-r--r--ext/POSIX/POSIX.xs7
-rw-r--r--ext/POSIX/lib/POSIX.pm2
-rw-r--r--ext/POSIX/t/posix.t17
3 files changed, 24 insertions, 2 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 1757549232..5f546f5e8f 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -2912,6 +2912,13 @@ tmpnam()
*
* Then again, maybe this should be removed at some point.
* No point in enabling dangerous interfaces. */
+ if (ckWARN_d(WARN_DEPRECATED)) {
+ HV *warned = get_hv("POSIX::_warned", GV_ADD | GV_ADDMULTI);
+ if (! hv_exists(warned, (const char *)&PL_op, sizeof(PL_op))) {
+ Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Calling POSIX::tmpnam() is deprecated");
+ hv_store(warned, (const char *)&PL_op, sizeof(PL_op), &PL_sv_yes, 0);
+ }
+ }
len = strlen(tmpnam(SvPV(RETVAL, i)));
SvCUR_set(RETVAL, len);
OUTPUT:
diff --git a/ext/POSIX/lib/POSIX.pm b/ext/POSIX/lib/POSIX.pm
index be1f09767d..4770a54233 100644
--- a/ext/POSIX/lib/POSIX.pm
+++ b/ext/POSIX/lib/POSIX.pm
@@ -4,7 +4,7 @@ use warnings;
our ($AUTOLOAD, %SIGRT);
-our $VERSION = '1.44';
+our $VERSION = '1.45';
require XSLoader;
diff --git a/ext/POSIX/t/posix.t b/ext/POSIX/t/posix.t
index 398928c74b..18ea0bef41 100644
--- a/ext/POSIX/t/posix.t
+++ b/ext/POSIX/t/posix.t
@@ -8,7 +8,7 @@ BEGIN {
}
}
-use Test::More tests => 117;
+use Test::More tests => 120;
use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
errno localeconv dup dup2 lseek access);
@@ -433,6 +433,21 @@ SKIP: {
cmp_ok($!, '==', POSIX::ENOTDIR);
}
+{ # tmpnam() is deprecated
+ my @warn;
+ local $SIG{__WARN__} = sub { push @warn, "@_"; note "@_"; };
+ my $x = sub { POSIX::tmpnam() };
+ my $foo = $x->();
+ $foo = $x->();
+ is(@warn, 1, "POSIX::tmpnam() should warn only once per location");
+ like($warn[0], qr!^Calling POSIX::tmpnam\(\) is deprecated at t/posix.t line \d+\.$!,
+ "check POSIX::tmpnam warns by default");
+ no warnings "deprecated";
+ undef $warn;
+ my $foo = POSIX::tmpnam();
+ is($warn, undef, "... but the warning can be disabled");
+}
+
# Check that output is not flushed by _exit. This test should be last
# in the file, and is not counted in the total number of tests.
if ($^O eq 'vos') {