| 1 | package App::WatchLater::Browser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 1 | 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<open(1)> on mac OS, L<xdg-open(1)> on Linux, and C<start> on Windows. Falls | ||||||||||||||||||||||||||||
| 23 | back to the command specified by the C<BROWSER> 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<open_url> - exported by default. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =back | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 45 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 46 | 1 | our @EXPORT = qw(open_url); | |||||||||||||||||||||||||||
| 47 | 1 | our @EXPORT_OK = qw(open_url); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub _get_browser_name { | ||||||||||||||||||||||||||
|
Subroutine
_get_browser_name: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $ENV{BROWSER} if exists $ENV{BROWSER}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | for ($^O) { | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (/MSWin32/ || /cygwin/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/MSWin32/u or /cygwin/u
MC/DC0%0/2
/MSWin32/u or /cygwin/u
/MSWin32/u
/cygwin/u
Truth table0%0/3
A or B
A= /MSWin32/uB= /cygwin/u
| |||||||||||||||||||||||||||||
| 54 | 0 | return 'start'; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (/darwin/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | return 'open'; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (/linux/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub open_url { | ||||||||||||||||||||||||||
|
Subroutine
open_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($url) = @_; | |||||||||||||||||||||||||||
| 78 | 0 | my $browser = _get_browser_name(); | |||||||||||||||||||||||||||
| 79 | 0 | system { $browser } $browser, $url; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Aaron L. Zeng, C<< <me at bcc32.com> >> | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 BUGS | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Please report any bugs or feature requests to C<bug-app-watchlater at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 89 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-WatchLater>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-WatchLater> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | L<http://annocpan.org/dist/App-WatchLater> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | L<http://cpanratings.perl.org/d/App-WatchLater> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | L<http://search.cpan.org/dist/App-WatchLater/> | ||||||||||||||||||||||||||||
| 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<http://www.opensource.org/licenses/mit-license.php> | ||||||||||||||||||||||||||||
| 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 | 1; # End of App::WatchLater::Browser | |||||||||||||||||||||||||||