IO::Moose::Seekable(3)

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

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

DESCRIPTION
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.

INHERITANCE

•   extends IO::Moose::Handle

    •   extends MooseX::GlobRef::Object

        •   extends Moose::Object

•   extends IO::Seekable

    •   extends IO::Handle

EXCEPTIONS

Exception::Argument
    Thrown whether method is called with wrong argument.

Exception::Fatal
    Thrown whether fatal error is occurred by core function.

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"

SEE ALSO
IO::Seekable, IO::Moose, IO::Moose::Handle.

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

AUTHOR
Piotr Roszatycki <dexter@cpan.org>

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>