blib/lib/File/Cat.pm

filter: Statementstmt 100% 32 / 32 Branchbran 71.4% 10 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 77.7% 49 / 63 CC 10 SCAR 15.7
CC
10
Cov
85%
cattail
6.2
cat
5.4
BEGIN
1.0
CRAP 4.8
↑ Summary
1 package File::Cat;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 @ISA = qw(Exporter);
10 1 @EXPORT = qw( &cat &cattail );
11  
12 1 $VERSION = '1.2';
13  
14  
15  
16 =head1 NAME
17  
18 File::Cat - Perl implementation of cat(1)
19  
20 =head1 SYNOPSIS
21  
22 use File::Cat;
23  
24 cat ('/etc/motd', \*STDOUT)
25 or die "Can't cat /etc/motd: $!";
26  
27 =head1 DESCRIPTION
28  
29 File::Cat is a module of adventure, danger, and low cunning. With it, you
30 will explore some of the most inane programs ever seen by mortals. No
31 computer should be without one!
32  
33 =head1 FUNCTIONS
34  
35 =over
36  
37 =item *
38  
39 cat I<EXPR>, I<FILEHANDLE>
40  
41 Copies data from EXPR to FILEHANDLE, or returns false if an error occurred.
42 EXPR can be either an open readable filehandle or a filename to use as input.
43  
44 =cut
45  
46  
47  
48 1 ▶sub cat ($$) {
Subroutine cat: called CC=5 SCAR=16.8
Pod undocumented
49 1 my ($input, $handle) = @_;
50  
51 1 ▶ unless (ref \$input eq 'GLOB' or ref \$input eq 'REF') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref \$input eq "GLOB" or ref \$input eq "REF") 1 0 1
Condition33%1/3
ref \$input eq "GLOB" or ref \$input eq "REF"
l!l&&r!l&&!r
001
MC/DC0%0/2
ref \$input eq "GLOB" or ref \$input eq "REF"
ref \$input eq "GLOB" ref \$input eq "REF"
Truth table33%1/3
A or B
A= ref \$input eq "GLOB"B= ref \$input eq "REF"
ABresult
1X1
011
000
52 1 ▶ open FILE, $input or return;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $input or return 1 0 1
53 }
54 1 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 4 1 5
55 4 print $handle $_;
56 }
57 1 close FILE;
58
59 1 return (1);
60 }
61  
62  
63  
64 =pod
65  
66 =item *
67  
68 cattail I<EXPR>, I<FILEHANDLE>
69  
70 Prints EXPR to FILEHANDLE -- backwards, line by line -- or returns
71 false if an error occurred. Again, EXPR can be either a filehandle
72 or a filename.
73  
74 =cut
75  
76  
77  
78 1 ▶sub cattail ($$) {
Subroutine cattail: called CC=6 SCAR=18.2
Pod undocumented
79 1 my ($input, $handle) = @_;
80 1 my @lines = (0);
81  
82 1 ▶ unless (ref \$input eq 'GLOB' or ref \$input eq 'REF') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref \$input eq "GLOB" or ref \$input eq "REF") 1 0 1
Condition33%1/3
ref \$input eq "GLOB" or ref \$input eq "REF"
l!l&&r!l&&!r
001
MC/DC0%0/2
ref \$input eq "GLOB" or ref \$input eq "REF"
ref \$input eq "GLOB" ref \$input eq "REF"
Truth table33%1/3
A or B
A= ref \$input eq "GLOB"B= ref \$input eq "REF"
ABresult
1X1
011
000
83 1 ▶ open FILE, $input or return;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $input or return 1 0 1
84 }
85  
86 1 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 4 1 5
87 4 $lines[$.] = tell FILE;
88 }
89  
90 1 pop @lines;
91 1 ▶ while (defined ($_ = pop @lines)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = pop @lines)) 4 1 5
92 4 seek FILE, $_, 0;
93 4 print $handle scalar(<FILE>);
94 }
95 1 close FILE;
96  
97 1 return (1);
98 }
99  
100  
101  
102 =pod
103  
104 =back
105  
106 =head1 AUTHOR
107  
108 Dennis Taylor, E<lt>corbeau@execpc.comE<gt>
109  
110 =head1 APOLOGIES TO...
111  
112 Marc Blank.
113  
114 =head1 SEE ALSO
115  
116 cat(1)
117  
118 =cut
↑ Summary