blib/lib/Browser/Open.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 59.0% 13 / 22 Conditioncond 73.3% 11 / 15 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 75.2% 76 / 101 CC 19 SCAR 23.2
CC
19
Cov
76%
open_browser
20.0
_check_all_cmds
14.1
_search_in_path
4.0
CRAP 10.2
↑ Summary
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
BranchTrueFalseTotal
unless $url 0 0 0
68  
69 0 ▶ my $cmd = $all ? open_browser_cmd_all() : open_browser_cmd();
Branch: 1 branch
BranchTrueFalseTotal
$all ? : 0 0 0
70 0 ▶ return unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
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
BranchTrueFalseTotal
unless $cmd 2 12 14
92 12 ▶ next if $osname && $filter && $osname ne $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $osname and $filter and $osname ne $filter 5 7 12
Condition83%5/6
$osname and $filter and $osname ne $filter
!ll&&!rl&&r
615
$osname and $filter
!ll&&!rl&&r
066
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
ABCresult
0XX0
10X0
1100
1111
93 7 ▶ next if $no_search && !$filter && $osname ne $^O;
Branch: 1 branch
BranchTrueFalseTotal
if $no_search and not $filter and $osname ne $^O 1 6 7
Condition66%4/6
$no_search and not $filter and $osname ne $^O
!ll&&!rl&&r
601
$no_search and not $filter
!ll&&!rl&&r
601
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
ABCresult
0XX0
10X0
1100
1111
94  
95 6 ▶ return $cmd if $exact && -x $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $exact and -x $cmd 0 6 6
Condition66%2/3
$exact and -x $cmd
!ll&&!rl&&r
510
MC/DC0%0/2
$exact and -x $cmd
$exact -x $cmd
Truth table66%2/3
A and B
A= $exactB= -x $cmd
ABresult
0X0
100
111
96 6 ▶ return $cmd if $no_search;
Branch: 1 branch
BranchTrueFalseTotal
if $no_search 0 6 6
97 6 $cmd = _search_in_path($cmd);
98 6 ▶ return $cmd if $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd 2 4 6
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
BranchTrueFalseTotal
unless $path 0 56 56
108 56 my $file = catfile($path, $cmd);
109 56 ▶ return $file if -x $file;
Branch: 1 branch
BranchTrueFalseTotal
if -x $file 2 54 56
110 }
111 4 return;
112 }
113  
114  
115 2 1;
116 __END__
↑ Summary