Desktop-Open

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME
    Desktop::Open - Open a file or URL in the user's preferred application

VERSION
    This document describes version 0.004 of Desktop::Open (from Perl
    distribution Desktop-Open), released on 2023-10-21.

SYNOPSIS
     use Desktop::Open qw(open_desktop);
     my $ok = open_desktop($path_or_url);
     # !defined($ok);       no recognized command found
     # $ok == 0;            command found and executed
     # $ok != 0;            command found, error while executing

DESCRIPTION
    This module tries to open specified file or URL in the user's preferred
    application. Here's how it does it.

    1. If on Windows, use "start". If on other OS, use "xdg-open" if
    available.

    2. If #1 fails, resort to using Browser::Open's "open_browser". Return
    its return value. An exception is if #1 fails with "file/URL does not
    exist" error, in which case we give up immediately.

    TODO: On OSX, use "openit". Any taker?

FUNCTIONS
  open_desktop
ENVIRONMENT
  PERL_DESKTOP_OPEN_PROGRAM
    String. Override which program to use for opening the progrm instead of
    xdg-open. Note that the program is not checked for existence, nor the
    result is checked for success. No other program will be tried.

  PERL_DESKTOP_OPEN_USE_BROWSER
    Integer. If set to 1, then will just use Browser::Open directly instead
    of xdg-open program.

lib/Desktop/Open.pm  view on Meta::CPAN

use warnings;
use Log::ger;

use Exporter qw(import);

our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2023-10-21'; # DATE
our $DIST = 'Desktop-Open'; # DIST
our $VERSION = '0.004'; # VERSION

our @EXPORT_OK = qw(open_desktop);

sub open_desktop {
    my $path_or_url = shift;

    my $res;
  OPEN: {
        if (defined $ENV{PERL_DESKTOP_OPEN_PROGRAM}) {
            system $ENV{PERL_DESKTOP_OPEN_PROGRAM}, $path_or_url;
            $res = $?;
            last;
        }

lib/Desktop/Open.pm  view on Meta::CPAN

=head1 NAME

Desktop::Open - Open a file or URL in the user's preferred application

=head1 VERSION

This document describes version 0.004 of Desktop::Open (from Perl distribution Desktop-Open), released on 2023-10-21.

=head1 SYNOPSIS

 use Desktop::Open qw(open_desktop);
 my $ok = open_desktop($path_or_url);
 # !defined($ok);       no recognized command found
 # $ok == 0;            command found and executed
 # $ok != 0;            command found, error while executing

=head1 DESCRIPTION

This module tries to open specified file or URL in the user's preferred
application. Here's how it does it.

1. If on Windows, use "start". If on other OS, use "xdg-open" if available.

2. If #1 fails, resort to using L<Browser::Open>'s C<open_browser>. Return its
return value. An exception is if #1 fails with "file/URL does not exist" error,
in which case we give up immediately.

TODO: On OSX, use "openit". Any taker?

=head1 FUNCTIONS

=head2 open_desktop

=head1 ENVIRONMENT

=head2 PERL_DESKTOP_OPEN_PROGRAM

String. Override which program to use for opening the progrm instead of
B<xdg-open>. Note that the program is not checked for existence, nor the result
is checked for success. No other program will be tried.

=head2 PERL_DESKTOP_OPEN_USE_BROWSER



( run in 0.905 second using v1.01-cache-2.11-cpan-299005ec8e3 )