App-PTP

 view release on metacpan or  search on metacpan

lib/App/PTP/Files.pm  view on Meta::CPAN

    if ($options->{debug_mode}) {
      print "All output is going to: $options->{output}\n";
    }
    my $mode = $options->{append} ? '>>' : '>';
    open($global_output_fh, "${mode}:encoding($options->{output_encoding})", $options->{output})
        or die "Cannot open output file '$options->{output}': $!.\n";
  } elsif (not $options->{in_place}) {
    print "All output is going to STDOUT.\n" if $options->{debug_mode};
    $global_output_fh = $stdout;
  }
  # We're setting the correct binmode for STDOUT here, because it can be used
  # when in_place is true, but also if the --tee command is used.
  binmode($stdout, ":encoding($options->{output_encoding})");
}

sub close_global_output {
  my ($options) = @_;
  if ($options->{output}) {
    close $global_output_fh
        or die "Cannot close output file '$options->{output}': $!.\n";
  }
}

lib/App/PTP/Files.pm  view on Meta::CPAN

  my @data = read_handle($fh, $options);
  close($fh) or die "Cannot close the file '$path': $!.\n";
  return @data;
}

# read_stdin()
# Applies the correct read option to STDIN and calls read_handle(STDIN).
sub read_stdin {
  my ($options, $stdin) = @_;
  print "Reading STDIN\n" if $options->{debug_mode};
  binmode($stdin, ":encoding($options->{input_encoding})");
  return read_handle($stdin, $options);
}

# read_input($input, $options, \*STDIN)
# Checks whether the input is the $stdin_marker or a file name and calls the
# matching method to read it, the third argument is the file-handle to read
# when $input is the $stdin_marker (usually STDIN except in tests).
sub read_input {
  my ($input, $options, $stdin) = @_;
  if (ref($input)) {

t/lib/AppPtpTest.pm  view on Meta::CPAN


# If there is the relative 'lib' directory in the input, we're fixing it to an
# absolute path, so that "use" at run-time inside the Safe will still work.
@INC = map { rel2abs($_) } @INC;

our @EXPORT = qw(ptp slurp slurp_and_close);

sub slurp_and_close {
  my ($fh) = @_;
  seek $fh, 0, Fcntl::SEEK_SET;
  binmode $fh;
  local $/; # enable slurp mode;
  my $str = <$fh>;
  close $fh;
  return $str;
}

sub slurp {
  my ($file) = @_;
  open my $fh, '<:bytes', $file;
  local $/; # enable slurp mode;



( run in 0.900 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )