| 1 | package Browser::Open; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | @Browser::Open::EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 14 | open_browser | ||||||||||||||||||||||||||||||||||||||||||
| 15 | open_browser_cmd | ||||||||||||||||||||||||||||||||||||||||||
| 16 | open_browser_cmd_all | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | my @known_commands = ( | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ['', $ENV{BROWSER}], | |||||||||||||||||||||||||||||||||||||||||
| 21 | ['darwin', '/usr/bin/open', 1], | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ['cygwin', 'start'], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ['MSWin32', 'start', undef, 1], | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ['solaris', 'xdg-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ['solaris', 'firefox'], | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ['linux', 'sensible-browser'], | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ['linux', 'xdg-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ['linux', 'x-www-browser'], | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ['linux', 'www-browser'], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ['linux', 'htmlview'], | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ['linux', 'gnome-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ['linux', 'gnome-moz-remote'], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ['linux', 'kfmclient'], | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ['linux', 'exo-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ['linux', 'firefox'], | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ['linux', 'seamonkey'], | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ['linux', 'opera'], | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ['linux', 'mozilla'], | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ['linux', 'iceweasel'], | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ['linux', 'netscape'], | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ['linux', 'galeon'], | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ['linux', 'opera'], | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ['linux', 'w3m'], | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ['linux', 'lynx'], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ['freebsd', 'xdg-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ['freebsd', 'gnome-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ['freebsd', 'gnome-moz-remote'], | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ['freebsd', 'kfmclient'], | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ['freebsd', 'exo-open'], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ['freebsd', 'firefox'], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ['freebsd', 'seamonkey'], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ['freebsd', 'opera'], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ['freebsd', 'mozilla'], | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ['freebsd', 'netscape'], | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ['freebsd', 'galeon'], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ['freebsd', 'opera'], | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ['freebsd', 'w3m'], | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ['freebsd', 'lynx'], | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ['', 'open'], | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ['', 'start'], | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | ################################## | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub open_browser { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_browser: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($url, $all) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | croak('Missing required parameter $url, ') unless $url; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $cmd = $all ? open_browser_cmd_all() : open_browser_cmd(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return unless $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return system($cmd, $url); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub open_browser_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_browser_cmd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return _check_all_cmds($^O); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub open_browser_cmd_all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_browser_cmd_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return _check_all_cmds(''); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | ################################## | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub _check_all_cmds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_all_cmds: called CC=13 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my ($filter) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | foreach my $spec (@known_commands) { | |||||||||||||||||||||||||||||||||||||||||
| 90 | 14 | my ($osname, $cmd, $exact, $no_search) = @$spec; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 14 | ▶ | next unless $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 12 | ▶ | next if $osname && $filter && $osname ne $filter; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$osname and $filter and $osname ne $filter
$osname and $filter
MC/DC66%2/3
$osname and $filter and $osname ne $filter
$osname
$filter
$osname ne $filter
Truth table75%3/4
A and B and C
A= $osnameB= $filterC= $osname ne $filter
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | ▶ | next if $no_search && !$filter && $osname ne $^O; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$no_search and not $filter and $osname ne $^O
$no_search and not $filter
MC/DC33%1/3
$no_search and not $filter and $osname ne $^O
$no_search
not $filter
$osname ne $^O
Truth table50%2/4
A and not(B) and C
A= $no_searchB= not $filterC= $osname ne $^O
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | ▶ | return $cmd if $exact && -x $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$exact and -x $cmd
MC/DC0%0/2
$exact and -x $cmd
$exact
-x $cmd
Truth table66%2/3
A and B
A= $exactB= -x $cmd
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | ▶ | return $cmd if $no_search; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | $cmd = _search_in_path($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | ▶ | return $cmd if $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | sub _search_in_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_search_in_path: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | for my $path (split(/:/, $ENV{PATH})) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 56 | ▶ | next unless $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 56 | my $file = catfile($path, $cmd); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 56 | ▶ | return $file if -x $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||||||||||||