| 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
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 7 | ▶ | $config ||= undef; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config ||= undef
MC/DC0%0/1
$config ||= undef
$config
Truth table50%1/2
A
A= $config
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | ▶ | if ($config && ! -f $config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$config and not -f $config
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | /INVALID_CONFIGURATION/ && error "Your configuration could not be parsed."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | /MISSING_ARGUMENT|INVALID_ARGUMENT/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | && error "There was a problem setting up the execution internally. Please contact the author."; | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | /FILE_NOT_FOUND/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | && error "File does not exist."; | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | /^NO_BACKEND_FOUND\s(.*)/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | && error "There was a problem loading the backend '$1'. Please check your configuration."; | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | /BACKEND_CONFIG_ERROR/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | /NO_PROGRAM/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 87 | 0 | error "The program specified for '$file' failed to execute: $!"; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 10 | ▶ | if (@ARGV == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||