bin/openit

filter: Statementstmt 80.0% 48 / 60 Branchbran 30.7% 8 / 26 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 64.0% 66 / 103 CC 1 SCAR 1.1
CC
1
Cov
64%
error
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/App/Open/Backend/MailCap.pm ↑ Summary blib/lib/App/Open/Backend.pm »
1 #!/usr/bin/env perl
2 #
3 # open - a commandline interface to launching programs via filename and URL associations.
4 #
5 # Please see COPYING for information on author, copyright, etc.
6 #
7  
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use App::Open;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use App::Open::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # macro to coerce the exit status from waitpid() output
17 7 ▶use POSIX qw(WEXITSTATUS);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 ▶use constant VERSION => $App::Open::VERSION;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 7 my $backend = "YAML";
22 7 my $config = "$ENV{HOME}/.openrc";
23 7 my $help = undef;
24  
25 7 GetOptions(
26 'b|backend=s' => \$backend,
27 'c|config=s' => \$config,
28 'h|help' => \$help,
29 );
30  
31 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
32 0 pod2usage(
33 {
34 -message => "@_",
35 -exitval => -1,
36 -verbose => 2,
37 -output => \*STDERR,
38 }
39 );
40 }
41  
42 7 ▶error "You must specify a filename" unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 7 7
43  
44 7 ▶$config ||= undef;
Condition50%1/2
$config ||= undef
l!l
70
MC/DC0%0/1
$config ||= undef
$config
Truth table50%1/2
A
A= $config
Aresult
11
00
45  
46 7 ▶if ($config && ! -f $config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config and not -f $config) 0 7 7
Condition33%1/3
$config and not -f $config
!ll&&!rl&&r
070
MC/DC0%0/2
$config and not -f $config
$config not -f $config
Truth table33%1/3
A and not(B)
A= $configB= not -f $config
ABresult
0X0
100
111
47 0 error "Supplied configuration file does not exist."
48 }
49  
50 7 my $c_obj;
51  
52 7 eval { $c_obj = App::Open::Config->new($config); };
53  
54 # XXX yes, this assignment is intentional
55 7 ▶if ($_ = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $@) 0 7 7
56 0 ▶ /INVALID_CONFIGURATION/ && error "Your configuration could not be parsed.";
Branch: 1 branch
BranchTrueFalseTotal
/INVALID_CONFIGURATION/ and error("Your configuration could not be parsed.") 0 0 0
57 0 error "There was an unspecified problem handling your configuration."
58 }
59  
60 7 foreach my $file (@ARGV) {
61 10 my $e_obj;
62  
63 10 eval { $e_obj = App::Open->new($c_obj, $file); };
64  
65 10 ▶ if ($_ = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $@) 0 10 10
66 0 ▶ /MISSING_ARGUMENT|INVALID_ARGUMENT/
Branch: 1 branch
BranchTrueFalseTotal
/MISSING_ARGUMENT|INVALID_ARGUMENT/ and error("There was a problem setting up the execution internally. Please contact the author.") 0 0 0
67 && error "There was a problem setting up the execution internally. Please contact the author.";
68 0 ▶ /FILE_NOT_FOUND/
Branch: 1 branch
BranchTrueFalseTotal
/FILE_NOT_FOUND/ and error("File does not exist.") 0 0 0
69 && error "File does not exist.";
70 0 ▶ /^NO_BACKEND_FOUND\s(.*)/
Branch: 1 branch
BranchTrueFalseTotal
/^NO_BACKEND_FOUND\s(.*)/ and error("There was a problem loading the backend '$1'. Please check your configuration.") 0 0 0
71 && error "There was a problem loading the backend '$1'. Please check your configuration.";
72 0 ▶ /BACKEND_CONFIG_ERROR/
Branch: 1 branch
BranchTrueFalseTotal
/BACKEND_CONFIG_ERROR/ and error("There was a problem with the configuration of one of your backends. Please check your configuration.") 0 0 0
73 && error "There was a problem with the configuration of one of your backends. Please check your configuration.";
74 0 error "There was an unspecified problem handling the execution."
75 }
76  
77 10 my $return;
78 10 eval { $return = $e_obj->execute_program };
79  
80 10 ▶ if ($_ = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $@) 0 10 10
81 0 ▶ /NO_PROGRAM/
Branch: 1 branch
BranchTrueFalseTotal
/NO_PROGRAM/ and error("No suitable program could be found for your file.") 0 0 0
82 && error "No suitable program could be found for your file.";
83 0 error "There was an unspecified problem trying to execute the program against your file."
84 }
85  
86 10 ▶ if ($return eq -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return eq -1) 0 10 10
87 0 error "The program specified for '$file' failed to execute: $!";
88 }
89  
90 10 ▶ if (@ARGV == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV == 1) 5 5 10
91 5 exit WEXITSTATUS($return);
92 }
93 }
94  
95 2 exit 0;
96  
97 =head1 open - a commandline interface to launching programs via MIME associations
98  
99 =head2 usage
100  
101 open [options] files
102  
103 =head2 options
104  
105 =over 4
106  
107 =item -b, --backend [MODULE]
108  
109 Loads a backend for finding the right program. It will first attempt to load
110 App::Open::[MODULE], then [MODULE] directly. This command may be repeated for
111 multiple backends to attempt resolution, first match wins.
112  
113 =item -c, --config [FILENAME]
114  
115 Specifies an alternative configuration file to the default $HOME/.openrc.
116  
117 =item -h, --help
118  
119 This help message
120  
121 =back
122  
123 =cut
« blib/lib/App/Open/Backend/MailCap.pm ↑ Summary blib/lib/App/Open/Backend.pm »