r6476 - in /branches/upstream/libfile-read-perl: ./ current/ current/lib/ current/lib/File/ current/t/ current/t/samples/

deepak-guest at users.alioth.debian.org deepak-guest at users.alioth.debian.org
Sat Aug 11 17:27:37 UTC 2007


Author: deepak-guest
Date: Sat Aug 11 17:27:37 2007
New Revision: 6476

URL: http://svn.debian.org/wsvn/?sc=1&rev=6476
Log:
[svn-inject] Installing original source of libfile-read-perl

Added:
    branches/upstream/libfile-read-perl/
    branches/upstream/libfile-read-perl/current/
    branches/upstream/libfile-read-perl/current/Build.PL
    branches/upstream/libfile-read-perl/current/Changes
    branches/upstream/libfile-read-perl/current/MANIFEST
    branches/upstream/libfile-read-perl/current/META.yml
    branches/upstream/libfile-read-perl/current/Makefile.PL
    branches/upstream/libfile-read-perl/current/README
    branches/upstream/libfile-read-perl/current/lib/
    branches/upstream/libfile-read-perl/current/lib/File/
    branches/upstream/libfile-read-perl/current/lib/File/Read.pm
    branches/upstream/libfile-read-perl/current/t/
    branches/upstream/libfile-read-perl/current/t/00-load.t
    branches/upstream/libfile-read-perl/current/t/distchk.t
    branches/upstream/libfile-read-perl/current/t/file-read.t
    branches/upstream/libfile-read-perl/current/t/pod-coverage.t
    branches/upstream/libfile-read-perl/current/t/pod.t
    branches/upstream/libfile-read-perl/current/t/portfs.t
    branches/upstream/libfile-read-perl/current/t/samples/
    branches/upstream/libfile-read-perl/current/t/samples/config
    branches/upstream/libfile-read-perl/current/t/samples/empty
    branches/upstream/libfile-read-perl/current/t/samples/hello
    branches/upstream/libfile-read-perl/current/t/samples/hello-world
    branches/upstream/libfile-read-perl/current/t/samples/jerkcity2630
    branches/upstream/libfile-read-perl/current/t/samples/latin1
    branches/upstream/libfile-read-perl/current/t/samples/newline
    branches/upstream/libfile-read-perl/current/t/samples/pi
    branches/upstream/libfile-read-perl/current/t/samples/space
    branches/upstream/libfile-read-perl/current/t/samples/world

Added: branches/upstream/libfile-read-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/Build.PL?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/Build.PL (added)
+++ branches/upstream/libfile-read-perl/current/Build.PL Sat Aug 11 17:27:37 2007
@@ -1,0 +1,16 @@
+use strict;
+use Module::Build;
+
+my $builder = Module::Build->new(
+    module_name         => 'File::Read',
+    license             => 'perl',
+    dist_author         => 'Sébastien Aperghis-Tramoni <sebastien at aperghis.net>',
+    dist_version_from   => 'lib/File/Read.pm',
+    build_requires => {
+        'File::Slurp'   => 0,
+        'Test::More'    => 0,
+    },
+    add_to_cleanup      => [ 'File-Read-*' ],
+);
+
+$builder->create_build_script();

Added: branches/upstream/libfile-read-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/Changes?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/Changes (added)
+++ branches/upstream/libfile-read-perl/current/Changes Sat Aug 11 17:27:37 2007
@@ -1,0 +1,36 @@
+Revision history for File-Read
+
+0.0602  2006.10.13  (SAPER)
+        [DIST] Added example eg/read_hosts.pl
+        [DOC] Small Pod changes.
+
+0.0601  2006.07.22  (SAPER)
+        [TESTS] Fixed t/file-read.t so it skips when file doesn't exist.
+
+0.06    2006.07.05  (SAPER)
+        [CODE] _to_ascii(): Improved the substitution.
+
+0.0501  2005.03.30  (SAPER)
+        [DIST] Updated MANIFEST..
+
+0.05    2005.03.30  (SAPER)
+        [FEATURE] Added new filter: to_ascii.
+
+0.04    2006.03.29  (SAPER)
+        [DOC] Added a rationale subsection.
+        [DOC] Added a See Also section.
+        [DOC] Small presentation change.
+
+0.03    2006.03.27  (SAPER)
+        [CODE] Small improvment: replaced an eval-string with an eval-code.
+        [DIST] Added missing prereq File::Slurp in Build.PL, Makefile.PL
+
+0.02    2006.02.08  (SAPER)
+        [BUGFIX] Fixed a problem when reading files as root.
+        [API] Changed the semantic of the aggregate option for a more 
+        useful one.
+        [DOC] Fixed a few pod typos.
+
+0.01    2006.02.03  (SAPER)
+        First version, released on an unsuspecting world.
+

