Scroll to navigation

Catmandu::Exporter(3pm) User Contributed Perl Documentation Catmandu::Exporter(3pm)
 

NAME

Catmandu::Exporter - Namespace for packages that can export

SYNOPSIS

    package Catmandu::Exporter::Foo;
    use Catmandu::Sane;
    use Moo;
    with 'Catmandu::Exporter'
    sub add {
        my ($self, $data) = @_;
        my $fh = $self->fh;
    }
    package main;
    use Catmandu;
    my $exporter = Catmandu->exporter('Foo', file => "/tmp/output.txt");
    
    # Or on the command line
    $ catmandu convert JSON to Foo < /tmp/something.txt >/tmp/output.txt

DESCRIPTION

A Catmandu::Exporter is a Perl package the can export data. When no options are given exported data is written to the stdout. Optionally provide a "file" pathname or a "fh" file handle to redirect the output.
Every Catmandu::Exporter is a Catmandu::Fixable and thus provides a "fix" parameter that can be set in the constructor. For every "add" or for every item in "add_many" the given fixes will be applied first. E.g.
Every Catmandu::Exporter is a Catmandu::Addable and inherits the methods "add" and "add_many".

CONFIGURATION

file
Write output to a local file given by its path. Alternatively a scalar reference can be passed to write to a string.
fh
Write the output to an IO::Handle. If not specified, Catmandu::Util::io is used to create the output stream from the "file" argument or by using STDOUT.
encoding
Binmode of the output stream "fh". Set to ":utf8" by default.
fix
An ARRAY of one or more fixes or file scripts to be applied to exported items.

METHODS

add

Adds one object to be exported.

add_many

Adds many objects to be exported. This can be either an ARRAY-ref or an Catmandu::Iterator. Returns a true value when the export was successful or undef on error.

count

Returns the number of items exported by this Catmandu::Exporter.

log

Returns the current logger.

SEE ALSO

Catmandu::Addable, Catmandu::Fix,Catmandu::JSON, Catmandu::YAML, Catmandu::CSV, Catmandu::RIS
2014-10-14 perl v5.20.1