POSIX/IO/Handle.pm

filter: Statementstmt 100% 35 / 35 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 87.5% 7 / 8 totaltotal 98.2% 55 / 56 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« POSIX/Error.pm ↑ Summary POSIX/Mem/Directory.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 28 ▶use Fcntl qw(SEEK_CUR);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 28 ▶use Filesys::POSIX::Bits;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 28 ▶use Filesys::POSIX::Bits::System;
Subroutine BEGIN: called CC=1 SCAR=0.0
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<IO::Handle>; rather, it is meant to
25 provide a base reference for all of the I/O operations supported by
26 L<Filesys::POSIX>, which ignores concerns such as buffering and the like.
27  
28 =head1 METHODS
29  
30 =over
31  
32 =item C<Filesys::POSIX::IO::Handle-E<gt>new($fh)>
33  
34 Returns a blessed reference to the file handle passed.
35  
36 =cut
37  
38 19 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
39 19 my ( $class, $fh ) = @_;
40  
41 19 return bless \$fh, $class;
42 }
43  
44 =item C<$handle-E<gt>write($buf, $len)>
45  
46 Calls L<perlfunc/syswrite> on the current file handle, passing the C<$buf> and
47 C<$len> arguments literally. Returns the result of L<perlfunc/syswrite>.
48  
49 =cut
50  
51 4981 ▶sub write {
Subroutine write: called CC=1 SCAR=0.0
Pod documented
52 4981 my ( $self, $buf, $len ) = @_;
53  
54 4981 return syswrite( $$self, $buf, $len );
55 }
56  
57 =item C<$handle-E<gt>print(@args)>
58  
59 Prints a concatenation of each item passed, joined by C<$/>, to the current file
60 handle.
61  
62 =cut
63  
64 1 ▶sub print {
Subroutine print: called CC=1 SCAR=0.0
Pod documented
65 1 my ( $self, @args ) = @_;
66 1 my $buf = join( $/, @args );
67  
68 1 return $self->write( $buf, length $buf );
69 }
70  
71 =item C<$handle-E<gt>sprintf($format, @args)>
72  
73 Prints a formatted string to the current file handle. Uses L<perlfunc/sprintf>.
74  
75 =cut
76  
77 1 ▶sub printf {
Subroutine printf: called CC=1 SCAR=0.0
Pod undocumented
78 1 my ( $self, $format, @args ) = @_;
79 1 my $buf = sprintf( $format, @args );
80  
81 1 return $self->write( $buf, length $buf );
82 }
83  
84 =item C<$handle-E<gt>read($buf, $len)>
85  
86 Reads C<$len> bytes from C<$handle> into C<$buf>.
87  
88 =cut
89  
90 4888 ▶sub read {
Subroutine read: called CC=1 SCAR=0.0
Pod documented
91 4888 my $self = shift;
92 4888 my $len = pop;
93  
94 4888 return sysread( $$self, $_[0], $len );
95 }
96  
97 =item C<$handle-E<gt>seek($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<Filesys::POSIX::Bits>.
102  
103 =cut
104  
105 1 ▶sub seek {
Subroutine seek: called CC=1 SCAR=0.0
Pod documented
106 1 my ( $self, $pos, $whence ) = @_;
107  
108 1 return sysseek(
109 $$self, $pos,
110 Filesys::POSIX::Bits::System::convertWhenceToSystem($whence)
111 );
112 }
113  
114 =item C<$handle-E<gt>tell>
115  
116 Returns the current absolute byte position of the current file C<$handle>.
117  
118 =cut
119  
120 1 ▶sub tell {
Subroutine tell: called CC=1 SCAR=0.0
Pod documented
121 1 my ($self) = @_;
122  
123 1 return sysseek( $$self, 0, SEEK_CUR );
124 }
125  
126 =item C<$handle-E<gt>close>
127  
128 Close the current file handle.
129  
130 =cut
131  
132 11 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
133 11 my ($self) = @_;
134  
135 11 close $$self;
136 }
137  
138 =back
139  
140 =head1 SEE ALSO
141  
142 =over
143  
144 =item L<Filesys::POSIX::Mem::Bucket>
145  
146 Provides an implementation of the interface described herein, but for access to
147 regular file data for L<Filesys::POSIX::Mem> filesystem hierarchies.
148  
149 =back
150  
151 =cut
152  
153 28 1;
154  
155 __END__
« POSIX/Error.pm ↑ Summary POSIX/Mem/Directory.pm »