@@ -307,6 +307,7 @@ my %FILES_CREATED_BY_OBJECT;
307307# use of the O_TEMPORARY flag to sysopen.
308308# Usually irrelevant on unix
309309# "use_exlock" => Indicates that O_EXLOCK should be used. Default is false.
310+ # "write_only" => Indicates that O_WRONLY should be used. Default is false.
310311
311312# Optionally a reference to a scalar can be passed into the function
312313# On error this will be used to store the reason for the error
@@ -501,13 +502,16 @@ sub _gettemp {
501502 # Attempt to open the file
502503 my $open_success = undef ;
503504 if ( $^O eq ' VMS' and $options {" unlink_on_close" } && !$KEEP_ALL ) {
505+ my $flags = $OPENFLAGS ;
506+ $flags = ($flags & ~O_RDWR) | O_WRONLY if $options {write_only };
504507 # make it auto delete on close by setting FAB$V_DLT bit
505- $fh = VMS::Stdio::vmssysopen($path , $OPENFLAGS , 0600, ' fop=dlt' );
508+ $fh = VMS::Stdio::vmssysopen($path , $flags , 0600, ' fop=dlt' );
506509 $open_success = $fh ;
507510 } else {
508511 my $flags = ( ($options {" unlink_on_close" } && !$KEEP_ALL ) ?
509512 $OPENTEMPFLAGS :
510513 $OPENFLAGS );
514+ $flags = ($flags & ~O_RDWR) | O_WRONLY if $options {write_only };
511515 $flags |= $LOCKFLAG if (defined $LOCKFLAG && $options {use_exlock });
512516 $open_success = sysopen ($fh , $path , $flags , 0600);
513517 }
@@ -1048,7 +1052,8 @@ that the temporary file is removed by the object destructor
10481052if UNLINK is set to true (the default).
10491053
10501054Supported arguments are the same as for C<tempfile > : UNLINK
1051- (defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename
1055+ (defaulting to true), DIR, EXLOCK, WRITE_ONLY and SUFFIX.
1056+ Additionally, the filename
10521057template is specified using the TEMPLATE option. The OPEN option
10531058is not supported (the file is always opened).
10541059
@@ -1359,6 +1364,11 @@ versions, explicitly set C<< EXLOCK=>0 >>.
13591364
13601365 ($fh, $filename) = tempfile($template, EXLOCK => 1);
13611366
1367+ Normally, the temporary filehandle is opened for both reading
1368+ and writing. To open for writng only, use C<WRITE_ONLY > .
1369+
1370+ ($fh, $filename) = tempfile($template, WRITE_ONLY => 1);
1371+
13621372Options can be combined as required.
13631373
13641374Will croak() if there is an error.
@@ -1371,6 +1381,8 @@ TMPDIR flag available since 0.19.
13711381
13721382EXLOCK flag available since 0.19.
13731383
1384+ WRITE_ONLY flag available since 0.24.
1385+
13741386=cut
13751387
13761388sub tempfile {
@@ -1382,12 +1394,13 @@ sub tempfile {
13821394
13831395 # Default options
13841396 my %options = (
1385- " DIR" => undef , # Directory prefix
1386- " SUFFIX" => ' ' , # Template suffix
1387- " UNLINK" => 0, # Do not unlink file on exit
1388- " OPEN" => 1, # Open file
1389- " TMPDIR" => 0, # Place tempfile in tempdir if template specified
1390- " EXLOCK" => 0, # Open file with O_EXLOCK
1397+ " DIR" => undef , # Directory prefix
1398+ " SUFFIX" => ' ' , # Template suffix
1399+ " UNLINK" => 0, # Do not unlink file on exit
1400+ " OPEN" => 1, # Open file
1401+ " TMPDIR" => 0, # Place tempfile in tempdir if template specified
1402+ " EXLOCK" => 0, # Open file with O_EXLOCK
1403+ " WRITE_ONLY" => 0, # Open file with O_WRONLY
13911404 );
13921405
13931406 # Check to see whether we have an odd or even number of arguments
@@ -1464,12 +1477,13 @@ sub tempfile {
14641477 my ($fh , $path , $errstr );
14651478 croak " Error in tempfile() using template $template : $errstr "
14661479 unless (($fh , $path ) = _gettemp($template ,
1467- " open" => $options {' OPEN' },
1468- " mkdir" => 0 ,
1480+ " open" => $options {OPEN },
1481+ " mkdir" => 0,
14691482 " unlink_on_close" => $unlink_on_close ,
1470- " suffixlen" => length ($options {' SUFFIX' }),
1471- " ErrStr" => \$errstr ,
1472- " use_exlock" => $options {EXLOCK },
1483+ " suffixlen" => length ($options {SUFFIX }),
1484+ " ErrStr" => \$errstr ,
1485+ " use_exlock" => $options {EXLOCK },
1486+ " write_only" => $options {WRITE_ONLY },
14731487 ) );
14741488
14751489 # Set up an exit handler that can do whatever is right for the
0 commit comments