1N/A#
1N/A
1N/Apackage IO::Seekable;
1N/A
1N/A=head1 NAME
1N/A
1N/AIO::Seekable - supply seek based methods for I/O objects
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A use IO::Seekable;
1N/A package IO::Something;
1N/A @ISA = qw(IO::Seekable);
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AC<IO::Seekable> does not have a constructor of its own as it is intended to
1N/Abe inherited by other C<IO::Handle> based objects. It provides methods
1N/Awhich allow seeking of the file descriptors.
1N/A
1N/A=over 4
1N/A
1N/A=item $io->getpos
1N/A
1N/AReturns an opaque value that represents the current position of the
1N/AIO::File, or C<undef> if this is not possible (eg an unseekable stream such
1N/Aas a terminal, pipe or socket). If the fgetpos() function is available in
1N/Ayour C library it is used to implements getpos, else perl emulates getpos
1N/Ausing C's ftell() function.
1N/A
1N/A=item $io->setpos
1N/A
1N/AUses the value of a previous getpos call to return to a previously visited
1N/Aposition. Returns "0 but true" on success, C<undef> on failure.
1N/A
1N/A=back
1N/A
1N/ASee L<perlfunc> for complete descriptions of each of the following
1N/Asupported C<IO::Seekable> methods, which are just front ends for the
1N/Acorresponding built-in functions:
1N/A
1N/A=over 4
1N/A
1N/A=item $io->seek ( POS, WHENCE )
1N/A
1N/ASeek the IO::File to position POS, relative to WHENCE:
1N/A
1N/A=over 8
1N/A
1N/A=item WHENCE=0 (SEEK_SET)
1N/A
1N/APOS is absolute position. (Seek relative to the start of the file)
1N/A
1N/A=item WHENCE=1 (SEEK_CUR)
1N/A
1N/APOS is an offset from the current position. (Seek relative to current)
1N/A
1N/A=item WHENCE=2 (SEEK_END)
1N/A
1N/APOS is an offset from the end of the file. (Seek relative to end)
1N/A
1N/A=back
1N/A
1N/AThe SEEK_* constants can be imported from the C<Fcntl> module if you
1N/Adon't wish to use the numbers C<0> C<1> or C<2> in your code.
1N/A
1N/AReturns C<1> upon success, C<0> otherwise.
1N/A
1N/A=item $io->sysseek( POS, WHENCE )
1N/A
1N/ASimilar to $io->seek, but sets the IO::File's position using the system
1N/Acall lseek(2) directly, so will confuse most perl IO operators except
1N/Asysread and syswrite (see L<perlfunc> for full details)
1N/A
1N/AReturns the new position, or C<undef> on failure. A position
1N/Aof zero is returned as the string C<"0 but true">
1N/A
1N/A=item $io->tell
1N/A
1N/AReturns the IO::File's current position, or -1 on error.
1N/A
1N/A=back
1N/A
1N/A=head1 SEE ALSO
1N/A
1N/AL<perlfunc>,
1N/AL<perlop/"I/O Operators">,
1N/AL<IO::Handle>
1N/AL<IO::File>
1N/A
1N/A=head1 HISTORY
1N/A
1N/ADerived from FileHandle.pm by Graham Barr E<lt>gbarr@pobox.comE<gt>
1N/A
1N/A=cut
1N/A
1N/Ause 5.006_001;
1N/Ause Carp;
1N/Ause strict;
1N/Aour($VERSION, @EXPORT, @ISA);
1N/Ause IO::Handle ();
1N/A# XXX we can't get these from IO::Handle or we'll get prototype
1N/A# mismatch warnings on C<use POSIX; use IO::File;> :-(
1N/Ause Fcntl qw(SEEK_SET SEEK_CUR SEEK_END);
1N/Arequire Exporter;
1N/A
1N/A@EXPORT = qw(SEEK_SET SEEK_CUR SEEK_END);
1N/A@ISA = qw(Exporter);
1N/A
1N/A$VERSION = "1.09";
1N/A$VERSION = eval $VERSION;
1N/A
1N/Asub seek {
1N/A @_ == 3 or croak 'usage: $io->seek(POS, WHENCE)';
1N/A seek($_[0], $_[1], $_[2]);
1N/A}
1N/A
1N/Asub sysseek {
1N/A @_ == 3 or croak 'usage: $io->sysseek(POS, WHENCE)';
1N/A sysseek($_[0], $_[1], $_[2]);
1N/A}
1N/A
1N/Asub tell {
1N/A @_ == 1 or croak 'usage: $io->tell()';
1N/A tell($_[0]);
1N/A}
1N/A
1N/A1;