Stream/Iterator/File.pm

filter: Statementstmt 94.8% 73 / 77 Branchbran 77.2% 17 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.2% 15 / 17 Podpod 50.0% 5 / 10 totaltotal 87.3% 110 / 126 CC 12 SCAR 9.5
CC
12
Cov
91%
new
5.0
DESTROY
4.0
get_size
3.0
CRAP 2.6
« Stream/Iterator/File/MergeSortAsc/Stack.pm ↑ Summary Stream/Iterator/Array.pm »
1 package Data::Range::Compare::Stream::Iterator::File;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use base qw(Data::Range::Compare::Stream::Iterator::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Data::Range::Compare::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 11 ▶sub NEW_FROM { $_[0]->{NEW_FROM} }
Subroutine NEW_FROM: called CC=1 SCAR=0.0
Pod documented
12  
13 124 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod undocumented
14 124 my ($class,%args)=@_;
15  
16 124 my $self=$class->SUPER::new(%args);
17  
18 124 $self->{pos}=0;
19 124 my $has_next;
20  
21 124 ▶ if(defined($args{fh})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'fh'}) { } 88 36 124
elsif (defined $args{'filename'}) { } 34 2 36
22 88 $self->{fh}=$args{fh};
23 88 $self->{filename}=ref($args{fh});
24 88 my $fh=$self->{fh};
25  
26 88 ▶ croak 'fh=>$fh does not suppot getline' unless $fh->can('getline');
Branch: 1 branch
BranchTrueFalseTotal
unless $fh->can("getline") 0 88 88
27  
28 88 my $line=$fh->getline;
29 88 $self->{next_line}=$line;
30 88 $has_next=defined($line);
31  
32 } elsif(defined($args{filename})) {
33 34 my $fh=IO::File->new($args{filename},'r');
34 34 ▶ if($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 34 0 34
35 34 $self->{fh}=$fh;
36 34 my $line=$fh->getline;
37 34 $self->{next_line}=$line;
38 34 $has_next=defined($line);
39 34 $self->{created_fh}=1;
40 } else {
41 0 $self->{msg}="Error could not open $args{filename} error was: $!";
42 }
43  
44 } else {
45 2 $self->{msg}="filename=>undef";
46 }
47  
48 124 $self->{has_next}=$has_next;
49 124 return $self;
50 }
51  
52 1 ▶sub get_size {
Subroutine get_size: called CC=3 SCAR=11.0
Pod documented
53 1 my ($self)=@_;
54 1 ▶ return $self->{size} if defined($self->{size});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"size"} 0 1 1
55  
56 1 my $fh=$self->get_fh;
57 1 my $pos=tell($fh);
58 1 seek($fh,0,0);
59 1 my $size=0;
60 1 ▶ while($fh->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->getline) 4 1 5
61 4 ++$size;
62 }
63 1 $self->{size}=$size;
64 1 seek($fh,$pos,0);
65 1 $size;
66 }
67  
68 5 ▶sub get_pos { $_[0]->{pos} }
Subroutine get_pos: called CC=1 SCAR=0.0
Pod documented
69  
70 18 ▶sub in_error {
Subroutine in_error: called CC=2 SCAR=6.9
Pod undocumented
71 18 my ($self)=@_;
72 18 ▶ return 1 if defined($self->{msg});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"msg"} 2 16 18
73 16 return 0;
74 }
75  
76 0 ▶sub get_error { $_[0]->{msg} }
Subroutine get_error: not called CC=1 SCAR=6.9
Pod undocumented
77  
78 0 ▶sub to_string {
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
79 0 my ($self)=@_;
80 0 return $self->{filename};
81 }
82  
83 61516 ▶sub get_next {
Subroutine get_next: called CC=2 SCAR=7.0
Pod documented
84 61516 my ($self)=@_;
85 61516 ▶ return undef unless $self->has_next;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_next 0 61516 61516
86 61516 ++$self->{pos};
87  
88 61516 my $line=$self->{next_line};
89 61516 $self->{next_line}=$self->{fh}->getline;
90 61516 $self->{has_next}=defined($self->{next_line});
91  
92 61516 return $self->create_from_factory(@{$self->parse_line($line)});
93 }
94  
95 3 ▶sub get_fh { $_[0]->{fh} }
Subroutine get_fh: called CC=1 SCAR=0.0
Pod undocumented
96  
97 2 ▶sub created_fh { $_[0]->{created_fh} }
Subroutine created_fh: called CC=1 SCAR=0.0
Pod undocumented
98  
99 124 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=13.9
100 124 my ($self)=@_;
101 124 ▶ return unless defined($self);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 124 124
102 124 ▶ return unless defined($self->{fh});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"fh"} 2 122 124
103 122 ▶ return unless $self->{created_fh};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"created_fh"} 88 34 122
104 34 $self->{fh}->close;
105 34 $self->{fh}=undef;
106 }
107  
108 4 1;
« Stream/Iterator/File/MergeSortAsc/Stack.pm ↑ Summary Stream/Iterator/Array.pm »