The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

package Rex::Interface::File::Local;

use strict;
use warnings;

our $VERSION = '1.1.0'; # VERSION

use Rex::Interface::File::Base;
use base qw(Rex::Interface::File::Base);

sub new {
  my $that  = shift;
  my $proto = ref($that) || $that;
  my $self  = $proto->SUPER::new(@_);

  bless( $self, $proto );

  return $self;
}

sub open {
  my ( $self, $mode, $file ) = @_;

  Rex::Logger::debug("Opening $file with mode: $mode");

  open( $self->{fh}, $mode, $file ) or return;

  return 1;
}

sub read {
  my ( $self, $len ) = @_;

  my $buf;
  read( $self->{fh}, $buf, $len );
  return $buf;
}

sub write {
  my ( $self, $buf ) = @_;

  my $fh = $self->{fh};
  print $fh $buf;
}

sub seek {
  my ( $self, $pos ) = @_;

  my $fh = $self->{fh};
  seek( $fh, $pos, 0 );
}

sub close {
  my ($self) = @_;

  my $fh = $self->{fh};
  close $fh if $fh;
  $self->{fh} = undef;
  $self = undef;
}

1;