
package PeekHandle;

sub new {
  my $class = shift;
  my $filename = shift;
  my $fh = \do{local *FH};
  open $fh, $filename or return;
  bless $fh => $class;
}

sub peek {
  my $self = shift;
  my $n = shift;
  my $upcoming;
  my $pos = tell $self;
  if (defined $n)  {
    read $self, $upcoming, $n;
    #  print "Peeker on $self sees ($nextline)\n";
  } else {
    $upcoming = <$self>;
  }
  seek $self, $pos, 0;
  $upcoming;
}

1;

