NAME
Catmandu::Importer::Text - Package that imports textual data
SYNOPSIS
use Catmandu::Importer::Text;
my $importer = Catmandu::Importer::text->new(file => "/foo/bar.yaml");
my $n = $importer->each(sub {
my $hashref = $_[0];
printf "line %d: text: %s" , $hashref->{_id} , $hashref->{text};
});
DESCRIPTION
This Catmandu::Importer reads each line of input as an item with line number in field _id
and text content in field text
. Line separators are not included. A regular expression can be specified to only import selected lines and parts of lines that match a given pattern.
CONFIGURATION
- file
-
Read input from a local file given by its path. Alternatively a scalar reference can be passed to read from a string.
- fh
-
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. - encoding
-
Binmode of the input stream
fh
. Set to:utf8
by default. - fix
-
An ARRAY of one or more fixes or file scripts to be applied to imported items.
- split
-
Character or regular expression, given as string, to split each line. Imported field
text
will contain an array. - pattern
-
An regular expression, given as string, to only import matching lines. Whitespaces in patterns are ignored or must be escaped if patterns consists of multiple lines. If the pattern contains capturing groups, captured values are imported in field
match
instead oftext
.For instance dates in
YYYY-MM-DD
format can be imported as named fields with(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)
or as array with
(\d\d\d\d)- # year (\d\d)- # month (\d\d) # day
METHODS
Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The Catmandu::Importer::YAML methods are not idempotent: YAML feeds can only be read once.