Added: branches/upstream/libfile-read-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/MANIFEST?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/MANIFEST (added)
+++ branches/upstream/libfile-read-perl/current/MANIFEST Sat Aug 11 17:27:37 2007
@@ -1,0 +1,23 @@
+Build.PL
+Changes
+MANIFEST
+META.yml
+Makefile.PL
+README
+lib/File/Read.pm
+t/00-load.t
+t/distchk.t
+t/file-read.t
+t/pod-coverage.t
+t/pod.t
+t/portfs.t
+t/samples/config
+t/samples/empty
+t/samples/hello
+t/samples/hello-world
+t/samples/jerkcity2630
+t/samples/latin1
+t/samples/newline
+t/samples/pi
+t/samples/space
+t/samples/world

Added: branches/upstream/libfile-read-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/META.yml?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/META.yml (added)
+++ branches/upstream/libfile-read-perl/current/META.yml Sat Aug 11 17:27:37 2007
@@ -1,0 +1,20 @@
+---
+name: File-Read
+version: 0.0602
+author:
+  - 'Sébastien Aperghis-Tramoni <sebastien at aperghis.net>'
+abstract: Unique interface for reading one or more files
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+build_requires:
+  File::Slurp: 0
+  Test::More: 0
+provides:
+  File::Read:
+    file: lib/File/Read.pm
+    version: 0.0602
+generated_by: Module::Build version 0.2805
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.2.html
+  version: 1.2

Added: branches/upstream/libfile-read-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/Makefile.PL?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/Makefile.PL (added)
+++ branches/upstream/libfile-read-perl/current/Makefile.PL Sat Aug 11 17:27:37 2007
@@ -1,0 +1,18 @@
+use strict;
+use ExtUtils::MakeMaker;
+eval 'use ExtUtils::MakeMaker::Coverage';
+
+WriteMakefile(
+    NAME                => 'File::Read',
+    LICENSE             => 'perl',
+    AUTHOR              => 'Sébastien Aperghis-Tramoni <sebastien at aperghis.net>',
+    VERSION_FROM        => 'lib/File/Read.pm',
+    ABSTRACT_FROM       => 'lib/File/Read.pm',
+    PL_FILES            => {},
+    PREREQ_PM => {
+        'File::Slurp'   => 0,
+        'Test::More'    => 0,
+    },
+    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+    clean               => { FILES => 'File-Read-*' },
+);

Added: branches/upstream/libfile-read-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/README?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/README (added)
+++ branches/upstream/libfile-read-perl/current/README Sat Aug 11 17:27:37 2007
@@ -1,0 +1,74 @@
+NAME
+
+    File::Read - Unique interface for reading one or more files
+
+
+DESCRIPTION
+
+    This module mainly proposes functions for reading one or more files, 
+    with different options. See the documentation for more details and 
+    examples.
+
+
+INSTALLATION
+
+    To install this module, run the following commands:
+
+        perl Makefile.PL
+        make
+        make test
+        make install
+
+
+    Alternatively, to install with Module::Build, you can use the 
+    following commands:
+
+        perl Build.PL
+        ./Build
+        ./Build test
+        ./Build install
+
+    File::Read has been tested by the author to ensure that it works 
+    with the following versions of Perl: 
+
+      - Perl 5.4.5 i686-linux (custom build)
+      - Perl 5.4.5 x86_64-linux (custom build)
+      - Perl 5.5.3 i686-linux (custom build)
+      - Perl 5.5.3 x86_64-linux (custom build)
+      - Perl 5.6.2 i686-linux (custom build)
+      - Perl 5.6.2 x86_64-linux (custom build)
+      - Perl 5.8.5 i686-linux (vendor build)
+      - Perl 5.8.7 x86_64-linux (vendor build)
+
+    See also the corresponding CPAN Testers page: 
+        http://testers.cpan.org/show/File-Read.html
+
+
+SUPPORT AND DOCUMENTATION
+
+    After installing, you can find documentation for this module with 
+    the perldoc command.
+
+        perldoc File::Read
+
+    You can also look for information at:
+
+        Search CPAN
+            http://search.cpan.org/dist/File-Read
+
+        CPAN Request Tracker:
+            http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Read
+
+        AnnoCPAN, annotated CPAN documentation:
+            http://annocpan.org/dist/File-Read
+
+        CPAN Ratings:
+            http://cpanratings.perl.org/d/File-Read
+
+
+COPYRIGHT AND LICENCE
+
+    Copyright (C) 2006 Sébastien Aperghis-Tramoni
+
+    This program is free software; you can redistribute it and/or modify it
+    under the same terms as Perl itself.

