line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ETL::Yertl::Command::yto; |
2
|
|
|
|
|
|
|
our $VERSION = '0.035'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Write documents to a format like JSON or CSV |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use ETL::Yertl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
6
|
1
|
|
|
1
|
|
279
|
use ETL::Yertl::Util qw( load_module ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
7
|
use Module::Runtime qw( use_module compose_module_name is_module_spec ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub main { |
10
|
4
|
|
|
4
|
0
|
10
|
my $class = shift; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
|
|
9
|
my %opt; |
13
|
4
|
50
|
|
|
|
12
|
if ( ref $_[-1] eq 'HASH' ) { |
14
|
4
|
|
|
|
|
6
|
%opt = %{ pop @_ }; |
|
4
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
8
|
my ( $format, @files ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
15
|
die "Must give a format\n" unless $format; |
20
|
3
|
|
|
|
|
8
|
my $out_fmt = load_module( format => $format )->new( %opt ); |
21
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
6
|
push @files, "-" unless @files; |
23
|
2
|
|
|
|
|
4
|
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
|
|
|
|
7
|
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
|
|
|
|
|
31
|
my $in_fmt = load_module( format => 'default' )->new( input => $fh ); |
38
|
2
|
|
|
|
|
8
|
print $out_fmt->write( $in_fmt->read ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |