File Coverage

blib/lib/App/WatchLater/Browser.pm
Criterion Covered Total %
statement 15 28 53.5
branch 0 8 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod 1 1 100.0
total 21 47 44.6


line stmt bran cond sub pod time code
1             package App::WatchLater::Browser;
2              
3 1     1   14 use 5.016;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         15  
5 1     1   4 use warnings;
  1         1  
  1         35  
6              
7             =head1 NAME
8              
9             App::WatchLater::Browser - Open URLs in the User's Browser
10              
11             =head1 VERSION
12              
13             Version 0.03
14              
15             =cut
16              
17             our $VERSION = '0.03';
18              
19             =head1 SYNOPSIS
20              
21             This is a simple module for opening a URL in the user's browser, using
22             L on mac OS, L on Linux, and C on Windows. Falls
23             back to the command specified by the C environment variable, if set.
24              
25             use App::WatchLater::Browser;
26             open_url('https://duckduckgo.com');
27             ...
28              
29             =head1 EXPORT
30              
31             =over 4
32              
33             =item *
34              
35             C - exported by default.
36              
37             =back
38              
39             =cut
40              
41 1     1   4 use Carp;
  1         1  
  1         94  
42              
43             BEGIN {
44 1     1   6 require Exporter;
45 1         14 our @ISA = qw(Exporter);
46 1         3 our @EXPORT = qw(open_url);
47 1         185 our @EXPORT_OK = qw(open_url);
48             }
49              
50             sub _get_browser_name {
51 0 0   0     return $ENV{BROWSER} if exists $ENV{BROWSER};
52 0           for ($^O) {
53 0 0 0       if (/MSWin32/ || /cygwin/) {
54 0           return 'start';
55             }
56 0 0         if (/darwin/) {
57 0           return 'open';
58             }
59 0 0         if (/linux/) {
60 0           return 'xdg-open';
61             }
62 0           croak 'unsupported OS; try setting BROWSER environment variable';
63             }
64             }
65              
66             =head1 SUBROUTINES/METHODS
67              
68             =head2 open_url
69              
70             open_url($url);
71              
72             Does what it says on the tin. Croaks if unable to determine an appropriate browser.
73              
74             =cut
75              
76             sub open_url {
77 0     0 1   my ($url) = @_;
78 0           my $browser = _get_browser_name();
79 0           system { $browser } $browser, $url;
  0            
80             }
81              
82             =head1 AUTHOR
83              
84             Aaron L. Zeng, C<< >>
85              
86             =head1 BUGS
87              
88             Please report any bugs or feature requests to C, or through
89             the web interface at L. I will be notified, and then you'll
90             automatically be notified of progress on your bug as I make changes.
91              
92              
93              
94              
95             =head1 SUPPORT
96              
97             You can find documentation for this module with the perldoc command.
98              
99             perldoc App::WatchLater::Browser
100              
101              
102             You can also look for information at:
103              
104             =over 4
105              
106             =item * RT: CPAN's request tracker (report bugs here)
107              
108             L
109              
110             =item * AnnoCPAN: Annotated CPAN documentation
111              
112             L
113              
114             =item * CPAN Ratings
115              
116             L
117              
118             =item * Search CPAN
119              
120             L
121              
122             =back
123              
124              
125             =head1 ACKNOWLEDGEMENTS
126              
127              
128             =head1 LICENSE AND COPYRIGHT
129              
130             Copyright 2017 Aaron L. Zeng.
131              
132             This program is distributed under the MIT (X11) License:
133             L
134              
135             Permission is hereby granted, free of charge, to any person
136             obtaining a copy of this software and associated documentation
137             files (the "Software"), to deal in the Software without
138             restriction, including without limitation the rights to use,
139             copy, modify, merge, publish, distribute, sublicense, and/or sell
140             copies of the Software, and to permit persons to whom the
141             Software is furnished to do so, subject to the following
142             conditions:
143              
144             The above copyright notice and this permission notice shall be
145             included in all copies or substantial portions of the Software.
146              
147             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
148             EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
149             OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
150             NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
151             HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
152             WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
153             FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
154             OTHER DEALINGS IN THE SOFTWARE.
155              
156              
157             =cut
158              
159             1; # End of App::WatchLater::Browser