line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::HomeDir::Darwin::Carbon; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Basic implementation for the Dawin family of operating systems. |
4
|
|
|
|
|
|
|
# This includes (most prominently) Mac OS X. |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1059
|
use 5.008003; |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
6
|
use Cwd (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
18
|
|
11
|
1
|
|
|
1
|
|
5
|
use File::HomeDir::Darwin (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use vars qw{$VERSION}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This is only a child class of the pure Perl darwin |
16
|
|
|
|
|
|
|
# class so that we can do homedir detection of all three |
17
|
|
|
|
|
|
|
# drivers at one via ->isa. |
18
|
1
|
|
|
1
|
|
7
|
use base "File::HomeDir::Darwin"; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
132
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
BEGIN |
21
|
|
|
|
|
|
|
{ |
22
|
1
|
|
|
1
|
|
4
|
$VERSION = '1.004'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Load early if in a forking environment and we have |
25
|
|
|
|
|
|
|
# prefork, or at run-time if not. |
26
|
1
|
|
|
|
|
3
|
local $@; ## no critic (Variables::RequireInitializationForLocalVars) |
27
|
1
|
|
|
1
|
|
83
|
eval "use prefork 'Mac::Files'"; ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) |
|
1
|
|
|
|
|
1044
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
##################################################################### |
31
|
|
|
|
|
|
|
# Current User Methods |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## no critic qw(UnusedPrivateSubroutines) |
34
|
|
|
|
|
|
|
sub _guess_determined_home |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
|
|
my $class = shift; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
require Mac::Files; |
39
|
0
|
|
|
|
|
|
my $home = $class->_find_folder(Mac::Files::kCurrentUserFolderType(),); |
40
|
0
|
|
0
|
|
|
|
$home ||= $class->SUPER::_guess_determined_home($@); |
41
|
0
|
|
|
|
|
|
return $home; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub my_desktop |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
require Mac::Files; |
49
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kDesktopFolderType(),); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub my_documents |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
require Mac::Files; |
57
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kDocumentsFolderType(),); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub my_data |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
require Mac::Files; |
65
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kApplicationSupportFolderType(),); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub my_music |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
require Mac::Files; |
73
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kMusicDocumentsFolderType(),); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub my_pictures |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
require Mac::Files; |
81
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kPictureDocumentsFolderType(),); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub my_videos |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
require Mac::Files; |
89
|
0
|
|
|
|
|
|
$class->_find_folder(Mac::Files::kMovieDocumentsFolderType(),); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _find_folder |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
|
|
my $class = shift; |
95
|
0
|
|
|
|
|
|
my $name = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
require Mac::Files; |
98
|
0
|
|
|
|
|
|
my $folder = Mac::Files::FindFolder(Mac::Files::kUserDomain(), $name,); |
99
|
0
|
0
|
|
|
|
|
return undef unless defined $folder; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
unless (-d $folder) |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
# Make sure that symlinks resolve to directories. |
104
|
0
|
0
|
|
|
|
|
return undef unless -l $folder; |
105
|
0
|
0
|
|
|
|
|
my $dir = readlink $folder or return; |
106
|
0
|
0
|
|
|
|
|
return undef unless -d $dir; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return Cwd::abs_path($folder); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
##################################################################### |
113
|
|
|
|
|
|
|
# Arbitrary User Methods |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub users_home |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
118
|
0
|
|
|
|
|
|
my $home = $class->SUPER::users_home(@_); |
119
|
0
|
0
|
|
|
|
|
return defined $home ? Cwd::abs_path($home) : undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# in theory this can be done, but for now, let's cheat, since the |
123
|
|
|
|
|
|
|
# rest is Hard |
124
|
|
|
|
|
|
|
sub users_desktop |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
0
|
0
|
|
my ($class, $name) = @_; |
127
|
0
|
0
|
|
|
|
|
return undef if $name eq 'root'; |
128
|
0
|
|
|
|
|
|
$class->_to_user($class->my_desktop, $name); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub users_documents |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
0
|
0
|
|
my ($class, $name) = @_; |
134
|
0
|
0
|
|
|
|
|
return undef if $name eq 'root'; |
135
|
0
|
|
|
|
|
|
$class->_to_user($class->my_documents, $name); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub users_data |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
0
|
0
|
|
my ($class, $name) = @_; |
141
|
0
|
0
|
|
|
|
|
$class->_to_user($class->my_data, $name) |
142
|
|
|
|
|
|
|
|| $class->users_home($name); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# cheap hack ... not entirely reliable, perhaps, but ... c'est la vie, since |
146
|
|
|
|
|
|
|
# there's really no other good way to do it at this time, that i know of -- pudge |
147
|
|
|
|
|
|
|
sub _to_user |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
0
|
|
|
my ($class, $path, $name) = @_; |
150
|
0
|
|
|
|
|
|
my $my_home = $class->my_home; |
151
|
0
|
|
|
|
|
|
my $users_home = $class->users_home($name); |
152
|
0
|
0
|
|
|
|
|
defined $users_home or return undef; |
153
|
0
|
|
|
|
|
|
$path =~ s/^\Q$my_home/$users_home/; |
154
|
0
|
|
|
|
|
|
return $path; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=pod |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 NAME |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
File::HomeDir::Darwin - Find your home and other directories on Darwin (OS X) |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 DESCRIPTION |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This module provides Darwin-specific implementations for determining |
168
|
|
|
|
|
|
|
common user directories. In normal usage this module will always be |
169
|
|
|
|
|
|
|
used via L. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Note -- since this module requires Mac::Carbon and Mac::Carbon does |
172
|
|
|
|
|
|
|
not work with 64-bit perls, on such systems, File::HomeDir will try |
173
|
|
|
|
|
|
|
L and then fall back to the (pure Perl) |
174
|
|
|
|
|
|
|
L. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 SYNOPSIS |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
use File::HomeDir; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Find directories for the current user |
181
|
|
|
|
|
|
|
$home = File::HomeDir->my_home; # /Users/mylogin |
182
|
|
|
|
|
|
|
$desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop |
183
|
|
|
|
|
|
|
$docs = File::HomeDir->my_documents; # /Users/mylogin/Documents |
184
|
|
|
|
|
|
|
$music = File::HomeDir->my_music; # /Users/mylogin/Music |
185
|
|
|
|
|
|
|
$pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures |
186
|
|
|
|
|
|
|
$videos = File::HomeDir->my_videos; # /Users/mylogin/Movies |
187
|
|
|
|
|
|
|
$data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 TODO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * Test with Mac OS (versions 7, 8, 9) |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * Some better way for users_* ? |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |