line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Cmd::run; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
162484
|
use Catmandu::Sane; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
94
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
106
|
use parent 'Catmandu::Cmd'; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
82
|
|
8
|
14
|
|
|
14
|
|
1024
|
use Catmandu; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
66
|
|
9
|
14
|
|
|
14
|
|
3061
|
use Catmandu::Util qw(require_package); |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
682
|
|
10
|
14
|
|
|
14
|
|
91
|
use namespace::clean; |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
78
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub command_opt_spec { |
13
|
|
|
|
|
|
|
( |
14
|
1
|
|
|
1
|
1
|
21
|
["var=s%", ""], |
15
|
|
|
|
|
|
|
["fix=s@", ""], |
16
|
|
|
|
|
|
|
["preprocess|pp", ""], |
17
|
|
|
|
|
|
|
["verbose|v", ""], |
18
|
|
|
|
|
|
|
["i", "interactive mode"], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub command { |
23
|
1
|
|
|
1
|
1
|
5
|
my ($self, $opts, $args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
33
|
|
|
12
|
if (defined $opts->{i} || !defined $args->[0]) { |
26
|
0
|
|
|
|
|
0
|
my $pkg = require_package('Catmandu::Interactive'); |
27
|
0
|
|
|
|
|
0
|
my $app = Catmandu::Interactive->new(); |
28
|
0
|
|
|
|
|
0
|
$app->run(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
1
|
|
|
|
|
4
|
my $fix_file = $args->[0]; |
32
|
1
|
50
|
|
|
|
18
|
$fix_file = [\*STDIN] unless defined $fix_file; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
5
|
$opts->{fix} = [$fix_file]; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
10
|
my $from = Catmandu->importer('Null'); |
37
|
1
|
|
|
|
|
33
|
$from = $self->_build_fixer($opts)->fix($from); |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
47
|
if ($opts->verbose) { |
40
|
0
|
|
|
|
|
0
|
$from = $from->benchmark; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
14
|
my $into = Catmandu->exporter('Null'); |
44
|
1
|
|
|
|
|
12
|
my $n = $into->add_many($from); |
45
|
1
|
|
|
|
|
33
|
$into->commit; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
4
|
if ($opts->verbose) { |
48
|
0
|
0
|
|
|
|
|
say STDERR $n == 1 ? "converted 1 item" : "converted $n items"; |
49
|
0
|
|
|
|
|
|
say STDERR "done"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Catmandu::Cmd::run - run a fix command |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 EXAMPLES |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Run an interactive Fix shell |
67
|
|
|
|
|
|
|
$ catmandu run |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Execute the fix script |
70
|
|
|
|
|
|
|
$ catmandu run myfixes.txt |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Execute the scripts with options passed |
73
|
|
|
|
|
|
|
$ catmandu run --var source=bla myfixes.txt |
74
|
|
|
|
|
|
|
$ cat myfixes.txt |
75
|
|
|
|
|
|
|
add_field(my_source,{{source}}) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Or create an execurable fix script: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#!/usr/bin/env catmandu run |
80
|
|
|
|
|
|
|
do importer(Mock,size:10) |
81
|
|
|
|
|
|
|
add_field(foo,bar) |
82
|
|
|
|
|
|
|
add_to_exporter(.,JSON) |
83
|
|
|
|
|
|
|
end |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |