| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Open::OOP; |
|
2
|
1
|
|
|
1
|
|
1309
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
53
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
65
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
20
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
134
|
|
|
8
|
1
|
|
|
1
|
|
1132
|
use File::Open qw(fopen); |
|
|
1
|
|
|
|
|
1418
|
|
|
|
1
|
|
|
|
|
268
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(oopen); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
File::Open::OOP - An Object Oriented way to read and write files |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Reading lines one-by-one |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use File::Open::OOP qw(oopen); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $fh = oopen 'filename'; |
|
23
|
|
|
|
|
|
|
while ( my $row = $fh->readline ) { |
|
24
|
|
|
|
|
|
|
print $row; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Reading all the line at once: |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @rows = oopen('filename')->readall; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Reading all the lines into a single scalar: |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $rows = oopen('filename')->slurp; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 OTHER |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This module is based on the L module of Lukas Mai. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 AUTHOR |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Gabor Szabo C<< >> |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Copyright 2011 Gabor Szabo. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
48
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
49
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
See L for more information. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
|
56
|
4
|
|
|
4
|
0
|
12
|
my ($class, %args) = @_; |
|
57
|
4
|
|
|
|
|
7
|
my $self = \%args; |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
24
|
return bless $self, $class; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub oopen { |
|
63
|
4
|
|
|
4
|
0
|
1583
|
my $fh = fopen(@_); |
|
64
|
4
|
|
|
|
|
354
|
return File::Open::OOP->new(fh => $fh); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub readline { |
|
68
|
39
|
|
|
39
|
0
|
22828
|
my ($self) = @_; |
|
69
|
39
|
|
|
|
|
67
|
my $fh = $self->{fh}; |
|
70
|
39
|
|
|
|
|
207
|
return scalar <$fh>; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub readall { |
|
74
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
|
75
|
1
|
|
|
|
|
3
|
my $fh = $self->{fh}; |
|
76
|
1
|
|
|
|
|
35
|
return <$fh>; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub slurp { |
|
80
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
|
81
|
1
|
|
|
|
|
3
|
my $fh = $self->{fh}; |
|
82
|
1
|
|
|
|
|
5
|
local $/ = undef; |
|
83
|
1
|
|
|
|
|
31
|
return scalar <$fh>; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |