blib/lib/File/ReadSimple.pm

filter: Statementstmt 15.9% 14 / 88 Branchbran 0.0% 0 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 21.4% 3 / 14 Podpod 0.0% 0 / 11 totaltotal 10.3% 17 / 165 CC 27 SCAR 27.4
CC
27
Cov
10%
file_tail
30.0
file_grep_word
20.0
file_grep_word_line_no
20.0
CRAP 15.5
↑ Summary
1 package File::ReadSimple;
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 require Exporter;
8  
9 #our @ISA = qw(Exporter);
10 1 our (@ISA, @EXPORT, $VERSION);
11 1 @ISA = qw(Exporter);
12 1 @EXPORT = qw(file_read file_read_line file_bulk_read_line file_read_last_lines file_read_first_lines file_read_odd_lines file_read_even_lines file_grep_word file_grep_word_line_no file_tail file_word_replace );
13 1 $VERSION = "1.0";
14 # Preloaded methods go here.
15  
16 0 ▶sub file_read {
Subroutine file_read: not called CC=3 SCAR=24.8
Pod undocumented
17 0 ▶open ( FILEREAD, "@_" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open FILEREAD, join($", @_) or die "File not found" 0 0 0
18 0 ▶while ( readline *FILEREAD )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline *FILEREAD)) 0 0 0
19 {
20 0 print $_;
21 }
22 0 close ( FILEREAD );
23 }
24  
25 0 ▶sub file_read_line {
Subroutine file_read_line: not called CC=2 SCAR=17.9
Pod undocumented
26 0 my $linenumber = $_[1] -1;
27 0 ▶open ( FILEREADLINE, "$_[0]" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open FILEREADLINE, "$_[0]" or die "File not found" 0 0 0
28 0 my @lines = <FILEREADLINE>;
29 0 print $lines[$linenumber];
30 0 close ( FILEREADLINE );
31 }
32  
33 0 ▶sub file_bulk_read_line {
Subroutine file_bulk_read_line: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my $linestart = $_[1] - 1;
35 0 my $lineend = $_[2];
36 0 ▶open ( FILEBULKREAD, "$_[0]" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open FILEBULKREAD, "$_[0]" or die "File not found" 0 0 0
37 0 my @line = <FILEBULKREAD>;
38 0 ▶while ( $linestart < $lineend )
Branch: 1 branch
BranchTrueFalseTotal
if ($linestart < $lineend) 0 0 0
39 {
40 0 print $line[$linestart];
41 0 $linestart = $linestart + 1;
42 }
43 0 close ( FILEBULKREAD );
44 }
45  
46 0 ▶sub file_read_last_lines {
Subroutine file_read_last_lines: not called CC=3 SCAR=24.8
Pod undocumented
47 0 my $linestart = $_[1];
48 0 ▶open ( LASTLINES, "$_[0]" ) || die "File not found";
Branch: 1 branch
BranchTrueFalseTotal
open LASTLINES, "$_[0]" or die "File not found" 0 0 0
49 0 my @li = <LASTLINES>;
50 0 ▶while ( $linestart > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($linestart > 0) 0 0 0
51 {
52 0 print $li[-$linestart];
53 0 $linestart = $linestart - 1;
54 }
55 0 close ( LASTLINES );
56 }
57
58 0 ▶sub file_read_first_lines {
Subroutine file_read_first_lines: not called CC=3 SCAR=24.8
Pod undocumented
59 0 ▶open ( FIRSTLINES, "$_[0]" ) || die "File not found";
Branch: 1 branch
BranchTrueFalseTotal
open FIRSTLINES, "$_[0]" or die "File not found" 0 0 0
60 0 my @li = <FIRSTLINES>;
61 0 my $line = 0;
62 0 ▶while ( $line < $_[1] )
Branch: 1 branch
BranchTrueFalseTotal
if ($line < $_[1]) 0 0 0
63 {
64
65 0 print $li[$line];
66 0 $line = $line + 1;
67 }
68 0 close ( FIRSTLINES );
69 }
70  
71 0 ▶sub file_read_odd_lines {
Subroutine file_read_odd_lines: not called CC=3 SCAR=24.8
Pod undocumented
72 0 ▶ open ( ODD, $_[0]) || die "File not found";
Branch: 1 branch
BranchTrueFalseTotal
open ODD, $_[0] or die "File not found" 0 0 0
73 0 my @data = <ODD>;
74 0 my $i = "1";
75 0 my $size = $#data + 1;
76 0 ▶ while ( $i <= $size )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $size) 0 0 0
77 {
78 0 print "$data[$i]";
79 0 $i = $i + 2;
80 }
81 0 close ( ODD );
82 }
83  
84 0 ▶sub file_read_even_lines {
Subroutine file_read_even_lines: not called CC=3 SCAR=24.8
Pod undocumented
85 0 ▶ open ( EVEN, "$_[0]" ) || die "File not found";
Branch: 1 branch
BranchTrueFalseTotal
open EVEN, "$_[0]" or die "File not found" 0 0 0
86 0 my @data = <EVEN>;
87 0 my $i = "0";
88 0 my $size = $#data + 1;
89 0 ▶ while ( $i <= $size )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $size) 0 0 0
90 {
91 0 print "$data[$i]";
92 0 $i = $i + 2;
93  
94 }
95 0 close ( EVEN );
96 }
97  
98 0 ▶sub file_grep_word {
Subroutine file_grep_word: not called CC=4 SCAR=30.0
Pod undocumented
99 0 ▶open ( FILEGREP, "$_[0]" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open FILEGREP, "$_[0]" or die "File not found" 0 0 0
100 0 ▶while ( readline *FILEGREP )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline *FILEGREP)) 0 0 0
101 {
102 0 ▶ print $_ if ( $_ =~ /$_[1]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /$_[1]/ 0 0 0
103 }
104 0 close ( FILEGREP );
105 }
106  
107 0 ▶sub file_grep_word_line_no {
Subroutine file_grep_word_line_no: not called CC=4 SCAR=30.0
Pod undocumented
108 0 my $no = "1";
109 0 ▶open ( FILEGREPNO, "$_[0]" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open FILEGREPNO, "$_[0]" or die "File not found" 0 0 0
110 0 ▶while ( readline *FILEGREPNO )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline *FILEGREPNO)) 0 0 0
111 {
112
113 0 ▶ print "$no:$_ " if ( $_ =~ /$_[1]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /$_[1]/ 0 0 0
114 0 $no = $no + 1;
115 }
116 0 close ( FILEGREPNO );
117 }
118  
119 0 ▶sub file_word_replace {
Subroutine file_word_replace: not called CC=4 SCAR=30.0
Pod undocumented
120 0 ▶open ( GREPREPLACE, "$_[0]" ) || die "File not found" ;
Branch: 1 branch
BranchTrueFalseTotal
open GREPREPLACE, "$_[0]" or die "File not found" 0 0 0
121 0 ▶while ( readline *GREPREPLACE )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline *GREPREPLACE)) 0 0 0
122 {
123 0 ▶if ( $_ =~ /$_[1]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /$_[1]/) 0 0 0
124 {
125 0 $_ =~ s/$_[1]/$_[2]/;
126 0 print $_;
127  
128 }
129 }
130 0 close ( GREPREPLACE );
131 }
132  
133  
134  
135 0 ▶sub file_tail {
Subroutine file_tail: not called CC=5 SCAR=34.0
Pod undocumented
136 0 my $no = "1" ;
137 0 ▶open ( FILETAIL, "$_[0]") || die "File not found";
Branch: 1 branch
BranchTrueFalseTotal
open FILETAIL, "$_[0]" or die "File not found" 0 0 0
138 0 my @lines = <FILETAIL>;
139 0 my $start = $#lines;
140 #my $first = $lines[-1];
141 #my $len = length ($first );
142 0 ▶print $lines[-1] if ( length($lines[-1]) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if length $lines[-1] > 0 0 0 0
143 0 ▶while ($no > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($no > 0) 0 0 0
144 {
145 0 my @new_lines = <FILETAIL>;
146 0 my $end = $#new_lines;
147 0 ▶ if ( $start =! $end )
Branch: 1 branch
BranchTrueFalseTotal
if ($start = !$end) 0 0 0
148 {
149 0 print $new_lines[-1];
150 }
151 }
152 0 close(FILETAIL);
153 }
154  
155  
156  
157  
158 1 1;
159 __END__
↑ Summary