File/State/TempFile.pm

filter: Statementstmt 43.5% 27 / 62 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 57.1% 8 / 14 Podpod 100% 6 / 6 totaltotal 36.6% 41 / 112 CC 12 SCAR 27.5
CC
12
Cov
31%
new
42.0
initialize
20.0
finish
12.0
CRAP 15.7
↑ Summary File/Utility.pm »
1 package Iterator::File::State::TempFile;
2  
3 ## $Id: TempFile.pm,v 1.8 2008/06/11 05:20:07 wdr1 Exp $
4  
5 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Digest::MD5 qw|md5_hex|;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Iterator::File::State::Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our @ISA = qw(Iterator::File::State::Interface);
17 1 our $VERSION = substr(q$Revision: 1.8 $, 10);
18  
19 1 our %default_config = ();
20  
21  
22 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
23 0 my ($class, %config) = @_;
24  
25 confess("No file name given!")
26 0 ▶ unless ($config{'filename'} || $config{'marker_file'});
Branch: 1 branch
BranchTrueFalseTotal
unless $config{"filename"} or $config{"marker_file"} 0 0 0
Condition0%0/3
$config{"filename"} or $config{"marker_file"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config{"filename"} or $config{"marker_file"}
$config{"filename"} $config{"marker_file"}
Truth table0%0/3
A or B
A= $config{"filename"}B= $config{"marker_file"}
ABresult
1X1
011
000
27  
28 0 %config = (%default_config, %config);
29 0 ▶ unless ($config{'marker_file'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config{"marker_file"}) 0 0 0
30 $config{'marker_file'} = ($ENV{'TMPDIR'} || $ENV{'TEMPDIR'} || '/tmp')
31 0 ▶ . '/iterator-file-' . md5_hex( $config{filename}) . '.tmp';
Condition0%0/5
$ENV{'TMPDIR'} || $ENV{'TEMPDIR'} || '/tmp'
l!l
00
$ENV{"TMPDIR"} or $ENV{"TEMPDIR"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'TMPDIR'} || $ENV{'TEMPDIR'} || '/tmp'
$ENV{"TMPDIR"} $ENV{"TEMPDIR"}
Truth table0%0/3
A or B
A= $ENV{"TMPDIR"}B= $ENV{"TEMPDIR"}
ABresult
1X1
011
000
32 }
33
34 0 my $self = $class->SUPER::new( %config );
35 0 bless($self, $class);
36  
37 0 $self->_verbose("Marker file is '", $self->{'marker_file'}, "'...\n");
38  
39 0 return $self;
40 }
41  
42  
43  
44 0 ▶sub initialize {
Subroutine initialize: not called CC=4 SCAR=30.0
Pod documented
45 0 my ($self) = @_;
46  
47 0 $self->_debug( __PACKAGE__ . " initializing... ");
48
49 0 my $marker_file = $self->{'marker_file'};
50  
51 ## What's our marker (possibly from prior run)
52 0 my $marker = 0;
53 0 ▶ if (-f $marker_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $marker_file) 0 0 0
54 my $fh = new IO::File ($self->{'marker_file'}, "r")
55 0 ▶ || croak("Couldn't open '", $self->{'marker_file'}, "': $!");
Condition0%0/2
'IO::File'->new($self->{'marker_file'}, 'r') || croak(q[Couldn't open '], $self->{'marker_file'}, "': $!")
l!l
00
MC/DC0%0/1
'IO::File'->new($self->{'marker_file'}, 'r') || croak(q[Couldn't open '], $self->{'marker_file'}, "': $!")
'IO::File'->new($self->{'marker_file'}, 'r')
Truth table0%0/2
A
A= 'IO::File'->new($self->{'marker_file'}, 'r')
Aresult
11
00
56 0 $marker = <$fh>;
57 0 $fh->close();
58 }
59  
60 my $fh = new IO::File ($self->{'marker_file'}, "w")
61 0 ▶ || croak("Couldn't open '", $self->{'marker_file'}, "': $!");
Condition0%0/2
'IO::File'->new($self->{'marker_file'}, 'w') || croak(q[Couldn't open '], $self->{'marker_file'}, "': $!")
l!l
00
MC/DC0%0/1
'IO::File'->new($self->{'marker_file'}, 'w') || croak(q[Couldn't open '], $self->{'marker_file'}, "': $!")
'IO::File'->new($self->{'marker_file'}, 'w')
Truth table0%0/2
A
A= 'IO::File'->new($self->{'marker_file'}, 'w')
Aresult
11
00
62
63 0 $self->{'marker_filehandle'} = $fh;
64 0 $self->{'marker'} = $marker;
65
66 0 $self->_verbose( "Starting marker location is '$marker'..." );
67 }
68  
69  
70  
71 0 ▶sub finish {
Subroutine finish: not called CC=3 SCAR=24.8
Pod documented
72 0 my ($self) = @_;
73
74 0 my $fh = $self->{'marker_filehandle'};
75 0 ▶ $fh->close() || warn("Couldn't close '", $self->{'marker_file'}, "': $!");
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or warn "Couldn't close '", $self->{"marker_file"}, "': $!" 0 0 0
76 0 $self->_debug("Removing '", $self->{'marker_file'}, "'...");
77 unlink( $self->{'marker_file'} ) ||
78 0 ▶ warn("Couldn't unlink '", $self->{'marker_file'}, "': $!");
Branch: 1 branch
BranchTrueFalseTotal
unlink $self->{"marker_file"} or warn "Couldn't unlink '", $self->{"marker_file"}, "': $!" 0 0 0
79 }
80  
81  
82  
83 0 ▶sub marker {
Subroutine marker: not called CC=1 SCAR=6.9
Pod documented
84 0 my ($self) = @_;
85
86 0 return $self->{'marker'};
87 }
88  
89  
90  
91 0 ▶sub set_marker {
Subroutine set_marker: not called CC=2 SCAR=17.9
Pod documented
92 0 my ($self, $num) = @_;
93
94 0 $self->{'marker'} = $num;
95 0 my $fh = $self->{'marker_filehandle'};
96 0 ▶ $fh->seek(0, SEEK_SET)
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek(0, 0) or confess("Unable to set position in marker file!") 0 0 0
97 || confess("Unable to set position in marker file!");
98 0 print $fh $self->{'marker'};
99 }
100  
101  
102  
103 0 ▶sub marker_file {
Subroutine marker_file: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($self) = @_;
105  
106 0 return $self->{'marker_file'};
107 }
108  
109  
110  
111 # Preloaded methods go here.
112  
113 1 1;
114 __END__
↑ Summary File/Utility.pm »