line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ETL::Yertl::Command::yto; |
2
|
|
|
|
|
|
|
our $VERSION = '0.037'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Write documents to a format like JSON or CSV |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use ETL::Yertl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
30
|
use ETL::Yertl::Util qw( load_module ); |
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
5
|
use Module::Runtime qw( use_module compose_module_name is_module_spec ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub main { |
10
|
4
|
|
|
4
|
0
|
8
|
my $class = shift; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
|
|
5
|
my %opt; |
13
|
4
|
50
|
|
|
|
12
|
if ( ref $_[-1] eq 'HASH' ) { |
14
|
4
|
|
|
|
|
6
|
%opt = %{ pop @_ }; |
|
4
|
|
|
|
|
9
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
10
|
my ( $format, @files ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
14
|
die "Must give a format\n" unless $format; |
20
|
3
|
|
|
|
|
9
|
my $out_fmt = load_module( format => $format )->new( %opt ); |
21
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
8
|
push @files, "-" unless @files; |
23
|
2
|
|
|
|
|
5
|
for my $file ( @files ) { |
24
|
|
|
|
|
|
|
# We're doing a similar behavior to <>, but manually for easier testing. |
25
|
2
|
|
|
|
|
3
|
my $fh; |
26
|
2
|
100
|
|
|
|
5
|
if ( $file eq '-' ) { |
27
|
|
|
|
|
|
|
# Use the existing STDIN so tests can fake it |
28
|
1
|
|
|
|
|
3
|
$fh = \*STDIN; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
1
|
50
|
|
|
|
10
|
unless ( open $fh, '<', $file ) { |
32
|
0
|
|
|
|
|
0
|
warn "Could not open file '$file' for reading: $!\n"; |
33
|
0
|
|
|
|
|
0
|
next; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
29
|
my $in_fmt = load_module( format => 'default' )->new( input => $fh ); |
38
|
2
|
|
|
|
|
7
|
print $out_fmt->write( $in_fmt->read ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |