line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2014, cPanel, Inc. |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
# http://cpanel.net/ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the same |
6
|
|
|
|
|
|
|
# terms as Perl itself. See the LICENSE file for further details. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::POSIX::IO::Handle; |
9
|
|
|
|
|
|
|
|
10
|
27
|
|
|
27
|
|
527
|
use strict; |
|
27
|
|
|
|
|
29
|
|
|
27
|
|
|
|
|
818
|
|
11
|
27
|
|
|
27
|
|
98
|
use warnings; |
|
27
|
|
|
|
|
35
|
|
|
27
|
|
|
|
|
592
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
89
|
use Fcntl qw(SEEK_CUR); |
|
27
|
|
|
|
|
28
|
|
|
27
|
|
|
|
|
1065
|
|
14
|
27
|
|
|
27
|
|
626
|
use Filesys::POSIX::Bits; |
|
27
|
|
|
|
|
51
|
|
|
27
|
|
|
|
|
7286
|
|
15
|
27
|
|
|
27
|
|
617
|
use Filesys::POSIX::Bits::System; |
|
27
|
|
|
|
|
31
|
|
|
27
|
|
|
|
|
8159
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Filesys::POSIX::IO::Handle - Basic wrapper for Perl file handles |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This package provides a wrapper for standard Perl file handles. It is not meant |
24
|
|
|
|
|
|
|
to supplant the behavior or necessity of L; rather, it is meant to |
25
|
|
|
|
|
|
|
provide a base reference for all of the I/O operations supported by |
26
|
|
|
|
|
|
|
L, which ignores concerns such as buffering and the like. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=over |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item Cnew($fh)> |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Returns a blessed reference to the file handle passed. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
20
|
|
|
20
|
1
|
12876
|
my ( $class, $fh ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
20
|
|
|
|
|
356
|
return bless \$fh, $class; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item C<$handle-Ewrite($buf, $len)> |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Calls L on the current file handle, passing the C<$buf> and |
47
|
|
|
|
|
|
|
C<$len> arguments literally. Returns the result of L. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub write { |
52
|
4990
|
|
|
4990
|
1
|
5692
|
my ( $self, $buf, $len ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
4990
|
|
|
|
|
136605
|
return syswrite( $$self, $buf, $len ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item C<$handle-Eprint(@args)> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Prints a concatenation of each item passed, joined by C<$/>, to the current file |
60
|
|
|
|
|
|
|
handle. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub print { |
65
|
1
|
|
|
1
|
1
|
3
|
my ( $self, @args ) = @_; |
66
|
1
|
|
|
|
|
3
|
my $buf = join( $/, @args ); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
4
|
return $self->write( $buf, length $buf ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item C<$handle-Esprintf($format, @args)> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Prints a formatted string to the current file handle. Uses L. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub printf { |
78
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $format, @args ) = @_; |
79
|
1
|
|
|
|
|
4
|
my $buf = sprintf( $format, @args ); |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
4
|
return $self->write( $buf, length $buf ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item C<$handle-Eread($buf, $len)> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Reads C<$len> bytes from C<$handle> into C<$buf>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub read { |
91
|
4889
|
|
|
4889
|
1
|
4249
|
my $self = shift; |
92
|
4889
|
|
|
|
|
3361
|
my $len = pop; |
93
|
|
|
|
|
|
|
|
94
|
4889
|
|
|
|
|
91032
|
return sysread( $$self, $_[0], $len ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item C<$handle-Eseek($pos, $whence)> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Seek C<$handle> to C<$pos> bytes, relative to the current byte position, |
100
|
|
|
|
|
|
|
according to the seek mode listed in C<$whence>. C<$whence> is a position |
101
|
|
|
|
|
|
|
modifier as specified in L. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub seek { |
106
|
1
|
|
|
1
|
1
|
6
|
my ( $self, $pos, $whence ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
4
|
return sysseek( |
109
|
|
|
|
|
|
|
$$self, $pos, |
110
|
|
|
|
|
|
|
Filesys::POSIX::Bits::System::convertWhenceToSystem($whence) |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item C<$handle-Eeof> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns a boolean indicating whether the file handle has reached end-of-file. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub eof { |
121
|
10
|
|
|
10
|
1
|
12
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
10
|
|
|
|
|
149
|
return eof $$self; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item C<$handle-Etell> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns the current absolute byte position of the current file C<$handle>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub tell { |
133
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
5
|
return sysseek( $$self, 0, SEEK_CUR ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item C<$handle-Eclose> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Close the current file handle. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub close { |
145
|
11
|
|
|
11
|
1
|
22
|
my ($self) = @_; |
146
|
|
|
|
|
|
|
|
147
|
11
|
|
|
|
|
151
|
close $$self; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Provides an implementation of the interface described herein, but for access to |
159
|
|
|
|
|
|
|
regular file data for L filesystem hierarchies. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |