File-Slurper-0.012/0000755000175000017500000000000013243105314013045 5ustar leontleontFile-Slurper-0.012/xt/0000755000175000017500000000000013243105314013500 5ustar leontleontFile-Slurper-0.012/xt/author/0000755000175000017500000000000013243105314015002 5ustar leontleontFile-Slurper-0.012/xt/author/pod-syntax.t0000644000175000017500000000025213243105314017274 0ustar leontleont#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); File-Slurper-0.012/lib/0000755000175000017500000000000013243105314013613 5ustar leontleontFile-Slurper-0.012/lib/File/0000755000175000017500000000000013243105314014472 5ustar leontleontFile-Slurper-0.012/lib/File/Slurper.pm0000644000175000017500000001410113243105314016461 0ustar leontleontpackage File::Slurper; $File::Slurper::VERSION = '0.012'; use strict; use warnings; use Carp 'croak'; use Exporter 5.57 'import'; use Encode 2.11 qw/FB_CROAK STOP_AT_PARTIAL/; use PerlIO::encoding; our @EXPORT_OK = qw/read_binary read_text read_lines write_binary write_text read_dir/; sub read_binary { my $filename = shift; # This logic is a bit ugly, but gives a significant speed boost # because slurpy readline is not optimized for non-buffered usage open my $fh, '<:unix', $filename or croak "Couldn't open $filename: $!"; if (my $size = -s $fh) { my $buf; my ($pos, $read) = 0; do { defined($read = read $fh, ${$buf}, $size - $pos, $pos) or croak "Couldn't read $filename: $!"; $pos += $read; } while ($read && $pos < $size); return ${$buf}; } else { return do { local $/; <$fh> }; } } use constant { CRLF_DEFAULT => $^O eq 'MSWin32', HAS_UTF8_STRICT => scalar do { local $@; eval { require PerlIO::utf8_strict } }, }; sub _text_layers { my ($encoding, $crlf) = @_; $crlf = CRLF_DEFAULT if $crlf && $crlf eq 'auto'; if (HAS_UTF8_STRICT && $encoding =~ /^utf-?8\b/i) { return $crlf ? ':unix:utf8_strict:crlf' : ':unix:utf8_strict'; } else { # non-ascii compatible encodings such as UTF-16 need encoding before crlf return $crlf ? ":raw:encoding($encoding):crlf" : ":raw:encoding($encoding)"; } } sub read_text { my ($filename, $encoding, $crlf) = @_; $encoding ||= 'utf-8'; my $layer = _text_layers($encoding, $crlf); local $PerlIO::encoding::fallback = STOP_AT_PARTIAL | FB_CROAK; open my $fh, "<$layer", $filename or croak "Couldn't open $filename: $!"; return do { local $/; <$fh> }; } sub write_text { my ($filename, undef, $encoding, $crlf) = @_; $encoding ||= 'utf-8'; my $layer = _text_layers($encoding, $crlf); local $PerlIO::encoding::fallback = STOP_AT_PARTIAL | FB_CROAK; open my $fh, ">$layer", $filename or croak "Couldn't open $filename: $!"; print $fh $_[1] or croak "Couldn't write to $filename: $!"; close $fh or croak "Couldn't write to $filename: $!"; return; } sub write_binary { my $filename = $_[0]; open my $fh, ">:raw", $filename or croak "Couldn't open $filename: $!"; print $fh $_[1] or croak "Couldn't write to $filename: $!"; close $fh or croak "Couldn't write to $filename: $!"; return; } sub read_lines { my ($filename, $encoding, $crlf, $skip_chomp) = @_; $encoding ||= 'utf-8'; my $layer = _text_layers($encoding, $crlf); local $PerlIO::encoding::fallback = STOP_AT_PARTIAL | FB_CROAK; open my $fh, "<$layer", $filename or croak "Couldn't open $filename: $!"; return <$fh> if $skip_chomp; my @buf = <$fh>; close $fh; chomp @buf; return @buf; } sub read_dir { my ($dirname) = @_; opendir my ($dir), $dirname or croak "Could not open $dirname: $!"; return grep { not m/ \A \.\.? \z /x } readdir $dir; } 1; # ABSTRACT: A simple, sane and efficient module to slurp a file __END__ =pod =encoding UTF-8 =head1 NAME File::Slurper - A simple, sane and efficient module to slurp a file =head1 VERSION version 0.012 =head1 SYNOPSIS use File::Slurper 'read_text'; my $content = read_text($filename); =head1 DESCRIPTION This module provides functions for fast and correct slurping and spewing. All functions are optionally exported. All functions throw exceptions on errors, write functions don't return any meaningful value. =head1 FUNCTIONS =head2 read_text($filename, $encoding, $crlf) Reads file C<$filename> into a scalar and decodes it from C<$encoding> (which defaults to UTF-8). If C<$crlf> is true, crlf translation is performed. The default for this argument is off. The special value C<'auto'> will set it to a platform specific default value. =head2 read_binary($filename) Reads file C<$filename> into a scalar without any decoding or transformation. =head2 read_lines($filename, $encoding, $crlf, $skip_chomp) Reads file C<$filename> into a list/array line-by-line, after decoding from C<$encoding>, optional crlf translation and chomping. =head2 write_text($filename, $content, $encoding, $crlf) Writes C<$content> to file C<$filename>, encoding it to C<$encoding> (which defaults to UTF-8). It can also take a C argument that works exactly as in read_text. =head2 write_binary($filename, $content) Writes C<$content> to file C<$filename> as binary data. =head2 read_dir($dirname) Open C and return all entries except C<.> and C<..>. =head1 RATIONALE This module tries to make it as easy as possible to read and write files correctly and fast. The most correct way of doing this is not always obvious (e.g. L<#83126|https://rt.cpan.org/Public/Bug/Display.html?id=83126>), and just as often the most obvious correct way is not the fastest correct way. This module hides away all such complications behind an easy intuitive interface. =head1 DEPENDENCIES This module has an optional dependency on L. Installing this will make UTF-8 encoded IO significantly faster, but should not otherwise affect the operation of this module. This may change into a dependency on the related Unicode::UTF8 in the future. =head1 SEE ALSO =over 4 =item * L A minimalistic abstraction handling not only IO but also paths. =item * L An attempt to expose as many IO related features as possible via a single API. =item * L This is a previous generation file slurping module. It has a number of issues, as described L. =item * L This was my previous attempt at a better file slurping module. It's mostly (but not entirely) a drop-in replacement for File::Slurp, which is both a feature (easy conversion) and a bug (interface issues). =back =head1 TODO =over 4 =item * C/C? =item * C? =back =head1 AUTHOR Leon Timmermans =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut File-Slurper-0.012/bench/0000755000175000017500000000000013243105314014124 5ustar leontleontFile-Slurper-0.012/bench/modules.pl0000644000175000017500000001205313243105314016132 0ustar leontleont#! /usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; use File::Slurp qw/read_file/; use File::Slurper qw/read_text read_lines read_binary/; use POSIX (); use Unicode::UTF8 'decode_utf8'; my $filename = shift or die "No argument given"; my $count = shift || 1000; my $factor = 10; my $length = -s $filename; my $compare = read_binary($filename); print "Slurping into a scalar\n"; cmpthese($count * $factor, { 'Slurp' => sub { my $content = read_file($filename, binmode => ":raw") }, 'Slurper' => sub { my $content = read_binary($filename) }, 'Traditional' => sub { open my $fh, '<', $filename or die $!; my $content = do { local $/; <$fh> } }, 'Unix' => sub { open my $fh, '<:unix', $filename or die $!; my $content = do { local $/; <$fh> } }, 'POSIX' => sub { open my $fh, '<', $filename or die $!; POSIX::read(fileno $fh, my $content, -s $fh) }, }); print "\nSlurping into an array\n"; cmpthese($count, { 'Slurp' => sub { my @lines = read_file($filename) }, 'Slurp+ref' => sub { my $lines = read_file($filename, array_ref => 1) }, 'Slurper' => sub { my @lines = read_lines($filename, 'latin1', 0, 1) }, 'Traditional' => sub { open my $fh, '<', $filename; my @lines = <$fh> }, }); print "\nSlurping into a loop\n"; cmpthese($count, { 'Slurp' => sub { for(read_file($filename)) {} }, 'Slurp+ref' => sub { for(@{ read_file($filename, array_ref => 1) }) {} }, 'Slurper' => sub { for(read_lines($filename, 'latin1', 0, 1)) {} }, 'Traditional' => sub { open my $fh, '<', $filename; while(<$fh>) {} }, }); print "\nSlurping into an array, chomped\n"; cmpthese($count, { 'Slurp' => sub { my @lines = read_file($filename, chomp => 1) }, 'Slurp+ref' => sub { my $lines = read_file($filename, array_ref => 1, chomp => 1) }, 'Slurper' => sub { my @lines = read_lines($filename, 'latin1', 0, 0) }, 'Traditional' => sub { open my $fh, '<', $filename; my @lines = <$fh>; chomp @lines }, }); print "\nSlurping crlf into a scalar\n"; cmpthese($count * $factor, { 'Slurper' => sub { my $content = read_text($filename, 'latin1', 1, 1) }, 'Slurp' => sub { my $content = read_file($filename, binmode => ':crlf') }, 'Traditional' => sub { open my $fh, '<:crlf', $filename or die $!; my $content = do { local $/; <$fh> } }, 'Smart' => sub { open my $fh, '<:crlf:perlio', $filename or die $!; my $content = do { local $/; <$fh> } }, 'Explicit' => sub { my $content = read_binary($filename); $content =~ s/\r\n/\n/g }, }); print "\nSlurping crlf into an array\n"; cmpthese($count, { 'Slurper' => sub { my @lines = read_lines($filename, 'latin1', 1, 1) }, 'Slurp' => sub { my @lines = read_file($filename, binmode => ':crlf') }, 'Traditional' => sub { open my $fh, '<:crlf', $filename; my @lines = <$fh> }, 'Explicit' => sub { my $content = read_binary($filename); $content =~ s/\r\n/\n/g; my @lines = $content =~ /(.*?\n|.+\z)/sg }, }); print "\nSlurping crlf into an array, chomped\n"; cmpthese($count, { 'Slurper' => sub { my @lines = read_lines($filename, 'latin1', 1, 0) }, 'Slurp' => sub { my @lines = read_file($filename, binmode => ':crlf', chomp => 1) }, 'Traditional' => sub { open my $fh, '<:crlf', $filename; my @lines = <$fh>; chomp @lines }, }); print "\nNote that File::Slurp (as of 9999.19) does not validate its input, falsely improving its performance\n"; print "\nSlurping utf8 into a scalar\n"; cmpthese($count, { 'Slurp' => sub { my $content = read_file($filename, binmode => ':raw:encoding(utf-8)') }, 'Slurper' => sub { my $content = read_text($filename) }, 'Traditional' => sub { open my $fh, '<:raw:encoding(utf-8)', $filename or die $!; my $content = do { local $/; <$fh> } }, 'Strict' => sub { open my $fh, '<:raw:utf8_strict', $filename or die $!; my $content = do { local $/; <$fh> } }, 'Explicit' => sub { my $content = read_binary($filename); utf8::decode($content); }, 'Explicit2' => sub { my $content = read_binary($filename); decode_utf8($content); }, }); print "\nSlurping utf8 into an array\n"; cmpthese($count, { 'Slurp' => sub { my @lines = read_file($filename, binmode => ':raw:encoding(utf-8)') }, 'Slurp+ref' => sub { my $lines = read_file($filename, array_ref => 1, binmode => ':raw:encoding(utf-8)') }, 'Slurper' => sub { my @lines = read_lines($filename, 'utf-8', 0, 1) }, 'Traditional' => sub { open my $fh, '<:raw:encoding(utf-8)', $filename; my @lines = <$fh> }, 'Strict' => sub { open my $fh, '<:unix:utf8_strict', $filename; my @lines = <$fh> }, 'Explicit' => sub { my @lines = map { utf8::decode($_); $_ } read_lines($filename, 'latin1', 0, 1) }, }); print "\nSlurping utf8 into an array, chomped\n"; cmpthese($count, { 'Slurp' => sub { my @lines = read_file($filename, chomp => 1, binmode => ':raw:encoding(utf-8)') }, 'Slurper' => sub { my @lines = read_lines($filename, 'utf-8', 0, 0) }, 'Traditional' => sub { open my $fh, '<:raw:encoding(utf-8)', $filename; my @lines = <$fh>; chomp @lines }, 'Strict' => sub { open my $fh, '<:unix:utf8_strict', $filename; my @lines = <$fh>; chomp @lines }, }); File-Slurper-0.012/bench/layers.pl0000644000175000017500000001000113243105314015750 0ustar leontleont#! /usr/bin/env perl use 5.010; use strict; use warnings; use Benchmark 'cmpthese', ':hireswallclock'; sub read_text { my ($filename, $layers) = @_; open my $fh, "<$layers", $filename or die "Can't open $filename:#!"; my $foo = do { local $/; <$fh> }; return; } sub read_lines { my ($filename, $layers) = @_; open my $fh, "<$layers", $filename or die "Can't open $filename:#!"; my @foo = <$fh>; return; } my $filename = shift // 'test.txt'; my $count = shift // 200; my $encoding = shift // 'utf-8'; say "Read utf8 encoded Unix text file, decode with :encoding\n"; cmpthese($count, { ':encoding' => sub { read_text($filename, ':encoding(utf-8-strict)') }, ':encoding:perlio' => sub { read_text($filename, ':encoding(utf-8-strict):perlio') }, }); say "\nRead utf8 encoded Unix text file into lines, decode with :encoding\n"; cmpthese($count, { ':encoding' => sub { read_lines($filename, ':encoding(utf-8-strict)') }, ':encoding:perlio' => sub { read_lines($filename, ':encoding(utf-8-strict):perlio') }, }); say "Read utf8 encoded Windows text file, decode with :encoding\n"; cmpthese($count, { 'c:e' => sub { read_text($filename, ":crlf:encoding(utf-8-strict)") }, 'c:p:e' => sub { read_text($filename, ":crlf:perlio:encoding(utf-8-strict)") }, 'u:c:e' => sub { read_text($filename, ":unix:crlf:encoding(utf-8-strict)") }, 'u:c:p:e' => sub { read_text($filename, ":unix:crlf:perlio:encoding(utf-8-strict)") }, 'u:c:e:p' => sub { read_text($filename, ":unix:crlf:encoding(utf-8-strict):perlio") }, 'u:c:p:e:p' => sub { read_text($filename, ":unix:crlf:perlio:encoding(utf-8-strict):perlio") }, 'c:p:e:p' => sub { read_text($filename, ":crlf:perlio:encoding(utf-8-strict):perlio") }, 'e:c' => sub { read_text($filename, ":raw:encoding(utf-8-strict):crlf") }, 'e:c:p' => sub { read_text($filename, ":raw:encoding(utf-8-strict):crlf:perlio") }, 'e:p:c:p' => sub { read_text($filename, ":raw:encoding(utf-8-strict):perlio:crlf:perlio") }, }); say "\nRead utf8 encoded text file, decode with :utf8_strict\n"; cmpthese($count * 10, { ':utf8_strict' => sub { read_text($filename, ":utf8_strict") }, ':unix:utf8_strict' => sub { read_text($filename, ":unix:utf8_strict") }, ':unix:utf8_strict:perlio' => sub { read_text($filename, ":unix:utf8_strict:perlio") }, }); say "\nRead utf8 encoded text file with optional crlf line endings, decode with :utf8_strict\n"; cmpthese($count * 10, { ':crlf:utf8_strict' => sub { read_text($filename, ":crlf:utf8_strict") }, ':utf8_strict:crlf' => sub { read_text($filename, ":utf8_strict:crlf") }, ':utf8_strict:crlf:perlio' => sub { read_text($filename, ":utf8_strict:crlf:perlio") }, ':utf8_strict:perlio' => sub { read_text($filename, ":utf8_strict:perlio") }, ':utf8_strict' => sub { read_text($filename, ":utf8_strict") }, }); say "\nRead lines of utf8 encoded text file with optional crlf line endings, decode with :utf8_strict\n"; cmpthese($count * 10, { ':crlf:utf8_strict' => sub { read_lines($filename, ":crlf:utf8_strict") }, ':utf8_strict:crlf' => sub { read_lines($filename, ":utf8_strict:crlf") }, ':utf8_strict:crlf:perlio' => sub { read_lines($filename, ":utf8_strict:crlf:perlio") }, ':utf8_strict:perlio' => sub { read_lines($filename, ":utf8_strict:perlio") }, ':utf8_strict' => sub { read_lines($filename, ":utf8_strict") }, }); say "\nRead text file doing crlf translation\n"; cmpthese($count * 10, { ':unix:crlf' => sub { read_text($filename, ":unix:crlf") }, ':unix:crlf:perlio' => sub { read_text($filename, ":unix:crlf:perlio") }, # ':unix' => sub { read_text($filename, ":unix") }, # ':raw' => sub { read_text($filename, ":raw") }, }); say "\nRead text file into lines doing crlf translation\n"; cmpthese($count * 10, { ':unix:crlf' => sub { read_lines($filename, ":unix:crlf") }, ':unix:crlf:perlio' => sub { read_lines($filename, ":unix:crlf:perlio") }, # ':raw' => sub { read_lines($filename, ":raw") }, }); File-Slurper-0.012/bench/logic.pl0000644000175000017500000000464513243105314015567 0ustar leontleont#! /usr/bin/env perl use strict; use warnings; use Carp 'croak'; use File::Slurp 'read_file'; use File::Slurper 'read_binary'; use Benchmark 'cmpthese'; my $filename = shift or die "No argument given"; my $count = shift || -0.5; sub read_complicated { my $filename = shift; my $buf; open my $fh, '<:unix', $filename or croak "Couldn't open $filename: $!"; my $size = -s $fh; my ($pos, $read) = 0; do { defined($read = read $fh, $buf, $size - $pos, $pos) or croak "Couldn't read $filename: $!"; $pos += $read; } while ($read && $pos < $size); return $buf; } sub read_complicated_ref { my $filename = shift; my $buf = shift; open my $fh, '<:unix', $filename or croak "Couldn't open $filename: $!"; my $size = -s $fh; my ($pos, $read) = 0; do { defined($read = read $fh, ${$buf}, $size - $pos, $pos) or croak "Couldn't read $filename: $!"; $pos += $read; } while ($read && $pos < $size); return ${$buf}; } sub read_simple { my $filename = shift; open my $fh, '<:unix', $filename or croak "Couldn't open $filename: $!"; return do { local $/; <$fh> }; } sub read_naive { my $filename = shift; open my $fh, '<:raw', $filename or croak "Couldn't open $filename: $!"; return do { local $/; <$fh> }; } sub read_sysread { my $filename = shift; my $buf; open my $fh, '<:unix', $filename or croak "Couldn't open $filename: $!"; my $size = -s $fh; my ($pos, $read) = 0; do { defined($read = sysread $fh, $buf, $size - $pos, $pos) or croak "Couldn't read $filename: $!"; $pos += $read; } while ($read && $pos < $size); return $buf; } cmpthese($count, { complicated => sub { read_complicated($filename) }, ref => sub { read_complicated_ref($filename, \my $content) }, simple => sub { read_simple($filename) }, naive => sub { read_naive($filename) }, sysread => sub { read_sysread($filename) }, slurp => sub { read_file($filename, binmode => ':raw') }, slurper => sub { read_binary($filename) }, }); cmpthese($count, { complicated => sub { my $content = read_complicated($filename) }, simple => sub { my $content = read_simple($filename) }, naive => sub { my $content = read_naive($filename) }, sysread => sub { my $content = read_sysread($filename) }, ref => sub { read_complicated_ref($filename, \my $content) }, slurp => sub { my $content = read_file($filename, binmode => ':raw') }, slurper => sub { my $content = read_binary($filename) }, }); File-Slurper-0.012/t/0000755000175000017500000000000013243105314013310 5ustar leontleontFile-Slurper-0.012/t/20-no-side-effects.t0000755000175000017500000000066713243105314016703 0ustar leontleont#! perl use strict; use warnings; use Test::More; use Test::Warnings; use File::Slurper 'read_text'; use File::Spec::Functions 'catfile'; use FindBin '$RealBin'; use File::Temp 'tempfile'; my $inputfile = catfile( $RealBin, 'data', 'cp1252.txt' ); my $s = read_text( $inputfile, 'cp1252' ); my ( $outfh, $outputfile ) = tempfile(); binmode $outfh, ':encoding(utf8)'; print $outfh "Snowman! \x{2603}\n"; close $outfh; done_testing; File-Slurper-0.012/t/data/0000755000175000017500000000000013243105314014221 5ustar leontleontFile-Slurper-0.012/t/data/cp1252.txt0000644000175000017500000000346713243105314015710 0ustar leontleontlatin1 test paragraph: ~ 0x21 ! 0x22 " 0x23 # 0x24 $ 0x25 % 0x26 & 0x27 ' 0x28 ( 0x29 ) 0x2a * 0x2b + 0x2c , 0x2d - 0x2e . 0x2f / 0x30 0 0x31 1 0x32 2 0x33 3 0x34 4 0x35 5 0x36 6 0x37 7 0x38 8 0x39 9 0x3a : 0x3b ; 0x3c < 0x3d = 0x3e > 0x3f ? 0x40 @ 0x41 A 0x42 B 0x43 C 0x44 D 0x45 E 0x46 F 0x47 G 0x48 H 0x4a J 0x4b K 0x4c L 0x4d M 0x4e N 0x4f O 0x50 P 0x51 Q 0x52 R 0x53 S 0x54 T 0x55 U 0x56 V 0x57 W 0x58 X 0x59 Y 0x5a Z 0x5b [ 0x5c \ 0x5d ] 0x5e ^ 0x5f _ 0x60 ` 0x61 a 0x62 b 0x63 c 0x64 d 0x65 e 0x66 f 0x67 g 0x68 h 0x69 i 0x6a j 0x6b k 0x6c l 0x6d m 0x6e n 0x6f o 0x70 p 0x71 q 0x72 r 0x73 s 0x74 t 0x75 u 0x76 v 0x77 w 0x78 x 0x79 y 0x7a z 0x7b { 0x7c | 0x7d } 0x7e ~ 0xa0 � 0xa1 � 0xa2 � 0xa3 � 0xa4 � 0xa5 � 0xa6 � 0xa7 � 0xa8 � 0xa9 � 0xaa � 0xab � 0xac � 0xae � 0xaf � 0xb0 � 0xb1 � 0xb2 � 0xb3 � 0xb4 � 0xb5 � 0xb6 � 0xb7 � 0xb8 � 0xb9 � 0xba � 0xbb � 0xbc � 0xbd � 0xbe � 0xbf � 0xc0 � 0xc1 � 0xc2 � 0xc3 � 0xc4 � 0xc5 � 0xc6 � 0xc7 � 0xc8 � 0xc9 � 0xca � 0xcb � 0xcc � 0xcd � 0xce � 0xcf � 0xd0 � 0xd1 � 0xd2 � 0xd3 � 0xd4 � 0xd5 � 0xd6 � 0xd7 � 0xd8 � 0xd9 � 0xda � 0xdb � 0xdc � 0xdd � 0xde � 0xdf � 0xe0 � 0xe1 � 0xe2 � 0xe3 � 0xe4 � 0xe5 � 0xe6 � 0xe7 � 0xe8 � 0xe9 � 0xea � 0xeb � 0xec � 0xed � 0xee � 0xef � 0xf0 � 0xf1 � 0xf2 � 0xf3 � 0xf4 � 0xf5 � 0xf6 � 0xf7 � 0xf8 � 0xf9 � 0xfa � 0xfb � 0xfc � 0xfd � 0xfe � 0xff � ~ cp1252 test paragraph: ~ 0x80 � 0x82 � 0x83 � 0x84 � 0x85 � 0x86 � 0x87 � 0x88 � 0x89 � 0x8a � 0x8b � 0x8c � 0x8e � 0x91 � 0x92 � 0x93 � 0x94 � 0x95 � 0x96 � 0x97 � 0x98 � 0x99 � 0x9a � 0x9b � 0x9c � 0x9e � 0x9f � ~ File-Slurper-0.012/t/10-basics.t0000644000175000017500000000162313243105314015161 0ustar leontleont#! perl use strict; use warnings; use File::Spec::Functions qw/catfile/; use File::Slurper qw/read_text read_binary read_lines write_text read_dir/; use File::Temp 'tempfile'; use Test::More; my $content = do { local $/; open my $fh, '<:raw', $0; <$fh> }; is(read_text($0), $content, 'read_file() works'); is(read_binary($0), $content, 'read_binary() works'); my @content = split /(?<=\n)/, $content; is_deeply([ read_lines($0, 'utf-8', 0, 1) ], \@content, 'read_lines returns the right thing (no chomp)'); chomp @content; is_deeply([ read_lines($0) ], \@content, 'read_lines returns the right thing (chomp)'); is_deeply([ read_dir('lib') ], [ 'File' ], 'read_dir appears to work'); my ($fh, $filename) = tempfile(UNLINK => 1); ok(eval { write_text($filename, $content); 1 }, 'File has been written') or diag "Error: $@"; is(read_text($filename), $content, 'New file has correct content'); done_testing; File-Slurper-0.012/Makefile.PL0000644000175000017500000000274513243105314015027 0ustar leontleont# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.010. use strict; use warnings; use 5.008; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "A simple, sane and efficient module to slurp a file", "AUTHOR" => "Leon Timmermans ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "File-Slurper", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008", "NAME" => "File::Slurper", "PREREQ_PM" => { "Carp" => 0, "Encode" => "2.11", "Exporter" => "5.57", "PerlIO::encoding" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec::Functions" => 0, "File::Temp" => 0, "FindBin" => 0, "Test::More" => 0, "Test::Warnings" => 0 }, "VERSION" => "0.012", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Encode" => "2.11", "Exporter" => "5.57", "File::Spec::Functions" => 0, "File::Temp" => 0, "FindBin" => 0, "PerlIO::encoding" => 0, "Test::More" => 0, "Test::Warnings" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); File-Slurper-0.012/META.json0000644000175000017500000000433213243105314014470 0ustar leontleont{ "abstract" : "A simple, sane and efficient module to slurp a file", "author" : [ "Leon Timmermans " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "File-Slurper", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "perl" : "5.008" }, "suggests" : { "JSON::PP" : "2.27300" } }, "develop" : { "requires" : { "Test::More" : "0", "Test::Pod" : "1.41" } }, "runtime" : { "recommends" : { "PerlIO::utf8_strict" : "0" }, "requires" : { "Carp" : "0", "Encode" : "2.11", "Exporter" : "5.57", "PerlIO::encoding" : "0", "constant" : "0", "perl" : "5.008", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec::Functions" : "0", "File::Temp" : "0", "FindBin" : "0", "Test::More" : "0", "Test::Warnings" : "0", "perl" : "5.008" } } }, "provides" : { "File::Slurper" : { "file" : "lib/File/Slurper.pm", "version" : "0.012" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-file-slurper at rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=File-Slurper" }, "repository" : { "type" : "git", "url" : "git://github.com/Leont/file-slurp-sane.git", "web" : "https://github.com/Leont/file-slurp-sane" } }, "version" : "0.012", "x_contributors" : [ "Jim Davis ", "Leon Timmermans ", "Olivier Mengu\u00e9 ", "Philipp Gortan " ], "x_serialization_backend" : "Cpanel::JSON::XS version 3.0215" } File-Slurper-0.012/MANIFEST0000644000175000017500000000046313243105314014201 0ustar leontleont# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.010. Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README bench/layers.pl bench/logic.pl bench/modules.pl dist.ini lib/File/Slurper.pm t/10-basics.t t/20-no-side-effects.t t/data/cp1252.txt xt/author/pod-syntax.t File-Slurper-0.012/META.yml0000644000175000017500000000224513243105314014321 0ustar leontleont--- abstract: 'A simple, sane and efficient module to slurp a file' author: - 'Leon Timmermans ' build_requires: File::Spec::Functions: '0' File::Temp: '0' FindBin: '0' Test::More: '0' Test::Warnings: '0' perl: '5.008' configure_requires: ExtUtils::MakeMaker: '0' perl: '5.008' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: File-Slurper provides: File::Slurper: file: lib/File/Slurper.pm version: '0.012' recommends: PerlIO::utf8_strict: '0' requires: Carp: '0' Encode: '2.11' Exporter: '5.57' PerlIO::encoding: '0' constant: '0' perl: '5.008' strict: '0' warnings: '0' resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=File-Slurper repository: git://github.com/Leont/file-slurp-sane.git version: '0.012' x_contributors: - 'Jim Davis ' - 'Leon Timmermans ' - 'Olivier Mengué ' - 'Philipp Gortan ' x_serialization_backend: 'YAML::Tiny version 1.69' File-Slurper-0.012/dist.ini0000644000175000017500000000124613243105314014514 0ustar leontleontname = File-Slurper author = Leon Timmermans license = Perl_5 copyright_holder = Leon Timmermans copyright_year = 2014 [Git::GatherDir] [PruneCruft] [MetaYAML] [MetaJSON] [Readme] [Manifest] [License] [AutoPrereqs] [Repository] [Bugtracker] [MetaProvides::Package] [NextRelease] [Git::Contributors] [MinimumPerl] [MakeMaker] [Git::NextVersion] [@Git] [CheckChangesHasContent] [RunExtraTests] [TestRelease] [ConfirmRelease] [UploadToCPAN] [PodWeaver] [PkgVersion] [PodSyntaxTests] [InstallGuide] [RemovePrereqs] remove = PerlIO::utf8_strict [Prereqs / RuntimeRecommends] PerlIO::utf8_strict = 0 [Encoding] encoding=cp1252 filenames=t/data/cp1252.txt File-Slurper-0.012/INSTALL0000644000175000017500000000167113243105314014103 0ustar leontleontThis is the Perl distribution File-Slurper. Installing File-Slurper is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm File::Slurper If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S File::Slurper ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan File::Slurper ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation File-Slurper documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc File::Slurper File-Slurper-0.012/LICENSE0000644000175000017500000004366613243105314014071 0ustar leontleontThis software is copyright (c) 2014 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014 by Leon Timmermans. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by Leon Timmermans. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End File-Slurper-0.012/Changes0000644000175000017500000000320313243105314014336 0ustar leontleontRevision history for File-Slurper 0.012 2018-02-20 21:53:30+01:00 Europe/Amsterdam Depend on Encode 2.11 for STOP_AT_PARTIAL 0.011 2017-12-18 21:23:24+01:00 Europe/Amsterdam Correctly set value of $PerlIO::encoding::fallback Don't skip latin-1 checking 0.010 2017-09-17 22:09:05+02:00 Europe/Amsterdam Recognize "latin-1" as iso-8859-1 0.009 2016-08-05 18:26:58+02:00 Europe/Amsterdam Load PerlIO::encoding before localizing $PerlIO::encoding::fallback 0.008 2015-08-31 12:43:05+02:00 Europe/Amsterdam Impose scalar context on do/eval/require 0.007 2015-08-23 09:52:45+02:00 Europe/Amsterdam Added more items to a SEE ALSO Fixed up benchmarks 0.006 2015-07-02 02:02:00+02:00 Europe/Amsterdam Unmark experimental status Always croak on encoding error 0.005 2015-04-18 21:56:35+02:00 Europe/Amsterdam Get rid of singular named options 0.004 2015-02-06 17:08:01+01:00 Europe/Amsterdam Work around PerlIO encoding bug Add Rationale and Dependency sections to documentation 0.003 2015-02-05 20:42:26+01:00 Europe/Amsterdam Implement writer functions Default to crlf=off, add auto option for old behavior Make PerlIO::utf8_strict an optional dependency 0.002 2014-10-21 19:03:44+02:00 Europe/Amsterdam rename File::Slurp::Sane to File::Slurper Accept UTF-8 as encoding case-insensitively Fix performance issue on 5.20.0 0.001 2014-05-24 18:16:48CEST+0200 Europe/Amsterdam Initial release to an unsuspecting world File-Slurper-0.012/README0000644000175000017500000000060713243105314013730 0ustar leontleont This archive contains the distribution File-Slurper, version 0.012: A simple, sane and efficient module to slurp a file This software is copyright (c) 2014 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.010.