line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::HomeDir::Unix; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# See POD at the end of the file for documentation |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
819
|
use 5.008003; |
|
6
|
|
|
|
|
15
|
|
6
|
6
|
|
|
6
|
|
27
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
103
|
|
7
|
6
|
|
|
6
|
|
23
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
155
|
|
8
|
6
|
|
|
6
|
|
29
|
use Carp (); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
77
|
|
9
|
6
|
|
|
6
|
|
1644
|
use File::HomeDir::Driver (); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
104
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
27
|
use vars qw{$VERSION}; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
187
|
|
12
|
6
|
|
|
6
|
|
25
|
use base "File::HomeDir::Driver"; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
509
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN |
15
|
|
|
|
|
|
|
{ |
16
|
6
|
|
|
6
|
|
2912
|
$VERSION = '1.003_002'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
##################################################################### |
20
|
|
|
|
|
|
|
# Current User Methods |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub my_home |
23
|
|
|
|
|
|
|
{ |
24
|
18
|
|
|
18
|
0
|
24
|
my $class = shift; |
25
|
18
|
|
|
|
|
47
|
my $home = $class->_guess_home(@_); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# On Unix in general, a non-existent home means "no home" |
28
|
|
|
|
|
|
|
# For example, "nobody"-like users might use /nonexistent |
29
|
18
|
50
|
33
|
|
|
220
|
if (defined $home and not -d $home) |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
0
|
$home = undef; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
18
|
|
|
|
|
70
|
return $home; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _guess_env_home |
38
|
|
|
|
|
|
|
{ |
39
|
18
|
|
|
18
|
|
27
|
my $class = shift; |
40
|
18
|
100
|
33
|
|
|
94
|
if (exists $ENV{HOME} and defined $ENV{HOME} and length $ENV{HOME}) |
|
|
|
66
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
17
|
|
|
|
|
39
|
return $ENV{HOME}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# This is from the original code, but I'm guessing |
46
|
|
|
|
|
|
|
# it means "login directory" and exists on some Unixes. |
47
|
1
|
0
|
33
|
|
|
4
|
if (exists $ENV{LOGDIR} and $ENV{LOGDIR}) |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
|
|
0
|
return $ENV{LOGDIR}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
2
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _guess_determined_home |
56
|
|
|
|
|
|
|
{ |
57
|
1
|
|
|
1
|
|
1
|
my $class = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Light desperation on any (Unixish) platform |
60
|
|
|
|
|
|
|
SCOPE: |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
|
|
2
|
my $home = (getpwuid($<))[7]; |
|
1
|
|
|
|
|
75
|
|
63
|
1
|
50
|
33
|
|
|
19
|
return $home if $home and -d $home; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _guess_home |
70
|
|
|
|
|
|
|
{ |
71
|
18
|
|
|
18
|
|
22
|
my $class = shift; |
72
|
18
|
|
|
|
|
32
|
my $home = $class->_guess_env_home($@); |
73
|
18
|
|
66
|
|
|
33
|
$home ||= $class->_guess_determined_home($@); |
74
|
18
|
|
|
|
|
26
|
return $home; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# On unix by default, everything is under the same folder |
78
|
|
|
|
|
|
|
sub my_desktop |
79
|
|
|
|
|
|
|
{ |
80
|
2
|
|
|
2
|
0
|
4
|
shift->my_home; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub my_documents |
84
|
|
|
|
|
|
|
{ |
85
|
2
|
|
|
2
|
0
|
6
|
shift->my_home; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub my_data |
89
|
|
|
|
|
|
|
{ |
90
|
2
|
|
|
2
|
0
|
5
|
shift->my_home; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub my_music |
94
|
|
|
|
|
|
|
{ |
95
|
2
|
|
|
2
|
0
|
4
|
shift->my_home; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub my_pictures |
99
|
|
|
|
|
|
|
{ |
100
|
2
|
|
|
2
|
0
|
5
|
shift->my_home; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub my_videos |
104
|
|
|
|
|
|
|
{ |
105
|
2
|
|
|
2
|
0
|
5
|
shift->my_home; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
##################################################################### |
109
|
|
|
|
|
|
|
# General User Methods |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub users_home |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
0
|
3
|
my ($class, $name) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# IF and only if we have getpwuid support, and the |
116
|
|
|
|
|
|
|
# name of the user is our own, shortcut to my_home. |
117
|
|
|
|
|
|
|
# This is needed to handle HOME environment settings. |
118
|
1
|
50
|
|
|
|
43
|
if ($name eq getpwuid($<)) |
119
|
|
|
|
|
|
|
{ |
120
|
1
|
|
|
|
|
4
|
return $class->my_home; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
SCOPE: |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
|
my $home = (getpwnam($name))[7]; |
|
0
|
|
|
|
|
|
|
126
|
0
|
0
|
0
|
|
|
|
return $home if $home and -d $home; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return undef; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub users_desktop |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub users_documents |
138
|
|
|
|
|
|
|
{ |
139
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub users_data |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub users_music |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub users_pictures |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub users_videos |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
|
|
0
|
0
|
|
shift->users_home(@_); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=pod |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 NAME |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
File::HomeDir::Unix - Find your home and other directories on legacy Unix |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 SYNOPSIS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
use File::HomeDir; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# Find directories for the current user |
175
|
|
|
|
|
|
|
$home = File::HomeDir->my_home; # /home/mylogin |
176
|
|
|
|
|
|
|
$desktop = File::HomeDir->my_desktop; # All of these will... |
177
|
|
|
|
|
|
|
$docs = File::HomeDir->my_documents; # ...default to home... |
178
|
|
|
|
|
|
|
$music = File::HomeDir->my_music; # ...directory |
179
|
|
|
|
|
|
|
$pics = File::HomeDir->my_pictures; # |
180
|
|
|
|
|
|
|
$videos = File::HomeDir->my_videos; # |
181
|
|
|
|
|
|
|
$data = File::HomeDir->my_data; # |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 DESCRIPTION |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This module provides implementations for determining common user |
186
|
|
|
|
|
|
|
directories. In normal usage this module will always be |
187
|
|
|
|
|
|
|
used via L. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SUPPORT |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
See the support section the main L module. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHORS |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Sean M. Burke Esburke@cpan.orgE |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SEE ALSO |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L, L (legacy) |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright 2005 - 2011 Adam Kennedy. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Some parts copyright 2000 Sean M. Burke. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This program is free software; you can redistribute |
210
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
The full text of the license can be found in the |
213
|
|
|
|
|
|
|
LICENSE file included with this module. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |