r64317 - in /branches/upstream/libfile-slurp-unicode-perl: ./ current/ current/lib/ current/lib/File/ current/lib/File/Slurp/ current/t/
danai at users.alioth.debian.org
danai at users.alioth.debian.org
Thu Oct 28 05:49:04 UTC 2010
Author: danai
Date: Thu Oct 28 05:48:48 2010
New Revision: 64317
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=64317
Log:
[svn-inject] Installing original source of libfile-slurp-unicode-perl (0.7.1)
Added:
branches/upstream/libfile-slurp-unicode-perl/
branches/upstream/libfile-slurp-unicode-perl/current/
branches/upstream/libfile-slurp-unicode-perl/current/Build.PL
branches/upstream/libfile-slurp-unicode-perl/current/Changes
branches/upstream/libfile-slurp-unicode-perl/current/MANIFEST
branches/upstream/libfile-slurp-unicode-perl/current/META.yml
branches/upstream/libfile-slurp-unicode-perl/current/README
branches/upstream/libfile-slurp-unicode-perl/current/lib/
branches/upstream/libfile-slurp-unicode-perl/current/lib/File/
branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/
branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/Unicode.pm
branches/upstream/libfile-slurp-unicode-perl/current/t/
branches/upstream/libfile-slurp-unicode-perl/current/t/00_basic.t
branches/upstream/libfile-slurp-unicode-perl/current/t/10_read_file.t
branches/upstream/libfile-slurp-unicode-perl/current/t/20_write_file.t
branches/upstream/libfile-slurp-unicode-perl/current/t/30_unicode.t
Added: branches/upstream/libfile-slurp-unicode-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/Build.PL?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/Build.PL (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/Build.PL Thu Oct 28 05:48:48 2010
@@ -1,0 +1,9 @@
+use Module::Build;
+Module::Build->new(
+ module_name => 'File::Slurp::Unicode',
+ license => 'perl',
+ dist_author => 'David Caldwell <david at porkrind.org>',
+ requires => { perl => '5.10.0',
+ 'File::Slurp' => 0,
+ },
+)->create_build_script;
Added: branches/upstream/libfile-slurp-unicode-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/Changes?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/Changes (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/Changes Thu Oct 28 05:48:48 2010
@@ -1,0 +1,12 @@
+File::Slurp::Unicode (0.7.1)
+
+ * Added File::Slurp to dependencies. Not a core module after all. :-(
+
+ -- David Caldwell <david at porkrind.org> Sun, 11 Apr 2010 17:06:28 -0700
+
+File::Slurp::Unicode (0.7.0)
+
+ * First release to CPAN
+
+ -- David Caldwell <david at porkrind.org> Sat, 10 Apr 2010 16:34:35 -0700
+
Added: branches/upstream/libfile-slurp-unicode-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/MANIFEST?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/MANIFEST (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/MANIFEST Thu Oct 28 05:48:48 2010
@@ -1,0 +1,10 @@
+Build.PL
+Changes
+lib/File/Slurp/Unicode.pm
+MANIFEST This list of files
+README
+t/00_basic.t
+t/10_read_file.t
+t/20_write_file.t
+t/30_unicode.t
+META.yml
Added: branches/upstream/libfile-slurp-unicode-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/META.yml?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/META.yml (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/META.yml Thu Oct 28 05:48:48 2010
@@ -1,0 +1,20 @@
+---
+name: File-Slurp-Unicode
+version: 0.7.1
+author:
+ - 'David Caldwell <david at porkrind.org>'
+abstract: Reading/Writing of Complete Files with Character Encoding Support
+license: perl
+resources:
+ license: http://dev.perl.org/licenses/
+requires:
+ File::Slurp: 0
+ perl: 5.10.0
+provides:
+ File::Slurp::Unicode:
+ file: lib/File/Slurp/Unicode.pm
+ version: 0.7.1
+generated_by: Module::Build version 0.280801
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.2.html
+ version: 1.2
Added: branches/upstream/libfile-slurp-unicode-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/README?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/README (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/README Thu Oct 28 05:48:48 2010
@@ -1,0 +1,28 @@
+File::Slurp::Unicode
+--------------------
+
+This module wraps the standard File::Slurp package and adds character
+encoding support.
+
+For full documentation, run:
+ perldoc lib/File/Slurp/Unicode.pm
+
+
+Installation
+------------
+
+To build, test and install:
+
+ perl Build.PL
+ ./Build
+ ./Build test
+ ./Build install
+
+
+License
+-------
+
+Copyright 2010 David Caldwell <david at porkrind.org>
+
+This perl module is free software; it may be redistributed
+and/or modified under the same terms as Perl itself.
Added: branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/Unicode.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/Unicode.pm?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/Unicode.pm (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/lib/File/Slurp/Unicode.pm Thu Oct 28 05:48:48 2010
@@ -1,0 +1,164 @@
+# Copyright (c) 2010 David Caldwell, All Rights Reserved. -*- cperl -*-
+
+package File::Slurp::Unicode; use strict; use warnings;
+
+our $VERSION = '0.7.1';
+
+use base 'Exporter' ;
+our %EXPORT_TAGS = ( 'all' => [ qw( read_file write_file append_file read_dir ) ] ) ;
+our @EXPORT = ( @{ $EXPORT_TAGS{'all'} } );
+our @EXPORT_OK = qw( slurp ) ;
+
+*slurp = \&read_file ;
+
+use File::Slurp ();
+use Encode;
+use Carp;
+
+sub read_file {
+ my ($file_name, %args) = @_ ;
+
+ my $binary = ($args{encoding}||'') eq 'binary';
+ my $decode = sub {
+ map { $binary ? $_ : decode($args{encoding} // 'utf8', $_) } @_;
+ };
+
+ if ($args{array_ref}) {
+ my $r = File::Slurp::read_file($file_name, %args);
+ return [ $decode->(@$r)];
+ } elsif ($args{scalar_ref}) {
+ my $r = File::Slurp::read_file($file_name, %args);
+ return \($decode->($$r))[0];
+ } elsif (wantarray) {
+ my @r = File::Slurp::read_file($file_name, %args);
+ return $decode->(@r);
+ } elsif (defined wantarray) { # scalar context
+ my $r = File::Slurp::read_file($file_name, %args);
+ return ($decode->($r))[0];
+ } elsif ($args{buf_ref}) {
+ File::Slurp::read_file($file_name, %args);
+ ${$args{buf_ref}} = ($decode->(${$args{buf_ref}}))[0];
+ return; # void context
+ }
+ croak "What on earth did you do to get here?";
+}
+
+sub write_file {
+ my $file_name = shift ;
+ my $args = ( ref $_[0] eq 'HASH' ) ? shift : {} ;
+
+ my $binary = ($args->{encoding}||'') eq 'binary';
+ my $encode = sub {
+ map { !utf8::is_utf8($_) ? $_ :
+ $binary ? croak "Can't encode wide characters as binary"
+ : encode($args->{encoding} // 'utf8', $_)
+ } @_
+ };
+
+ my @data;
+ if ($args->{buf_ref}) {
+ @data = $encode->(${$args->{buf_ref}});
+ } elsif (ref $_[0] eq 'SCALAR') {
+ @data = $encode->(${$_[0]});
+ } elsif (ref $_[0] eq 'ARRAY') {
+ @data = $encode->(@{$_[0]});
+ } else {
+ @data = $encode->(@_);
+ }
+
+ File::Slurp::write_file($file_name, $args, @data);
+}
+
+sub append_file {
+ my $file_name = shift ;
+ my $args = ( ref $_[0] eq 'HASH' ) ? shift : {} ;
+ $args->{append} = 1;
+ write_file($file_name, $args, @_);
+}
+
+*read_dir = \&File::Slurp::read_dir;
+
+1;
+
+__END__
+
+=head1 NAME
+
+File::Slurp::Unicode - Reading/Writing of Complete Files with Character Encoding Support
+
+=head1 SYNOPSIS
+
+ use File::Slurp::Unicode;
+
+ my $text = read_file('filename', encoding => 'utf8');
+ my @lines = read_file('filename'); # utf8 is assumed if no encoding.
+
+ write_file('filename', { encoding => 'utf16' }, @lines);
+
+ # same as File::Slurp::write_file (ie. no encoding):
+ write_file('filename', { encoding => 'binary' }, @lines);
+
+ use File::Slurp::Unicode qw(slurp);
+
+ my $text = slurp('filename', encoding => 'latin1');
+
+=head1 DESCRIPTION
+
+This module wraps L<File::Slurp> and adds character encoding support through
+the B<< C<encoding> >> parameter. It exports the same functions which take
+all the same parameters as File::Slurp. Please see the L<File::Slurp>
+documentation for basic usage; only the differences are described from here
+on out.
+
+=head2 B<read_file>
+
+Pass in an argument called B<< C<encoding> >> to change the file
+encoding. If no argument is passed in, UTF-8 encoding is assumed.
+
+The special encoding B<'binary'> is interpreted to mean that there should
+be no decoding done to the data after reading it. This is pretty much the
+same as calling C<File::Slurp::read_file()> directly. This option is here
+only to make code which needs to read both binary and text files look
+uniform.
+
+=head2 B<write_file>
+
+Pass in an argument called B<< C<encoding> >> to change the file
+encoding. If no argument is passed in and no wide characters are present in
+the output data, then no conversion will be done. If there are wide
+characters in the output data then UTF-8 encoding is assumed.
+
+The special encoding B<'binary'> is interpreted to mean that there should
+be no encoding done to the data before writing. If you pass a wide string (a
+string with Perl's internal 'utf8 bit' set) to C<write_file> and set the
+encoding to 'binary' it will die with an appropriate message. This is pretty
+much the same as calling C<File::Slurp::write_file()> directly. This option
+is here only to make code which needs write both binary and text files look
+uniform.
+
+=head1 SEE ALSO
+
+L<File::Slurp>
+
+=head1 BUGS
+
+None known. Contact author or file a bug report on CPAN if you find any.
+
+=head1 COPYRIGHT
+
+This library is free software; you can redistribute it and/or
+modify it under the same terms as Perl itself.
+
+Copyright (C) 2010 David Caldwell
+
+=head1 AUTHOR
+
+David Caldwell E<lt>david at porkrind.orgE<gt>
+
+L<http://porkrind.org/>
+
+=head1 PROJECT HOME
+
+L<http://github.com/caldwell/File-Slurp-Unicode>
+
+=cut
Added: branches/upstream/libfile-slurp-unicode-perl/current/t/00_basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/t/00_basic.t?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/t/00_basic.t (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/t/00_basic.t Thu Oct 28 05:48:48 2010
@@ -1,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan tests => 1;
+
+use_ok('File::Slurp::Unicode');
Added: branches/upstream/libfile-slurp-unicode-perl/current/t/10_read_file.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/t/10_read_file.t?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/t/10_read_file.t (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/t/10_read_file.t Thu Oct 28 05:48:48 2010
@@ -1,0 +1,36 @@
+#!/usr/bin/perl
+
+# This just tests that I mimic the File::Slurp APIs correctly.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan tests => 5;
+
+use File::Slurp::Unicode;
+use File::Temp qw(tempfile);
+
+my ($fh, $name) = tempfile();
+$fh->autoflush(1);
+my @expect = map { "$_\n" } qw(line1 line2 line3);
+my $expect = join '', @expect;
+print $fh $expect;
+
+my @lines = read_file $name;
+is_deeply(\@lines, \@expect, "list context");
+
+my $data = read_file $name;
+is($data, $expect, "scalar context");
+
+my $data_ref;
+read_file $name, buf_ref => \$data_ref;
+is($data_ref, $expect, "buf_ref");
+
+$data_ref = read_file $name, scalar_ref => 1;
+is(${$data_ref}, $expect, "scalar_ref");
+
+$data_ref = read_file $name, array_ref => 1;
+is_deeply($data_ref, \@expect, "array_ref");
+
Added: branches/upstream/libfile-slurp-unicode-perl/current/t/20_write_file.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/t/20_write_file.t?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/t/20_write_file.t (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/t/20_write_file.t Thu Oct 28 05:48:48 2010
@@ -1,0 +1,41 @@
+#!/usr/bin/perl
+
+# This just tests that I mimic the File::Slurp APIs correctly.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan tests => 5;
+
+use File::Slurp::Unicode;
+use File::Temp qw(tempfile);
+
+my ($fh, $name) = tempfile();
+$fh->autoflush(1);
+my @data = map { "$_\n" } qw(line1 line2 line3);
+my $data = join '', @data;
+print $fh $data;
+
+sub compare {
+ my ($test_name) = @_;
+ seek($fh, 0,0);
+ is_deeply([$fh->getlines], \@data, $test_name);
+}
+
+write_file $name, @data;
+compare("list");
+
+write_file $name, $data;
+compare("scalar");
+
+write_file $name, \@data;
+compare("array ref");
+
+write_file $name, \$data;
+compare("scalar ref");
+
+write_file $name, { buf_ref => \$data };
+compare("buf_ref");
+
Added: branches/upstream/libfile-slurp-unicode-perl/current/t/30_unicode.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-slurp-unicode-perl/current/t/30_unicode.t?rev=64317&op=file
==============================================================================
--- branches/upstream/libfile-slurp-unicode-perl/current/t/30_unicode.t (added)
+++ branches/upstream/libfile-slurp-unicode-perl/current/t/30_unicode.t Thu Oct 28 05:48:48 2010
@@ -1,0 +1,38 @@
+#!/usr/bin/perl
+
+# This tests the meat of what File::Slurp::Unicode does.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan tests => 7;
+
+use File::Temp qw(tempfile);
+my ($fh, $name) = tempfile();
+
+use Encode;
+use utf8;
+my $wide_data = "Dävîd";
+my $bin_data = "D\xc3\xa4v\xc3\xaed";
+my $latin_data = "D\xe4v\xeed";
+
+use File::Slurp::Unicode;
+
+write_file $name, $wide_data;
+is(read_file($name), $wide_data, "Basic in/out parity");
+
+write_file $name, $bin_data;
+is(read_file($name), $wide_data, "Don't touch byte coded strings");
+is(read_file($name, encoding => 'binary'), $bin_data, "Binary encoding read");
+
+write_file $name, { encoding => 'binary' }, $bin_data;
+is(read_file($name, encoding => 'binary'), $bin_data, "Binary encoding write");
+
+eval { write_file $name, { encoding => 'binary' }, $wide_data; };
+like($@, qr/Can't encode wide characters as binary/, "Writing wide characters as binary should die");
+
+write_file $name, { encoding => 'latin1' }, $wide_data;
+is(read_file($name, encoding => 'binary'), $latin_data, "Latin1 encoding write");
+is(read_file($name, encoding => 'latin1'), $wide_data, "Latin1 encoding read");
More information about the Pkg-perl-cvs-commits
mailing list