Added: branches/upstream/libfile-read-perl/current/lib/File/Read.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/lib/File/Read.pm?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/lib/File/Read.pm (added)
+++ branches/upstream/libfile-read-perl/current/lib/File/Read.pm Sat Aug 11 17:27:37 2007
@@ -1,0 +1,324 @@
+package File::Read;
+use strict;
+use Carp;
+use File::Slurp ();
+require Exporter;
+
+{   no strict;
+    $VERSION = '0.0602';
+    @ISA = qw(Exporter);
+    @EXPORT = qw(read_file read_files);
+}
+
+*read_files = \&read_file;
+
+=head1 NAME
+
+File::Read - Unique interface for reading one or more files
+
+=head1 VERSION
+
+Version 0.06
+
+=head1 SYNOPSIS
+
+    use File::Read;
+
+    # read a file
+    $file = read_file($path);
+
+    # read several files
+    @files = read_files(@paths);
+
+    # aggregate several files
+    $file = read_files(@paths);
+
+    # read a file as root, skip comments and blank lines
+    $file = read_file({ as_root => 1, skip_comments => 1, skip_blanks => 1 }, $path);
+
+
+=head1 DESCRIPTION
+
+This module mainly proposes functions for reading one or more files, 
+with different options. See below for more details and examples.
+
+=head2 Rationale
+
+This module was created to address a quite specific need: reading many 
+files, some as a normal user and others as root, and eventually do a 
+little more processing, all while being at the same time compatible 
+with Perl 5.004. C<File::Slurp> addresses the first point, but not the 
+others, hence the creation of C<File::Read>. If you don't need reading 
+files as root or the post-processing features, then it's faster to 
+directly use C<File::Slurp>.
+
+=head1 EXPORT
+
+By default, this module exports all the functions documented afterhand.
+It also recognizes import options. For example
+
+    use File::Read 'err_mode=quiet';
+
+set C<read_file()>'s C<err_mode> option default value to C<"quiet">.
+
+=head1 FUNCTIONS
+
+=over
+
+=item B<read_file()>
+
+Read the files given in argument and return their content, 
+as as list, one element per file, when called in list context, 
+or as one big chunk of text when called in scalar context. 
+Options can be set using a hashref as first parameter.
+
+B<Options>
+
+=over
+
+=item *
+
+C<aggregate> controls how the function returns the content of the files 
+that were successfully read. By default, When set to true (default), 
+the function returns the content as a scalar; when set to false, the 
+content is returned as a list.
+
+=item *
+
+C<as_root> tells the function to read the given file(s) as root using 
+B<sudo(8)> and B<cat(1)>. You therefore need to edit F<sudoers(5)> in 
+order to allow the user to execute B<cat(1)>.
+
+=item *
+
+C<err_mode> controls how the function behaves when an error occurs. 
+Available values are C<"croak">, C<"carp"> and C<"quiet">.
+Default value is C<"croak">.
+
+=item *
+
+C<skip_comments> tells the functions to remove all comment lines from 
+the read files. 
+
+=item *
+
+C<skip_blanks> tells the functions to remove all blank lines from 
+the read files. 
+
+=item *
+
+C<to_ascii> tells the functions to convert the text to US-ASCII using
+C<Text::Unidecode>. If this module is not available, non-ASCII data 
+are deleted.
+
+=back
+
+B<Examples>
+
+Just read a file:
+
+    my $file = read_file($path);
+
+Read a file, returning it as list:
+
+    my @file = read_file({ aggregate => 0 }, $path);
+
+Read a file, skipping comments:
+
+    my $file = read_file({ skip_comments => 1 }, $path);
+
+Read several files, skipping blank lines and comments:
+
+    my @files = read_file({ skip_comments => 1, skip_blanks => 1 }, @paths);
+
+=item B<read_files()>
+
+C<read_files()> is just an alias for C<read_file()> so that it look more 
+sane when reading several files. 
+
+=cut
+
+my %defaults = (
+    aggregate       => 1, 
+    err_mode        => 'croak', 
+    skip_comments   => 0, 
+    skip_blanks     => 0, 
+    to_ascii        => 0, 
+);
+
+sub import {
+    my($module, at args) = @_;
+    my @new = ();
+
+    # parse arguments
+    for my $arg (@args) {
+        if(index($arg, '=') >= 0) {
+            my($opt,$val) = split('=', $arg);
+            $defaults{$opt} = $val if exists $defaults{$opt};
+
+        } else {
+            push @new, $arg
+        }
+    }
+
+    $module->export_to_level(1, $module, @new);
+}
+
+sub read_file {
+    my %opts = ref $_[0] eq 'HASH' ? %{+shift} : ();
+    my @paths = @_;
+    my @files = ();
+
+    # check options
+    for my $opt (keys %defaults) {
+        $opts{$opt} = $defaults{$opt} unless defined $opts{$opt}
+    }
+
+    # define error handler
+    $opts{err_mode} =~ /^(?:carp|croak|quiet)$/
+        or croak "error: Bad value '$opts{err_mode}' for option 'err_mode'";
+
+    my %err_with = (
+        'carp'  => \&carp, 
+        'croak' => \&croak, 
+        'quiet' => sub{}, 
+    );
+    my $err_sub = $err_with{$opts{err_mode}};
+
+    $err_sub->("error: This function needs at least one path") unless @paths;
+
+    for my $path (@paths) {
+        my @lines = ();
+        my $error = '';
+        
+        # first, read the file
+        if ($opts{as_root}) {    # ... as root
+            my $redir = $opts{err_mode} eq 'quiet' ? '2>&1' : '';
+            @lines = `sudo /bin/cat $path $redir`;
+
+            if ($?) {
+                if (not -f $path) {
+                    $! = eval { require Errno; Errno->import(":POSIX"); ENOENT() } ||  2
+                } elsif (not -r $path) {
+                    $! = eval { require Errno; Errno->import(":POSIX"); EACCES() } || 13
+                } else {
+                    $! = 1024
+                }
+                ($error = "$!") =~ s/ 1024//;
+            }
+
+        } else {                # ... as a normal user
+            @lines = eval { File::Slurp::read_file($path) };
+            $error = $@;
+        }
+
+        # if there's an error
+        $error and $err_sub->("error: $error");
+
+        # if there's any content at all...
+        if (@lines) {
+            # ... then do some filtering work if asked so
+            @lines = grep { ! /^$/    } @lines  if $opts{skip_blanks};
+            @lines = grep { ! /^\s*#/ } @lines  if $opts{skip_comments};
+            @lines = map { _to_ascii($_) } @lines  if $opts{to_ascii};
+        }
+
+        push @files, $opts{aggregate} ? join('', @lines) : @lines;
+    }
+
+    # how to return the content(s)?
+    return wantarray ? @files : join '', @files
+}
+
+
+my $has_unidecode = eval 'require Text::Unidecode; 1';
+
+sub _to_ascii {
+    # use Text::Unidecode if available
+    if($has_unidecode) {
+        return Text::Unidecode::unidecode(@_)
+
+    } else { # use a simple s///
+        my @text = @_;
+        map { s/[^\x00-\x7f]//g } @text;
+        return @text
+    }
+}
+
+=back
+
+=head1 DIAGNOSTICS
+
+=over
+
+=item C<Bad value '%s' for option '%s'>
+
+B<(E)> You gave a bad value for the indicated option. Please check the 
+documentation for the valid values. 
+
+=item C<This function needs at least one path>
+
+B<(E)> You called a function without giving it argument.
+
+=back
+
+=head1 SEE ALSO
+
+L<File::Slurp>
+
+L<IO::All>
+
+=head1 AUTHOR
+
+Sébastien Aperghis-Tramoni, C<< <sebastien at aperghis.net> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-file-read at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Read>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc File::Read
+
+You can also look for information at:
+
+=over 4
+
+=item *
+
+AnnoCPAN: Annotated CPAN documentation -
+L<http://annocpan.org/dist/File-Read>
+
+=item *
+
+CPAN Ratings -
+L<http://cpanratings.perl.org/d/File-Read>
+
+=item *
+
+RT: CPAN's request tracker -
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Read>
+
+=item *
+
+Search CPAN -
+L<http://search.cpan.org/dist/File-Read>
+
+=back
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006 Sébastien Aperghis-Tramoni, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of File::Read

Added: branches/upstream/libfile-read-perl/current/t/00-load.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/00-load.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/00-load.t (added)
+++ branches/upstream/libfile-read-perl/current/t/00-load.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+	use_ok( 'File::Read' );
+}
+
+diag( "Testing File::Read $File::Read::VERSION, Perl $], $^X" );

Added: branches/upstream/libfile-read-perl/current/t/distchk.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/distchk.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/distchk.t (added)
+++ branches/upstream/libfile-read-perl/current/t/distchk.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,4 @@
+use strict;
+use Test::More;
+eval "use Test::Distribution not => [qw(versions podcover use)]";
+plan skip_all => "Test::Distribution required for checking distribution" if $@;

Added: branches/upstream/libfile-read-perl/current/t/file-read.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/file-read.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/file-read.t (added)
+++ branches/upstream/libfile-read-perl/current/t/file-read.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,196 @@
+use strict;
+eval 'use warnings';
+use File::Read;
+use File::Spec;
+use Test::More;
+
+my $has_unidecode = defined $Text::Unidecode::VERSION;
+
+# describe the tests
+my @one_result_tests = (
+    {
+        args     => [ File::Spec->catfile(qw(t samples empty)) ], 
+        expected => '', 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples space)) ], 
+        expected => ' ', 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples newline)) ], 
+        expected => $/, 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples pi)) ], 
+        expected => "3.14159265358979\n", 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples hello)) ], 
+        expected => 'Hello', 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples world)) ], 
+        expected => "world\n",
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples hello)), 
+                      File::Spec->catfile(qw(t samples space)), 
+                      File::Spec->catfile(qw(t samples world)), 
+                    ], 
+        expected => "Hello world\n", 
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples jerkcity2630)) ], 
+        expected => "DEUCE: PLEASE DO THESE STEPS IN THE FOLLOWING ORDERS:\n" .
+                    "DEUCE: 1. SHUT UP\n" .
+                    "DEUCE: 2. GET THE FUCK OUT\n",
+    }, 
+    {
+        args     => [ File::Spec->catfile(qw(t samples config)) ], 
+        expected => "# something that looks like a configuration file\n" .
+                    "# with a few comments, and some empty lines\n" .
+                    "\n" .
+                    "# enable debug\n" .
+                    "debug = 1\n" .
+                    "\n" .
+                    "# be verbose\n" .
+                    "verbose = 1\n",
+    }, 
+    {
+        args     => [ { skip_comments => 1 }, File::Spec->catfile(qw(t samples config)) ], 
+        expected => "\n" .
+                    "debug = 1\n" .
+                    "\n" .
+                    "verbose = 1\n",
+    }, 
+    {
+        args     => [ { skip_blanks => 1 }, File::Spec->catfile(qw(t samples config)) ], 
+        expected => "# something that looks like a configuration file\n" .
+                    "# with a few comments, and some empty lines\n" .
+                    "# enable debug\n" .
+                    "debug = 1\n" .
+                    "# be verbose\n" .
+                    "verbose = 1\n",
+    }, 
+    {
+        args     => [ { skip_comments => 1, skip_blanks => 1 }, 
+                      File::Spec->catfile(qw(t samples config)) ], 
+        expected => "debug = 1\n" .
+                    "verbose = 1\n",
+    }, 
+    {
+        args     => [ { to_ascii => 1 }, File::Spec->catfile(qw(t samples latin1)) ], 
+        expected => $has_unidecode ?    # Text::Unidecode is available
+                    "agrave:a  aelig:ae  eacute:e  szlig:ss  eth:d   thorn:th   mu:u\n" .
+                    "pound:PS   laquo:<<  raquo:>>   sect:SS   para:P  middot:*\n"
+                    : # Text::Unidecode isn't available, non ASCII chars should be deleted
+                    "agrave:  aelig:  eacute:  szlig:  eth:   thorn:   mu:\n" .
+                    "pound:   laquo:  raquo:   sect:   para:  middot:\n"
+                    ,
+    }, 
+);
+
+my @one_result_root_tests = (
+    {
+        args     => [ { as_root => 1 }, 
+                      File::Spec->catfile(File::Spec->rootdir, qw(etc shadow)) ], 
+    }, 
+);
+
+my @many_results_tests = (
+    {
+        args     => [ File::Spec->catfile(qw(t samples empty)), 
+                      File::Spec->catfile(qw(t samples newline)), 
+                      File::Spec->catfile(qw(t samples space)) ], 
+        expected => [ '', $/, ' ' ], 
+    }, 
+    {
+        args     => [ { aggregate => 0 }, File::Spec->catfile(qw(t samples jerkcity2630)) ], 
+        expected => [ "DEUCE: PLEASE DO THESE STEPS IN THE FOLLOWING ORDERS:\n", 
+                      "DEUCE: 1. SHUT UP\n", 
+                      "DEUCE: 2. GET THE FUCK OUT\n" ]
+    }, 
+);
+
+
+# "I love it when a plan comes together"
+plan tests => 5 + @one_result_tests * 2 + @one_result_root_tests * 2 + @many_results_tests * 3;
+
+
+# check that the advertised functions are present
+can_ok( 'File::Read' => qw(read_file read_files) );
+
+
+# check diagnostics
+eval { read_file() };
+like( $@, '/^error: This function needs at least one path/', 
+    "calling read_file() with no argument" );
+
+eval { read_files() };
+like( $@, '/^error: This function needs at least one path/', 
+    "calling read_files() with no argument" );
+
+eval { read_file('not/such/file') };
+like( $@, q{/^error: read_file 'not/such/file' - /}, 
+    "calling read_file() with a file that does not exist" );
+
+eval { read_files({ err_mode => 'pwadak' }) };
+like( $@, q{/^error: Bad value 'pwadak' for option 'err_mode'/}, 
+    "calling read_files() with invalid value for option 'err_mode'" );
+
+
+# having Data::Dumper might be useful
+eval 'use Data::Dumper';
+$Data::Dumper::Indent = 0;
+$Data::Dumper::Indent = 0;
+
+# read files, returning one result
+for my $test (@one_result_tests) {
+    (eval { Dumper($test->{args}) } || '') =~ /\[(.+)\];$/;
+    my $args_str = $1 || "@{$test->{args}}";
+
+    my $file = eval { read_file( @{$test->{args}} ) };
+    is( $@, '', "calling read_file() with args: $args_str" );
+    is( $file, $test->{expected}, "checking result" );
+}
+
+
+# read files as root, returning one result
+for my $test (@one_result_root_tests) {
+    (eval { Dumper($test->{args}) } || '') =~ /\[(.+)\];$/;
+    my $args_str = $1 || "@{$test->{args}}";
+
+    # I don't know why, but Perl 5.005_04 chokes on the "SKIP:" line 
+    # with the error "Not a HASH reference". Fortunately, it's trappable 
+    # so we just eval{} it.
+    # Perl 5.8 also produces a warning "Pseudo-hashes are deprecated" 
+    # on the same line.
+    eval {
+        SKIP: {
+            skip "no such file", 2 unless -f $test->{args}[1];
+            skip "sudo (usually needs interactive password)", 2 if $ENV{AUTOMATED_TESTING};
+
+            my $file = eval { read_file( @{$test->{args}} ) };
+            is( $@, '', "calling read_file() with args: $args_str" );
+            cmp_ok( length $file, '>=', 0, "checking result" );
+        }
+    };
+    if($@) {
+        # something happened, preventing the previous block to 
+        # execute, so we just skip these tests by OK'ing them
+        pass(); pass();
+    }
+}
+
+
+# read files, returning several results
+for my $test (@many_results_tests) {
+    (eval { Dumper($test->{args}) } || '') =~ /\[(.+)\];$/;
+    my $args_str = $1 || "@{$test->{args}}";
+
+    my @files = eval { read_file( @{$test->{args}} ) };
+    is( $@, '', "calling read_file() with args: $args_str" );
+    is( @files, scalar @{ $test->{expected} }, "checking results: number of elements" );
+    is_deeply( \@files, $test->{expected}, "checking results: deep compare" );
+}
+

