File Coverage

File:local/lib/perl5/File/HomeDir/FreeDesktop.pm
Coverage:40.5%

linestmtbrancondsubtimecode
1package File::HomeDir::FreeDesktop;
2
3# Specific functionality for unixes running free desktops
4# compatible with (but not using) File-BaseDir-0.03
5
6# See POD at the end of the file for more documentation.
7
8
2
2
17
3
use 5.00503;
9
2
2
2
4
0
24
use strict;
10
2
2
2
3
1
8
use Carp                ();
11
2
2
2
4
1
7
use File::Spec          ();
12
2
2
2
4
1
8
use File::Which         ();
13
2
2
2
310
2
17
use File::HomeDir::Unix ();
14
15
2
2
2
5
1
50
use vars qw{$VERSION @ISA};
16BEGIN {
17
2
0
        $VERSION = '1.00';
18
2
301
        @ISA     = 'File::HomeDir::Unix';
19}
20
21# xdg uses $ENV{XDG_CONFIG_HOME}/user-dirs.dirs to know where are the
22# various "my xxx" directories. That is a shell file. The official API
23# is the xdg-user-dir executable. It has no provision for assessing
24# the directories of a user that is different than the one we are
25# running under; the standard substitute user mechanisms are needed to
26# overcome this.
27
28my $xdgprog = File::Which::which('xdg-user-dir');
29
30sub _my {
31        # No quoting because input is hard-coded and only comes from this module
32
0
        my $thingy = qx($xdgprog $_[1]);
33
0
        chomp $thingy;
34
0
        return $thingy;
35}
36
37# Simple stuff
38
0
sub my_desktop   { shift->_my('DESKTOP')   }
39
0
sub my_documents { shift->_my('DOCUMENTS') }
40
0
sub my_music     { shift->_my('MUSIC')     }
41
0
sub my_pictures  { shift->_my('PICTURES')  }
42
0
sub my_videos    { shift->_my('VIDEOS')    }
43
44sub my_data {
45
0
        $ENV{XDG_DATA_HOME}
46        or
47        File::Spec->catdir(
48                shift->my_home,
49                qw{ .local share }
50        );
51}
52
53sub my_config {
54
0
        $ENV{XDG_CONFIG_HOME}
55        or
56        File::Spec->catdir(
57                shift->my_home,
58                qw{ .config }
59        );
60}
61
62# Custom locations (currently undocumented)
63
0
sub my_download    { shift->_my('DOWNLOAD')    }
64
0
sub my_publicshare { shift->_my('PUBLICSHARE') }
65
0
sub my_templates   { shift->_my('TEMPLATES')   }
66
67sub my_cache {
68
0
    $ENV{XDG_CACHE_HOME}
69    ||
70    File::Spec->catdir(shift->my_home, qw{ .cache });
71}
72
73
74
75
76
77#####################################################################
78# General User Methods
79
80
0
sub users_desktop   { Carp::croak('The users_desktop method is not available on an XDG based system.');   }
81
0
sub users_documents { Carp::croak('The users_documents method is not available on an XDG based system.'); }
82
0
sub users_music     { Carp::croak('The users_music method is not available on an XDG based system.');     }
83
0
sub users_pictures  { Carp::croak('The users_pictures method is not available on an XDG based system.');  }
84
0
sub users_videos    { Carp::croak('The users_videos method is not available on an XDG based system.');    }
85
0
sub users_data      { Carp::croak('The users_data method is not available on an XDG based system.');      }
86
871;
88
89 - 136
=pod

=head1 NAME

File::HomeDir::FreeDesktop - Find your home and other directories on FreeDesktop.org Unix

=head1 DESCRIPTION

This module provides implementations for determining common user
directories.  In normal usage this module will always be
used via L<File::HomeDir>.

=head1 SYNOPSIS

  use File::HomeDir;
  
  # Find directories for the current user
  $home    = File::HomeDir->my_home;        # /home/mylogin
  $desktop = File::HomeDir->my_desktop;
  $docs    = File::HomeDir->my_documents;
  $music   = File::HomeDir->my_music;
  $pics    = File::HomeDir->my_pictures;
  $videos  = File::HomeDir->my_videos;
  $data    = File::HomeDir->my_data;

=head1 AUTHORS

Jerome Quelin E<lt>jquellin@cpan.org<gt>

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 SEE ALSO

L<File::HomeDir>, L<File::HomeDir::Win32> (legacy)

=head1 COPYRIGHT

Copyright 2009 - 2011 Jerome Quelin.

Some parts copyright 2010 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut