HomeDir/FreeDesktop.pm

filter: Statementstmt 59.1% 29 / 49 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 35.7% 10 / 28 Podpod 0.0% 0 / 17 totaltotal 39.0% 39 / 100 SCAR 17.4
CC
4
Cov
53%
my_data
6.0
my_config
6.0
my_cache
6.0
CRAP 5.7
« HomeDir/Test.pm ↑ Summary HomeDir/Driver.pm »
1 package 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 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Which ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::HomeDir::Unix ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use base "File::HomeDir::Unix";
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 BEGIN
20 {
21 1 ▶ $VERSION = '1.004';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 }
23  
24 # xdg uses $ENV{XDG_CONFIG_HOME}/user-dirs.dirs to know where are the
25 # various "my xxx" directories. That is a shell file. The official API
26 # is the xdg-user-dir executable. It has no provision for assessing
27 # the directories of a user that is different than the one we are
28 # running under; the standard substitute user mechanisms are needed to
29 # overcome this.
30  
31 1 my $xdgprog = File::Which::which('xdg-user-dir');
32  
33 sub _my
34 {
35 # No quoting because input is hard-coded and only comes from this module
36 0 ▶ my $thingy = qx($xdgprog $_[1]);
Subroutine _my: not called CC=1 SCAR=6.9
37 0 chomp $thingy;
38 0 return $thingy;
39 }
40  
41 # Simple stuff
42 0 ▶sub my_desktop { shift->_my('DESKTOP') }
Subroutine my_desktop: not called CC=1 SCAR=6.9
Pod undocumented
43 0 ▶sub my_documents { shift->_my('DOCUMENTS') }
Subroutine my_documents: not called CC=1 SCAR=6.9
Pod undocumented
44 0 ▶sub my_music { shift->_my('MUSIC') }
Subroutine my_music: not called CC=1 SCAR=6.9
Pod undocumented
45 0 ▶sub my_pictures { shift->_my('PICTURES') }
Subroutine my_pictures: not called CC=1 SCAR=6.9
Pod undocumented
46 0 ▶sub my_videos { shift->_my('VIDEOS') }
Subroutine my_videos: not called CC=1 SCAR=6.9
Pod undocumented
47  
48 sub my_data
49 {
50 $ENV{XDG_DATA_HOME}
51 0 ▶ or File::Spec->catdir(shift->my_home, qw{ .local share });
Subroutine my_data: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"XDG_DATA_HOME"} or "File::Spec"->catdir((shift())->my_home, (".local", "share")) 0 0 0
52 }
53  
54 sub my_config
55 {
56 $ENV{XDG_CONFIG_HOME}
57 0 ▶ or File::Spec->catdir(shift->my_home, qw{ .config });
Subroutine my_config: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"XDG_CONFIG_HOME"} or "File::Spec"->catdir((shift())->my_home, ".config") 0 0 0
58 }
59  
60 # Custom locations (currently undocumented)
61 0 ▶sub my_download { shift->_my('DOWNLOAD') }
Subroutine my_download: not called CC=1 SCAR=6.9
Pod undocumented
62 0 ▶sub my_publicshare { shift->_my('PUBLICSHARE') }
Subroutine my_publicshare: not called CC=1 SCAR=6.9
Pod undocumented
63 0 ▶sub my_templates { shift->_my('TEMPLATES') }
Subroutine my_templates: not called CC=1 SCAR=6.9
Pod undocumented
64  
65 sub my_cache
66 {
67 $ENV{XDG_CACHE_HOME}
68 0 ▶ || File::Spec->catdir(shift->my_home, qw{ .cache });
Subroutine my_cache: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"XDG_CACHE_HOME"} or "File::Spec"->catdir((shift())->my_home, ".cache") 0 0 0
69 }
70  
71 #####################################################################
72 # General User Methods
73  
74 0 ▶sub users_desktop { Carp::croak('The users_desktop method is not available on an XDG based system.'); }
Subroutine users_desktop: not called CC=1 SCAR=6.9
Pod undocumented
75 0 ▶sub users_documents { Carp::croak('The users_documents method is not available on an XDG based system.'); }
Subroutine users_documents: not called CC=1 SCAR=6.9
Pod undocumented
76 0 ▶sub users_music { Carp::croak('The users_music method is not available on an XDG based system.'); }
Subroutine users_music: not called CC=1 SCAR=6.9
Pod undocumented
77 0 ▶sub users_pictures { Carp::croak('The users_pictures method is not available on an XDG based system.'); }
Subroutine users_pictures: not called CC=1 SCAR=6.9
Pod undocumented
78 0 ▶sub users_videos { Carp::croak('The users_videos method is not available on an XDG based system.'); }
Subroutine users_videos: not called CC=1 SCAR=6.9
Pod undocumented
79 0 ▶sub users_data { Carp::croak('The users_data method is not available on an XDG based system.'); }
Subroutine users_data: not called CC=1 SCAR=6.9
Pod undocumented
80  
81 1 1;
82  
83 =pod
84  
85 =head1 NAME
86  
87 File::HomeDir::FreeDesktop - Find your home and other directories on FreeDesktop.org Unix
88  
89 =head1 DESCRIPTION
90  
91 This module provides implementations for determining common user
92 directories. In normal usage this module will always be
93 used via L<File::HomeDir>.
94  
95 This module can operate only when the command C<xdg-user-dir> is available
96 and executable, which is typically achieved by installed a package named
97 C<xdg-user-dirs> or similar.
98  
99 One can find the latest spec at L<https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>.
100  
101 =head1 SYNOPSIS
102  
103 use File::HomeDir;
104
105 # Find directories for the current user
106 $home = File::HomeDir->my_home; # /home/mylogin
107 $desktop = File::HomeDir->my_desktop;
108 $docs = File::HomeDir->my_documents;
109 $music = File::HomeDir->my_music;
110 $pics = File::HomeDir->my_pictures;
111 $videos = File::HomeDir->my_videos;
112 $data = File::HomeDir->my_data;
113 $config = File::HomeDir->my_config;
114
115 # Some undocumented ones, expect they don't work - use with caution
116 $download = File::HomeDir->my_download;
117 $publicshare = File::HomeDir->my_publicshare;
118 $templates = File::HomeDir->my_templates;
119 $cache = File::HomeDir->my_cache;
120  
121 =head1 AUTHORS
122  
123 Jerome Quelin E<lt>jquellin@cpan.org<gt>
124  
125 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
126  
127 =head1 SEE ALSO
128  
129 L<File::HomeDir>, L<File::HomeDir::Win32> (legacy)
130  
131 =head1 COPYRIGHT
132  
133 Copyright 2009 - 2011 Jerome Quelin.
134  
135 Some parts copyright 2010 Adam Kennedy.
136  
137 This program is free software; you can redistribute
138 it and/or modify it under the same terms as Perl itself.
139  
140 The full text of the license can be found in the
141 LICENSE file included with this module.
142  
143 =cut
« HomeDir/Test.pm ↑ Summary HomeDir/Driver.pm »