Added: branches/upstream/libfile-read-perl/current/t/pod-coverage.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/pod-coverage.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/pod-coverage.t (added)
+++ branches/upstream/libfile-read-perl/current/t/pod-coverage.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+all_pod_coverage_ok();

Added: branches/upstream/libfile-read-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/pod.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/pod.t (added)
+++ branches/upstream/libfile-read-perl/current/t/pod.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();

Added: branches/upstream/libfile-read-perl/current/t/portfs.t
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/portfs.t?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/portfs.t (added)
+++ branches/upstream/libfile-read-perl/current/t/portfs.t Sat Aug 11 17:27:37 2007
@@ -1,0 +1,8 @@
+#!/usr/bin/perl -T
+use strict;
+use Test::More;
+eval "use Test::Portability::Files";
+plan skip_all => "Test::Portability::Files required for testing filenames portability" if $@;
+
+# run the selected tests
+run_tests();

Added: branches/upstream/libfile-read-perl/current/t/samples/config
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/config?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/config (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/config Sat Aug 11 17:27:37 2007
@@ -1,0 +1,8 @@
+# something that looks like a configuration file
+# with a few comments, and some empty lines
+
+# enable debug
+debug = 1
+
+# be verbose
+verbose = 1

Added: branches/upstream/libfile-read-perl/current/t/samples/empty
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/empty?rev=6476&op=file
==============================================================================
    (empty)

Added: branches/upstream/libfile-read-perl/current/t/samples/hello
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/hello?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/hello (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/hello Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+Hello

Added: branches/upstream/libfile-read-perl/current/t/samples/hello-world
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/hello-world?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/hello-world (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/hello-world Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+Hello world

Added: branches/upstream/libfile-read-perl/current/t/samples/jerkcity2630
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/jerkcity2630?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/jerkcity2630 (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/jerkcity2630 Sat Aug 11 17:27:37 2007
@@ -1,0 +1,3 @@
+DEUCE: PLEASE DO THESE STEPS IN THE FOLLOWING ORDERS:
+DEUCE: 1. SHUT UP
+DEUCE: 2. GET THE FUCK OUT

Added: branches/upstream/libfile-read-perl/current/t/samples/latin1
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/latin1?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/latin1 (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/latin1 Sat Aug 11 17:27:37 2007
@@ -1,0 +1,2 @@
+agrave:à  aelig:æ  eacute:é  szlig:ß  eth:ð   thorn:þ   mu:µ
+pound:£   laquo:«  raquo:»   sect:§   para:¶  middot:·

Added: branches/upstream/libfile-read-perl/current/t/samples/newline
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/newline?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/newline (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/newline Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+

Added: branches/upstream/libfile-read-perl/current/t/samples/pi
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/pi?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/pi (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/pi Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+3.14159265358979

Added: branches/upstream/libfile-read-perl/current/t/samples/space
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/space?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/space (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/space Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+ 

Added: branches/upstream/libfile-read-perl/current/t/samples/world
URL: http://svn.debian.org/wsvn/branches/upstream/libfile-read-perl/current/t/samples/world?rev=6476&op=file
==============================================================================
--- branches/upstream/libfile-read-perl/current/t/samples/world (added)
+++ branches/upstream/libfile-read-perl/current/t/samples/world Sat Aug 11 17:27:37 2007
@@ -1,0 +1,1 @@
+world




More information about the Pkg-perl-cvs-commits mailing list