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
|
28
|
|
|
28
|
|
457
|
use strict; |
|
28
|
|
|
|
|
29
|
|
|
28
|
|
|
|
|
610
|
|
11
|
28
|
|
|
28
|
|
77
|
use warnings; |
|
28
|
|
|
|
|
25
|
|
|
28
|
|
|
|
|
648
|
|
12
|
|
|
|
|
|
|
|
13
|
28
|
|
|
28
|
|
87
|
use Fcntl qw(SEEK_CUR); |
|
28
|
|
|
|
|
42
|
|
|
28
|
|
|
|
|
980
|
|
14
|
28
|
|
|
28
|
|
469
|
use Filesys::POSIX::Bits; |
|
28
|
|
|
|
|
25
|
|
|
28
|
|
|
|
|
6783
|
|
15
|
28
|
|
|
28
|
|
478
|
use Filesys::POSIX::Bits::System; |
|
28
|
|
|
|
|
30
|
|
|
28
|
|
|
|
|
6806
|
|
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
|
19
|
|
|
19
|
1
|
9383
|
my ( $class, $fh ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
19
|
|
|
|
|
279
|
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
|
4981
|
|
|
4981
|
1
|
4360
|
my ( $self, $buf, $len ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
4981
|
|
|
|
|
136070
|
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
|
2
|
my ( $self, @args ) = @_; |
66
|
1
|
|
|
|
|
2
|
my $buf = join( $/, @args ); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
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
|
2
|
my ( $self, $format, @args ) = @_; |
79
|
1
|
|
|
|
|
4
|
my $buf = sprintf( $format, @args ); |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
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
|
4888
|
|
|
4888
|
1
|
3354
|
my $self = shift; |
92
|
4888
|
|
|
|
|
2871
|
my $len = pop; |
93
|
|
|
|
|
|
|
|
94
|
4888
|
|
|
|
|
78222
|
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
|
5
|
my ( $self, $pos, $whence ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
6
|
return sysseek( |
109
|
|
|
|
|
|
|
$$self, $pos, |
110
|
|
|
|
|
|
|
Filesys::POSIX::Bits::System::convertWhenceToSystem($whence) |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item C<$handle-Etell> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns the current absolute byte position of the current file C<$handle>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub tell { |
121
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
4
|
return sysseek( $$self, 0, SEEK_CUR ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item C<$handle-Eclose> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Close the current file handle. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub close { |
133
|
11
|
|
|
11
|
1
|
19
|
my ($self) = @_; |
134
|
|
|
|
|
|
|
|
135
|
11
|
|
|
|
|
230
|
close $$self; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Provides an implementation of the interface described herein, but for access to |
147
|
|
|
|
|
|
|
regular file data for L filesystem hierarchies. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |