script/ot

filter: Statementstmt 92.0% 58 / 63 Branchbran 80.7% 21 / 26 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 87.0% 94 / 108 CC 4 SCAR 8.7
CC
4
Cov
88%
exit_with_error
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« blib/lib/Open/This.pm ↑ Summary
1 #!perl
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use Open::This qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 editor_args_from_parsed_text
9 maybe_get_url_from_parsed_text
10 parse_text
11 18 );
12 18 ▶use Pod::Usage qw( pod2usage );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 18 ▶pod2usage("Error: missing argument\n") unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 18 18
15  
16 18 my $browse;
17 my $editor;
18 18 my $help;
19 18 my $json;
20 18 my $print;
21 18 my $version;
22  
23 18 my $options_ok = GetOptions(
24 'browse|b' => \$browse,
25 'editor|e=s' => \$editor,
26 'help|h' => \$help,
27 'json|j' => \$json,
28 'print|p' => \$print,
29 'version|v' => \$version,
30 );
31  
32 18 ▶if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 2 16 18
33 2 pod2usage(
34 -exitval => 0,
35 -output => \*STDOUT,
36 -verbose => 99,
37 -sections => [qw( SYNOPSIS PARAMETERS )],
38 );
39 }
40  
41 16 ▶if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 2 14 16
42 2 print STDOUT 'ot ', Open::This->VERSION, "\n";
43 2 exit(0);
44 }
45  
46 # With a target left, carry on so unquoted text with a stray -foo still opens.
47 14 ▶if ( !$options_ok && !@ARGV ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options_ok or @ARGV) 2 12 14
Condition100%3/3
$options_ok or @ARGV
l!l&&r!l&&!r
1112
MC/DC100%2/2
$options_ok or @ARGV
$options_ok @ARGV
Truth table100%3/3
A or B
A= $options_okB= @ARGV
ABresult
1X1
011
000
48 2 ▶ exit_with_error( 'Invalid options', undef, 2 ) if $json;
Branch: 1 branch
BranchTrueFalseTotal
if $json 1 1 2
49 1 pod2usage(2);
50 }
51  
52 12 my $parsed = parse_text(@ARGV);
53 12 ▶if ( !$parsed ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parsed) 1 11 12
54 1 exit_with_error( 'Could not locate file', join ' ', @ARGV );
55 }
56  
57 11 ▶if ($browse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($browse) 2 9 11
58 2 maybe_get_url_from_parsed_text($parsed);
59 2 ▶ if ( !exists $parsed->{remote_file_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $parsed->{"remote_file_url"}) 0 2 2
60 0 exit_with_error( 'Could not find remote repository', $parsed );
61 }
62  
63 2 require Browser::Open;
64 2 Browser::Open::open_browser( $parsed->{remote_file_url} );
65 2 exit(0);
66 }
67  
68 9 ▶local $ENV{EDITOR} = $editor || $ENV{EDITOR};
Condition33%1/3
$editor || $ENV{'EDITOR'}
l!l&&r!l&&!r
900
MC/DC0%0/2
$editor || $ENV{'EDITOR'}
$editor $ENV{'EDITOR'}
Truth table33%1/3
A || B
A= $editorB= $ENV{'EDITOR'}
ABresult
1X1
011
000
69  
70 9 ▶unless ( $ENV{EDITOR} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"EDITOR"}) 0 9 9
71 0 exit_with_error(
72 'Please set your $EDITOR env var or use the --editor arg');
73 }
74  
75 9 my @editor_args = editor_args_from_parsed_text($parsed);
76  
77 9 ▶if ($json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json) 4 5 9
78 4 require Cpanel::JSON::XS; ## no perlimports
79 my $json = Cpanel::JSON::XS->new->canonical->encode(
80 {
81 editor => $ENV{EDITOR},
82 4 editor_args => \@editor_args,
83 success => Cpanel::JSON::XS::true(),
84 }
85 );
86 4 print STDOUT $json, "\n";
87 4 exit(0);
88 }
89 5 ▶if ($print) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print) 5 0 5
90 5 print STDOUT join( ' ', @editor_args ), "\n";
91 5 exit(0);
92 }
93  
94 2 ▶sub exit_with_error {
Subroutine exit_with_error: called CC=4 SCAR=14.1
95 2 my $error = shift;
96 2 my $details = shift;
97 2 ▶ my $status = shift // 1;
Condition100%2/2
shift() // 1
l!l
11
MC/DC100%1/1
shift() // 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
98 2 ▶ unless ($json) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($json) 0 2 2
99 0 print STDERR $error, "\n";
100 0 exit($status);
101 }
102 2 require Cpanel::JSON::XS; ## no perlimports
103 2 ▶ my $json = Cpanel::JSON::XS->new->canonical->encode(
Branch: 1 branch
BranchTrueFalseTotal
$details ? : 1 1 2
104 {
105 ( $details ? ( details => $details ) : () ),
106 error => $error,
107 success => Cpanel::JSON::XS::false(),
108 }
109 );
110 2 print STDOUT $json, "\n";
111 2 exit($status);
112 }
113  
114 0 exec $ENV{EDITOR}, @editor_args;
115  
116 # ABSTRACT: parse text and (hopefully) open an editor with the correct arguments
117 # PODNAME: ot
118  
119 __END__
« blib/lib/Open/This.pm ↑ Summary