IO::Moose::Seekable - Reimplementation of IO::Seekable with improvements


NAME

IO::Moose::Seekable - Reimplementation of IO::Seekable with improvements

Back to Top


SYNOPSIS

  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";

Back to Top


DESCRIPTION

This class provides an interface mostly compatible with the IO::Seekable manpage. The differences:

Back to Top


INHERITANCE

Back to Top


EXCEPTIONS

the Exception::Argument manpage

Thrown whether method is called with wrong argument.

the Exception::Fatal manpage

Thrown whether fatal error is occurred by core function.

Back to Top


METHODS

seek( pos : Int, whence : Int ) : Self

Seek the file to position pos, relative to whence:

whence=0 (SEEK_SET)

pos is absolute position. (Seek relative to the start of the file)

whence=1 (SEEK_CUR)

pos is an offset from the current position. (Seek relative to current)

whence=2 (SEEK_END)

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");
sysseek( pos : Int, whence : Int ) : Int

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.

tell() : Int

Returns the current file position, or throws an exception on error.

getpos() : Int

Returns a value that represents the current position of the file. This method is implemented with tell method.

setpos( pos : Int ) : Self

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"

Back to Top


SEE ALSO

the IO::Seekable manpage, the IO::Moose manpage, the IO::Moose::Handle manpage.

Back to Top


BUGS

The API is not stable yet and can be changed in future.

Back to Top


AUTHOR

Piotr Roszatycki <dexter@cpan.org>

Back to Top


LICENSE

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

Back to Top

 IO::Moose::Seekable - Reimplementation of IO::Seekable with improvements