IO::Moose::Seekable - Reimplementation of IO::Seekable with improvements
package My::IO; use Moose; extends 'IO::Moose::Handle'; with 'IO::Moose::Seekable'; package main; my $stdin = My::IO->new( file => \*STDIN, mode => 'r' ); print $stdin->slurp; print $stdin->tell, "\n";
This class provides an interface mostly compatible with IO::Seekable. The differences:
It is based on Moose object framework.
It uses Exception::Base for signaling errors. Most of methods are throwing exception on failure.
It doesn't export any constants. Use Fcntl instead.
extends IO::Moose::Handle
extends MooseX::GlobRef::Object
extends Moose::Object
extends IO::Seekable
extends IO::Handle
Thrown whether method is called with wrong argument.
Thrown whether fatal error is occurred by core function.
Seek the file to position pos, relative to whence:
pos is absolute position. (Seek relative to the start of the file)
pos is an offset from the current position. (Seek relative to current)
pos is an offset from the end of the file. (Seek relative to end)
The SEEK_* constants can be imported from the Fcntl module if you don't wish to use the numbers 0, 1 or 2 in your code. The SEEK_* constants are more portable.
Returns self object on success or throws an exception.
use Fcntl ':seek'; $file->seek(0, SEEK_END); $file->say("*** End of file");
Uses the system call lseek(2) directly so it can be used with sysread and syswrite methods.
Returns the new position or throws an exception.
Returns the current file position, or throws an exception on error.
Returns a value that represents the current position of the file. This method is implemented with tell method.
Goes to the position stored previously with getpos method. Returns this object on success, throws an exception on failure. This method is implemented with seek method.
$pos = $file->getpos; $file->print("something\n"); $file->setpos($pos); print $file->readline; # prints "something"
IO::Seekable, IO::Moose, IO::Moose::Handle.
The API is not stable yet and can be changed in future.
Piotr Roszatycki <dexter@cpan.org>
Copyright 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install IO::Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Moose
CPAN shell
perl -MCPAN -e shell install IO::Moose
For more information on module installation, please visit the detailed CPAN module installation guide.