Desktop-Detect

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.007.
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
bin/detect-desktop
dist.ini
lib/Desktop/Detect.pm
t/00-compile.t
t/author-pod-coverage.t
t/author-pod-syntax.t
weaver.ini

META.json  view on Meta::CPAN

{
   "abstract" : "Detect desktop environment currently running",
   "author" : [
      "perlancar <perlancar@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150005",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Detect desktop environment currently running'
author:
  - 'perlancar <perlancar@cpan.org>'
build_requires:
  File::Spec: '0'
  IO::Handle: '0'
  IPC::Open3: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0

Makefile.PL  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007.
use strict;
use warnings;

use 5.010001;

use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT" => "Detect desktop environment currently running",
  "AUTHOR" => "perlancar <perlancar\@cpan.org>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME" => "Desktop-Detect",
  "EXE_FILES" => [
    "bin/detect-desktop"
  ],
  "LICENSE" => "perl",
  "MIN_PERL_VERSION" => "5.010001",
  "NAME" => "Desktop::Detect",
  "PREREQ_PM" => {
    "Data::Dumper" => 0,
    "Exporter" => 0,
    "strict" => 0,
    "warnings" => 0
  },

README  view on Meta::CPAN

SYNOPSIS

     use Desktop::Detect qw(detect_desktop);
     my $res = detect_desktop();
     say "We are running under XFCE" if $res->{desktop} eq 'xfce';

DESCRIPTION

    This module uses several heuristics to find out what desktop
    environment is currently running, along with extra information.

FUNCTIONS

 detect_desktop() => HASHREF

    Return a hashref containing information about running desktop
    environment and extra information.

    Detection is done from the cheapest methods, e.g. looking at
    environment variables. Several environment variables are checked, e.g.
    DESKTOP_SESSION, XDG_DESKTOP_SESSION, etc.

    Result:

      * desktop => STR

      Possible values: xfce, kde-plasma, gnome, gnome-classic, cinnamon,
      lxde, openbox, or empty string (if can't detect any desktop
      environment running).

SEE ALSO

bin/detect-desktop  view on Meta::CPAN

#!perl

our $DATE = '2016-10-07'; # DATE
our $VERSION = '0.06'; # VERSION

use strict;
use warnings;

use Data::Dumper;
use Desktop::Detect qw(detect_desktop);

my $res = detect_desktop();
{
    local $Data::Dumper::Terse = 1;
    print Dumper $res;
}
exit($res->{desktop} ? 0 : 1);

# ABSTRACT: Detect desktop (CLI)
# PODNAME: detect-desktop

__END__

=pod

=encoding UTF-8

=head1 NAME

detect-desktop - Detect desktop (CLI)

=head1 VERSION

This document describes version 0.06 of detect-desktop (from Perl distribution Desktop-Detect), released on 2016-10-07.

=head1 SYNOPSIS

 % detect-desktop

=head1 DESCRIPTION

This is a simple CLI to detect desktop. It essentially just dumps the
information returned by L<Desktop::Detect>.

=head1 EXIT CODES

0 if desktop can be detected.

1 if otherwise.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Desktop-Detect>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-Desktop-Detect>.

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


our $DATE = '2016-10-07'; # DATE
our $VERSION = '0.06'; # VERSION

use 5.010001;
use strict;
use warnings;

require Exporter;
our @ISA       = qw(Exporter);
our @EXPORT_OK = qw(detect_desktop); # detect_desktop_cached

#my $dd_cache;
#sub detect_desktop_cached {
#    if (!$dd_cache) {
#        $dd_cache = detect_desktop(@_);
#    }
#    $dd_cache;
#}

sub _det_env {
    my ($info, $desktop, $env, $re_or_str) = @_;
    my $cond = ref($re_or_str) eq 'Regexp' ?
        ($ENV{$env}//'') =~ $re_or_str : ($ENV{$env}//'') eq $re_or_str;
    if ($cond) {
        push @{$info->{_debug_info}}, "detect: $desktop via $env env";
        $info->{desktop} = $desktop;
        return 1;
    }
    0;
}

sub detect_desktop {
    my @dbg;
    my $info = {_debug_info=>\@dbg};

  DETECT:
    {
        # xfce
        last DETECT if _det_env($info, 'xfce', 'XDG_MENU_PREFIX', 'xfce-');
        last DETECT if _det_env($info, 'xfce', 'DESKTOP_SESSION', 'xfce');

        # kde-plasma

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

        last DETECT if _det_env($info, 'gnome-fallback', 'DESKTOP_SESSION', 'gnome-fallback');

        # lxde
        last DETECT if _det_env($info, 'lxde', 'XDG_MENU_PREFIX', 'lxde-');
        last DETECT if _det_env($info, 'lxde', 'DESKTOP_SESSION', 'LXDE');

        # openbox
        last DETECT if _det_env($info, 'openbox', 'DESKTOP_SESSION', 'openbox');

        push @dbg, "detect: nothing detected";
        $info->{desktop} = '';
    } # DETECT

    $info;
}

1;
# ABSTRACT: Detect desktop environment currently running

__END__

=pod

=encoding UTF-8

=head1 NAME

Desktop::Detect - Detect desktop environment currently running

=head1 VERSION

This document describes version 0.06 of Desktop::Detect (from Perl distribution Desktop-Detect), released on 2016-10-07.

=head1 SYNOPSIS

 use Desktop::Detect qw(detect_desktop);
 my $res = detect_desktop();
 say "We are running under XFCE" if $res->{desktop} eq 'xfce';

=head1 DESCRIPTION

This module uses several heuristics to find out what desktop environment
is currently running, along with extra information.

=head1 FUNCTIONS

=head2 detect_desktop() => HASHREF

Return a hashref containing information about running desktop environment and
extra information.

Detection is done from the cheapest methods, e.g. looking at environment
variables. Several environment variables are checked, e.g. C<DESKTOP_SESSION>,
C<XDG_DESKTOP_SESSION>, etc.

Result:

=over

=item * desktop => STR

Possible values: C<xfce>, C<kde-plasma>, C<gnome>, C<gnome-classic>,
C<cinnamon>, C<lxde>, C<openbox>, or empty string (if can't detect any desktop
environment running).

=back

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Desktop-Detect>.

=head1 SOURCE

t/00-compile.t  view on Meta::CPAN


use Test::More;

plan tests => 2 + ($ENV{AUTHOR_TESTING} ? 1 : 0);

my @module_files = (
    'Desktop/Detect.pm'
);

my @scripts = (
    'bin/detect-desktop'
);

# no fake home requested

my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib';

use File::Spec;
use IPC::Open3;
use IO::Handle;



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