| 1 | package File::Temp::Rename; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 1 | $File::Temp::Rename::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Create a temporary file object for output, and rename it when done. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Temp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Copy qw/move/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw/refaddr/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use base qw/File::Temp/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our %obj2original; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 19 | 3 | my %opt = @_; | |||||||||||||||||||||||||||
| 20 | 3 | ▶ | my $filename = delete $opt{FILE} or croak "need FILE argument"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 3 | my $clobber = delete $opt{CLOBBER}; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if (-e $filename and ! $clobber){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-e $filename and not $clobber
MC/DC100%2/2
-e $filename and not $clobber
-e $filename
not $clobber
Truth table100%3/3
A and not(B)
A= -e $filenameB= not $clobber
| |||||||||||||||||||||||||||||
| 24 | 1 | return; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | my $self = $class->SUPER::new(TEMPLATE => "$filename.tmpXXXXX", UNLINK => 0) or croak "couldn't create tmp file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 2 | my $tmp_filename = $self->filename; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | my $addr = refaddr($self); | |||||||||||||||||||||||||||
| 31 | 2 | $obj2original{$addr} = $filename; | |||||||||||||||||||||||||||
| 32 | 2 | return $self; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub DESTROY{ | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 36 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 2 | ▶ | my $filename = delete $obj2original{refaddr($self)} or die "$self does not have appropriate entry in obj2original? bug, please report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 2 | my $tmp_filename = $self->filename; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | $self->SUPER::DESTROY if $self->can("SUPER::DESTROY"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | move($tmp_filename, $filename) or croak "couldn't rename $tmp_filename to $filename"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||