File/Source/FlatFile.pm

filter: Statementstmt 46.1% 24 / 52 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 53.8% 7 / 13 Podpod 100% 6 / 6 totaltotal 41.5% 37 / 89 CC 8 SCAR 17.7
CC
8
Cov
36%
next
12.0
advance_to
12.0
new
6.0
CRAP 5.8
« File/Utility.pm ↑ Summary File/State/IPCShareable.pm »
1 package Iterator::File::Source::FlatFile;
2  
3 ## $Id: FlatFile.pm,v 1.6 2008/06/16 07:42:08 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 IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Iterator::File::Source::Interface;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our @ISA = qw(Iterator::File::Source::Interface);
16  
17 1 our $VERSION = substr(q$Revision: 1.6 $, 10);
18  
19 1 our %default_config = ();
20  
21 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
22 0 my ($class, %config) = @_;
23  
24 0 ▶ croak("No file name given!") unless ($config{filename});
Branch: 1 branch
BranchTrueFalseTotal
unless $config{"filename"} 0 0 0
25 0 %config = (%default_config, %config);
26 0 $config{'_current_value'} = undef;
27  
28 ## Instantiation
29 0 my $self = $class->SUPER::new( %config );
30 0 bless($self, $class);
31  
32 0 return $self;
33 }
34  
35  
36 0 ▶sub initialize {
Subroutine initialize: not called CC=2 SCAR=17.9
Pod documented
37 0 my ($self) = @_;
38
39 0 $self->_debug( __PACKAGE__ . " initializing... ");
40
41 my $fh = new IO::File ($self->{filename})
42 0 ▶ || croak("Couldn't open '", $self->{filename}, "': $!");
Condition0%0/2
'IO::File'->new($self->{'filename'}) || croak(q[Couldn't open '], $self->{'filename'}, "': $!")
l!l
00
MC/DC0%0/1
'IO::File'->new($self->{'filename'}) || croak(q[Couldn't open '], $self->{'filename'}, "': $!")
'IO::File'->new($self->{'filename'})
Truth table0%0/2
A
A= 'IO::File'->new($self->{'filename'})
Aresult
11
00
43 0 $self->{'_file_handle'} = $fh;
44  
45 }
46  
47  
48 0 ▶sub next {
Subroutine next: not called CC=3 SCAR=24.8
Pod documented
49 0 my ($self) = @_;
50  
51 0 my $fh = $self->{_file_handle};
52 0 $self->{'_current_value'} = <$fh>;
53
54 0 ▶ if ( $self->{'chomp'} && $self->{'_current_value'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"chomp"} and $self->{"_current_value"}) 0 0 0
Condition0%0/3
$self->{"chomp"} and $self->{"_current_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"chomp"} and $self->{"_current_value"}
$self->{"chomp"} $self->{"_current_value"}
Truth table0%0/3
A and B
A= $self->{"chomp"}B= $self->{"_current_value"}
ABresult
0X0
100
111
55 0 chomp( $self->{'_current_value'} );
56 }
57
58 0 return $self->{'_current_value'};
59 }
60  
61  
62 0 ▶sub advance_to {
Subroutine advance_to: not called CC=3 SCAR=24.8
Pod documented
63 0 my ($self, $marker) = @_;
64  
65 0 ▶ return unless ($marker);
Branch: 1 branch
BranchTrueFalseTotal
unless $marker 0 0 0
66
67 0 $self->_verbose("Advancing to '$marker'...");
68 0 my $i = 0;
69 0 ▶ while ($i++ <= $marker) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i++ <= $marker) 0 0 0
70 0 $self->next();
71 }
72 }
73  
74  
75 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self) = @_;
77  
78 0 return $self->{'_current_value'};
79 }
80  
81  
82 0 ▶sub finish {
Subroutine finish: not called CC=2 SCAR=17.9
Pod documented
83 0 my ($self) = @_;
84  
85 0 my $fh = $self->{'_file_handle'};
86 0 ▶ $fh->close() || warn("Couldn't close '", $self->{'filename'}, "': $!");
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or warn "Couldn't close '", $self->{"filename"}, "': $!" 0 0 0
87 }
88 1 1;
89 __END__
« File/Utility.pm ↑ Summary File/State/IPCShareable.pm »