[libcatmandu-perl] 77/85: Merge branch 'pr/importer' of https://github.com/nichtich/Catmandu into nichtich-pr/importer

Jonas Smedegaard dr at jones.dk
Tue May 20 09:56:21 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.91
in repository libcatmandu-perl.

commit 1e0053c513195890839827e26d00e04f4d24c04e
Merge: 43d4de7 198d750
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Mon May 19 18:53:27 2014 +0200

    Merge branch 'pr/importer' of https://github.com/nichtich/Catmandu into nichtich-pr/importer
    
    Conflicts:
    	lib/Catmandu/Importer.pm

 META.json                |   2 +-
 lib/Catmandu/Importer.pm | 121 ++++++++++++++++++++++++++++++-----------------
 t/Catmandu-Importer.t    |  18 ++++++-
 3 files changed, 95 insertions(+), 46 deletions(-)

diff --cc META.json
index 6c71e0c,0000000..428d30e
mode 100644,000000..100644
--- a/META.json
+++ b/META.json
@@@ -1,132 -1,0 +1,132 @@@
 +{
 +   "abstract" : "a data toolkit",
 +   "author" : [
 +      "Nicolas Steenlant, C<< <nicolas.steenlant at ugent.be> >>"
 +   ],
 +   "dynamic_config" : 0,
-    "generated_by" : "Dist::Milla version v1.0.5, Dist::Zilla version 5.016, CPAN::Meta::Converter version 2.132830",
++   "generated_by" : "Dist::Milla version v1.0.5, Dist::Zilla version 5.016, CPAN::Meta::Converter version 2.141170",
 +   "license" : [
 +      "perl_5"
 +   ],
 +   "meta-spec" : {
 +      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
 +      "version" : "2"
 +   },
 +   "name" : "Catmandu",
 +   "no_index" : {
 +      "directory" : [
 +         "t",
 +         "xt",
 +         "inc",
 +         "share",
 +         "eg",
 +         "examples"
 +      ]
 +   },
 +   "optional_features" : {
 +      "tidy" : {
 +         "description" : "Support pretty printing compiled fix code",
 +         "prereqs" : {
 +            "runtime" : {
 +               "requires" : {
 +                  "Perl::Tidy" : "0"
 +               }
 +            }
 +         }
 +      }
 +   },
 +   "prereqs" : {
 +      "build" : {
 +         "requires" : {
 +            "Module::Build" : "0.3601"
 +         }
 +      },
 +      "configure" : {
 +         "requires" : {
 +            "Module::Build" : "0.3601"
 +         }
 +      },
 +      "develop" : {
 +         "requires" : {
 +            "Test::Pod" : "1.41"
 +         }
 +      },
 +      "runtime" : {
 +         "recommends" : {
 +            "JSON::XS" : "2.3",
 +            "YAML::XS" : "0.34"
 +         },
 +         "requires" : {
 +            "App::Cmd" : "0.323",
 +            "CGI::Expand" : "2.02",
 +            "Clone" : "0.31",
 +            "Config::Onion" : "1.004",
 +            "Data::Compare" : "1.22",
 +            "Data::UUID" : "1.217",
 +            "Data::Util" : "0.59",
 +            "IO::Handle::Util" : "0.01",
 +            "JSON" : "2.51",
 +            "List::MoreUtils" : "0.33",
 +            "Log::Any::Adapter" : "0.11",
 +            "Marpa::R2" : "2.084000",
 +            "Moo" : "1.000008",
 +            "MooX::Log::Any" : "0",
 +            "Sub::Exporter" : "0.982",
 +            "Sub::Quote" : "0",
 +            "Text::CSV" : "1.21",
 +            "Throwable" : "0.200004",
 +            "Time::HiRes" : "0",
 +            "Try::Tiny::ByClass" : "0.01",
 +            "YAML::Any" : "0.90",
 +            "namespace::clean" : "0.24",
 +            "perl" : "v5.10.1"
 +         }
 +      },
 +      "test" : {
 +         "requires" : {
 +            "Log::Any::Adapter" : "0.11",
 +            "Log::Any::Test" : "0.15",
 +            "Test::Deep" : "0.112",
 +            "Test::Exception" : "0.32",
 +            "Test::More" : "1.001003"
 +         }
 +      }
 +   },
 +   "release_status" : "stable",
 +   "resources" : {
 +      "bugtracker" : {
 +         "web" : "https://github.com/LibreCat/Catmandu/issues"
 +      },
 +      "homepage" : "https://github.com/LibreCat/Catmandu",
 +      "repository" : {
 +         "type" : "git",
 +         "url" : "https://github.com/LibreCat/Catmandu.git",
 +         "web" : "https://github.com/LibreCat/Catmandu"
 +      }
 +   },
 +   "version" : "0.9",
 +   "x_contributors" : [
 +      "Christian Pietsch <chr.pietsch+github at googlemail.com>",
 +      "Dave Sherohman <Dave.Sherohman at lub.lu.se>",
 +      "Dave Sherohman <Dave.Sherohman at ub.lu.se>",
 +      "EC2 Default User <ec2-user at ip-10-113-18-155.ec2.internal>",
 +      "EC2 Default User <ec2-user at ip-10-114-199-125.ec2.internal>",
 +      "EC2 Default User <ec2-user at ip-10-194-230-16.ec2.internal>",
 +      "EC2 Default User <ec2-user at ip-10-77-5-148.ec2.internal>",
 +      "Jakob Voss <jakob at nichtich.de>",
 +      "Jakob Voss <voss at gbv.de>",
 +      "Nicolas <nicolas.steenlant at ugent.be>",
 +      "Nicolas Franck <nicolas.franck at ugent.be>",
 +      "Nicolas Steenlant <nicolas.steenlant at gmail.com>",
 +      "Nicolas Steenlant <nicolas.steenlant at ugent.be>",
 +      "Nicolas Steenlant <nsteenla at ca20c608.ugent.be>",
 +      "Nicolas Steenlnat <nicolas.steenlant at ugent.be>",
 +      "Patrick <phochste at hal.lub.lu.se>",
 +      "Snorri Briem <Snorri.Briem at lub.lu.se>",
 +      "Snorri Briem <Snorri.Briem at ub.lu.se>",
 +      "Vitali Peil <vitali.peil at uni-bielefeld.de>",
 +      "phochste <phochste at vmtemp4.ugent.be>",
 +      "vpeil <vitali.peil at uni-bielefeld.de>"
 +   ]
 +}
 +
diff --cc lib/Catmandu/Importer.pm
index 8915e9a,6fc0fc3..557df30
--- a/lib/Catmandu/Importer.pm
+++ b/lib/Catmandu/Importer.pm
@@@ -45,72 -58,66 +58,94 @@@ Catmandu::Importer - Namespace for pack
  
  =head1 SYNOPSIS
  
-     use Catmandu::Importer::JSON;
+     package Catmandu::Importer::Hello;
+ 
+     use Catmandu::Sane;
+     use Moo;
+ 
+     with 'Catmandu::Importer';
+ 
+     sub generator {
+         my ($self) = @_;
+         state $fh = $self->fh;
++        my $n = 0;
+         return sub {
++            $self->log->debug("generating record " . ++$n);
+             my $name = $self->readline;
+             return defined $name ? { "hello" => $name } : undef;
+         };
+     } 
+ 
++    package main;
 +
-     my $importer = Catmandu::Importer::JSON->new(file => "/foo/bar.json");
++    use Catmandu;
 +
-     my $n = $importer->each(sub {
-         my $hashref = $_[0];
-         # ...
++    my $importer = Catmandu->importer('Hello', file => '/tmp/names.txt');
++    $importer->each(sub {
++        my $items = shift;
++        .
++        .
++        .
 +    });
 +
++    # Or on the command line
++    $ catmandu convert Hello to YAML < /tmp/names.txt
++
 +
  =head1 DESCRIPTION
  
- A Catmandu::Importer is a stub for Perl packages that can import data from
- an external source (a file, the network, ...).
 -A Catmandu::Importer is a Perl packages that can import data from an external
++A Catmandu::Importer is a Perl package that can import data from an external
+ source (a file, the network, ...). Most importers read from an input stream, 
+ such as STDIN, a given file, or an URL to fetch data from, so this base class
+ provides helper method for consuming the input stream once.
  
--Every Catmandu::Importer is a L<Catmandu::Fixable> and thus provides a 'fix'
--parameter that can be set in the constructor. For every item returned by the
--generator the given fixes will be applied first.
++Every Catmandu::Importer is a L<Catmandu::Fixable> and thus inherits a 'fix'
++parameter that can be set in the constructor. When given then each item returned
++by the generator will be automatically Fixed using one or more L<Catmandu::Fix>es.
++E.g.
++    
++    my $importer = Catmandu::Importer::Hello->new(fix => ['upcase(hello)']);
++    $importer->each( sub {
++        my $item = shift ; # Every item will be upcased... 
++    } );
  
- =head1 METHODS
 -Every Catmandu::Importer is a L<Catmandu::Iterable> and its methods (C<first>,
 -C<each>, C<to_array>...) should be used to access items from the importer.
++Every Catmandu::Importer is a L<Catmandu::Iterable> and inherits the methods (C<first>,
++C<each>, C<to_array>...) etc.
  
- =head2 new(file => $file , encoding => $encoding )
+ =head1 CONFIGURATION
  
- Create a new importer reading input from a local file: $file is a string containing the path to
- the file.
+ =over
  
- =head2 new(fh => $fh , encoding => $encoding)
+ =item file
  
- Create a new importer by reading from a IO::Handle. Optionally use Catmandu::Util::io to create IO::Handles.
+ Read input from a local file given by its path. Alternatively a scalar
+ reference can be passed to read from a string.
  
- =head2 count
+ =item fh
  
- =head2 each(&callback)
+ Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to
+ create the input stream from the C<file> argument or by using STDIN.
  
- =head2 ...
+ =item encoding
  
- Every Catmandu::Importer is a L<Catmandu::Iterable> all its methods are inherited.
+ Binmode of the input stream C<fh>. Set to C<:utf8> by default.
  
- =head2 log
+ =back
  
- Return the current logger. Can be used when creating your own Importers.
+ =head1 METHODS
  
- E.g.
-     
-     package Catmandu::Importer::Mock;
+ =head2 readline
  
-     use namespace::clean;
-     use Catmandu::Sane;
-     use Moo;
+ Read a line from the input stream. Equivalent to C<< $importer->fh->getline >>.
  
-     with 'Catmandu::Importer';
+ =head2 readall
  
-     has size => (is => 'ro');
+ Read the whole input stream as string.
  
-     sub generator {
-         my ($self) = @_;
-         my $n = 0;
-         sub {
-             $self->log->debug("generating record $n");
-             return if defined $self->size && $n == $self->size;
-             return { n => $n++ };
-         };
-     }
++=head2 first, each, rest , ...
 +
- See also: L<Catmandu> for activating the logger in your main code.
++See L<Catmandu::Iterable> for all inherited methods.
 +
  =head1 SEE ALSO
  
  L<Catmandu::Iterable> , L<Catmandu::Util>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git



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