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