blib/lib/Catmandu/Cmd/run.pm

filter: Statementstmt 83.3% 30 / 36 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 73.3% 44 / 60 CC 7 SCAR 19.0
CC
7
Cov
71%
command
11.5
BEGIN
1.0
BEGIN
1.0
CRAP 6.7
« blib/lib/Catmandu/Fix.pm ↑ Summary blib/lib/Catmandu/Importer.pm »
1 package Catmandu::Cmd::run;
2  
3 13 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '1.0201_02';
6  
7 13 ▶use parent 'Catmandu::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Catmandu::Util qw(require_package);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub command_opt_spec {
13 (
14 1 ▶ ["var=s%", ""],
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
15 ["fix=s@", ""],
16 ["preprocess|pp", ""],
17 ["verbose|v", ""],
18 ["i", "interactive mode"],
19 );
20 }
21  
22 sub command {
23 1 ▶ my ($self, $opts, $args) = @_;
Subroutine command: called CC=7 SCAR=24.4
Pod documented
24  
25 1 ▶ if (defined $opts->{i} || !defined $args->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{'i'} or not defined $args->[0]) { } 0 1 1
Condition33%1/3
defined $opts->{"i"} or not defined $args->[0]
l!l&&r!l&&!r
001
MC/DC0%0/2
defined $opts->{"i"} or not defined $args->[0]
defined $opts->{"i"} not defined $args->[0]
Truth table33%1/3
A or not(B)
A= defined $opts->{"i"}B= not defined $args->[0]
ABresult
1X1
011
000
26 0 my $pkg = require_package('Catmandu::Interactive');
27 0 my $app = Catmandu::Interactive->new();
28 0 $app->run();
29 }
30 else {
31 1 my $fix_file = $args->[0];
32 1 ▶ $fix_file = [\*STDIN] unless defined $fix_file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fix_file 0 1 1
33  
34 1 $opts->{fix} = [$fix_file];
35  
36 1 my $from = Catmandu->importer('Null');
37 1 $from = $self->_build_fixer($opts)->fix($from);
38  
39 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 0 1 1
40 0 $from = $from->benchmark;
41 }
42  
43 1 my $into = Catmandu->exporter('Null');
44 1 my $n = $into->add_many($from);
45 1 $into->commit;
46  
47 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 0 1 1
48 0 ▶ say STDERR $n == 1
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 0 0
49 ? "converted 1 object"
50 : "converted $n objects";
51 0 say STDERR "done";
52 }
53 }
54 }
55  
56 13 1;
57  
58 __END__
59  
60 =pod
61  
62 =head1 NAME
63  
64 Catmandu::Cmd::run - run a fix command
65  
66 =head1 EXAMPLES
67
68 # Run an interactive Fix shell
69 $ catmandu run
70  
71 # Execute the fix script
72 $ catmandu run myfixes.txt
73  
74 # Execute the scripts with options passed
75 $ catmandu run --var source=bla myfixes.txt
76 $ cat myfixes.txt
77 add_field(my_source,{{source}})
78  
79 # Or create an execurable fix script:
80  
81 #!/usr/bin/env catmandu run
82 do importer(Mock,size:10)
83 add_field(foo,bar)
84 add_to_exporter(.,JSON)
85 end
86  
87 =cut
« blib/lib/Catmandu/Fix.pm ↑ Summary blib/lib/Catmandu/Importer.pm »