++ed by:

1 PAUSE user(s)
3 non-PAUSE user(s).

Nicolas Steenlant


Catmandu::Importer - Namespace for packages that can import


    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;

    use Catmandu;

    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


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 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 Catmandu::Fixes. E.g.

    my $importer = Catmandu->importer('Hello',fix => ['upcase(hello)']);
    $importer->each( sub {
        my $item = shift ; # Every item will be upcased... 
    } );

Every Catmandu::Importer is a Catmandu::Iterable and inherits the methods (first, each, to_array...) etc.



Read input from a local file given by its path. Alternatively a scalar reference can be passed to read from a string.


Read input from an IO::Handle. If not specified, Catmandu::Util::io is used to create the input stream from the file argument or by using STDIN.


Binmode of the input stream fh. Set to :utf8 by default.


An ARRAY of one or more fixes or file scripts to be applied to imported items.



Read a line from the input stream. Equivalent to $importer->fh->getline.


Read the whole input stream as string.

first, each, rest , ...

See Catmandu::Iterable for all inherited methods.


Catmandu::Iterable , Catmandu::Fix , Catmandu::Importer::CSV, Catmandu::Importer::JSON , Catmandu::Importer::YAML

Hosting generously
sponsored by Bytemark