use File::Copy ();
use IO::File ();
use File::Spec::Unix;
+use PerlIO::utf8_strict;
use namespace::clean -except => 'meta';
has filename => (is => 'rw');
my ($self, $layer) = @_;
my $fh = $self->fh;
- $layer = ":encoding(UTF-8)" if !$layer && $self->is_utf8_encoded;
+ $layer = ':utf8_strict' if !$layer && $self->is_utf8_encoded;
$layer = ':raw' unless $layer;
binmode($fh, $layer);
$layer = ':raw';
}
- my $content = undef;
+ my $content = '';
my $handle = $self->fh;
binmode( $handle, $layer );
$handle->seek(0, IO::File::SEEK_SET);
- while ( $handle->sysread( my $buffer, 8192 ) ) {
- $content .= $buffer;
+
+ if ($layer eq ':raw') {
+ while ( $handle->sysread( my $buffer, 8192 ) ) {
+ $content .= $buffer;
+ }
+ }
+ else {
+ $content = do { local $/; $handle->getline };
}
$handle->seek(0, IO::File::SEEK_SET);
my ( $self, $layer ) = @_;
my $handle = $self->decoded_fh($layer);
- my $content = undef;
$handle->seek(0, IO::File::SEEK_SET);
- while ( $handle->sysread( my $buffer, 8192 ) ) {
- $content .= $buffer;
- }
+
+ my $content = do { local $/; $handle->getline };
$handle->seek(0, IO::File::SEEK_SET);
return $content;