blib/lib/Tie/Array/FileWriter.pm

filter: Statementstmt 60.6% 37 / 61 Branchbran 43.7% 7 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.0% 9 / 20 Podpod n/a totaltotal 54.6% 53 / 97 CC 10 SCAR 12.3
CC
10
Cov
57%
TIEARRAY
8.5
PUSH
4.1
STORESIZE
2.1
CRAP 3.4
↑ Summary
1 package Tie::Array::FileWriter;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.1';
8  
9 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 #
14 # TIEARRAY()
15 #
16  
17 sub TIEARRAY
18 1 ▶{
Subroutine TIEARRAY: called CC=6 SCAR=21.4
19 1 my ($class, $file, $fdelim, $rdelim) = @_;
20  
21 1 ▶ $fdelim = "|" unless defined $fdelim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fdelim 0 1 1
22 1 ▶ $rdelim = "\n" unless defined $rdelim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rdelim 0 1 1
23  
24 1 my $fh;
25 my $close_it;
26  
27 1 ▶ if (ref $file eq 'FileHandle') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file eq 'FileHandle') { } 0 1 1
28 0 ▶ croak "FileHandle is not open for writing!"
Branch: 1 branch
BranchTrueFalseTotal
unless $fh->opened 0 0 0
29 unless $fh->opened;
30  
31 0 $fh = $file;
32 0 $close_it = 0;
33 } else {
34 1 $fh = FileHandle->new(">$file");
35  
36 1 ▶ croak "Unable to open file '$file' for writing: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 1 1
37 unless defined $fh;
38  
39 1 $close_it = 1;
40 }
41  
42 1 return bless {
43 FH => $fh,
44 CLOSE_IT => $close_it,
45 FDELIM => $fdelim,
46 RDELIM => $rdelim
47 }, $class;
48 }
49  
50  
51 #
52 # PUSH()
53 #
54  
55 sub PUSH
56 2 ▶{
Subroutine PUSH: called CC=4 SCAR=14.0
57 2 my $self = shift;
58 2 my $fh = $self->{FH};
59 2 my $fdelim = $self->{FDELIM};
60 2 my $rdelim = $self->{RDELIM};
61
62 2 foreach my $elem (@_) {
63 2 ▶ next unless defined $elem;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 2 2
64 2 ▶ next unless ref $elem eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $elem eq "ARRAY" 0 2 2
65 2 print($fh join($fdelim, @$elem), $rdelim);
66 }
67 }
68  
69  
70 #
71 # UNTIE():
72 #
73  
74 sub UNTIE
75 0 ▶{
Subroutine UNTIE: not called CC=1 SCAR=6.9
76 0 my $self = shift;
77 0 $self->{FH}->close;
78 }
79  
80  
81 #
82 # FETCHSIZE()
83 #
84 # Pushing elements calls FETCHSIZE().
85 #
86  
87 sub FETCHSIZE
88 0 ▶{
Subroutine FETCHSIZE: not called CC=1 SCAR=6.9
89 0 return 0;
90 }
91  
92  
93 #
94 # UNIMPLEMENTED FUNCTIONS:
95 #
96  
97 1 ▶sub CLEAR { my $self = shift; croak("No CLEAR in " . ref $self) }
Subroutine CLEAR: called CC=1 SCAR=0.0
98 0 ▶sub DELETE { my $self = shift; croak("No DELETE in " . ref $self) }
Subroutine DELETE: not called CC=1 SCAR=6.9
99 0 ▶sub EXISTS { my $self = shift; croak("No EXISTS in " . ref $self) }
Subroutine EXISTS: not called CC=1 SCAR=6.9
100 0 ▶sub EXTEND { my $self = shift; croak("No EXTEND in " . ref $self) }
Subroutine EXTEND: not called CC=1 SCAR=6.9
101 0 ▶sub FETCH { my $self = shift; croak("No FETCH in " . ref $self) }
Subroutine FETCH: not called CC=1 SCAR=6.9
102 0 ▶sub POP { my $self = shift; croak("No POP in " . ref $self) }
Subroutine POP: not called CC=1 SCAR=6.9
103 0 ▶sub SPLICE { my $self = shift; croak("No SPLICE in " . ref $self) }
Subroutine SPLICE: not called CC=1 SCAR=6.9
104 0 ▶sub SHIFT { my $self = shift; croak("No SHIFT in " . ref $self) }
Subroutine SHIFT: not called CC=1 SCAR=6.9
105 0 ▶sub STORE { my $self = shift; croak("No STORE in " . ref $self) }
Subroutine STORE: not called CC=1 SCAR=6.9
106 1 ▶sub STORESIZE { my $self = shift; croak("No STORESIZE in " . ref $self) unless shift == 0 }
Subroutine STORESIZE: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless shift() == 0 0 1 1
107 0 ▶sub UNSHIFT { my $self = shift; croak("No UNSHIFT in " . ref $self) }
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
108  
109 1 1;
110 __END__
↑ Summary