ETL-Yertl
view release on metacpan or search on metacpan
lib/ETL/Yertl.pm view on Meta::CPAN
package ETL::Yertl;
our $VERSION = '0.044';
# ABSTRACT: ETL with a Shell
use strict;
use warnings;
use 5.010;
use base 'Import::Base', 'Exporter';
use Carp qw( croak );
use Module::Runtime qw( use_module );
use ETL::Yertl::FormatStream;
use ETL::Yertl::Format;
use IO::Async::Loop;
our @EXPORT = qw( stdin stdout transform file yq );
our @EXPORT_OK = qw( loop );
sub loop;
sub import {
$_[0]->export_to_level( 1, undef, @EXPORT );
# C-style for loop because we remove items from the array and need
# to keep comparing against $#_
for ( my $i = 1; $i <= $#_; $i++ ) {
if ( grep { $_ eq $_[ $i ] } @EXPORT_OK ) {
$_[0]->export_to_level( 1, undef, $_[ $i ] );
splice @_, $i, 1;
redo unless $i > $#_;
}
}
goto &Import::Base::import;
}
our @IMPORT_MODULES = (
strict => [],
warnings => [],
feature => [qw( :5.10 )],
'Path::Tiny' => [qw( path )],
);
our %IMPORT_BUNDLES = (
Test => [
qw( Test::More Test::Deep Test::Exception Test::Differences ),
FindBin => [ '$Bin' ],
boolean => [':all'],
'Path::Tiny' => [qw( path cwd tempfile tempdir )],
'Dir::Self' => [qw( __DIR__ )],
'ETL::Yertl::Util' => [qw( docs_from_string )],
],
);
$ETL::Yertl::VERBOSE = $ENV{YERTL_VERBOSE} || 0;
sub yertl::diag {
my ( $level, $text ) = @_;
print STDERR "$text\n" if $ETL::Yertl::VERBOSE >= $level;
}
# format attribute takes simple string for named format object
sub stream(%) {
my ( %args ) = @_;
if ( $args{format} && !ref $args{format} ) {
$args{format} = ETL::Yertl::Format->get( $args{format} );
}
my $stream = ETL::Yertl::FormatStream->new( %args );
loop->add( $stream );
return $stream;
}
#pod =sub stdin
#pod
#pod my $stdin = stdin( %args );
#pod
#pod Get a L<ETL::Yertl::FormatStream> object for standard input. C<%args> is a list
#pod of key/value pairs passed to L<ETL::Yertl::FormatStream/new>. Useful keys are:
#pod
#pod =over
#pod
#pod =item format
#pod
#pod Specify the format that standard input is. Defaults to C<yaml> or the value
#pod of C<YERTL_FORMAT> (see L<ETL::Yertl::Format/get_default>.
#pod
#pod =back
#pod
#pod =cut
sub stdin(;%) {
my ( %args ) = @_;
$args{read_handle} = \*STDIN;
return stream( %args );
}
#pod =sub stdout
#pod
#pod my $stdout = stdout( %args );
#pod
#pod Get a L<ETL::Yertl::FormatStream> object for standard output. C<%args> is a list
#pod of key/value pairs passed to L<ETL::Yertl::FormatStream/new>. Useful keys are:
#pod
#pod =over
#pod
#pod =item format
#pod
( run in 0.497 second using v1.01-cache-2.11-cpan-6aa56a78535 )