Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/File/HomeDir/Unix.pm |
Statements | Executed 13 statements in 535µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 199µs | 270µs | BEGIN@8 | File::HomeDir::Unix::
1 | 1 | 1 | 14µs | 14µs | BEGIN@5 | File::HomeDir::Unix::
1 | 1 | 1 | 9µs | 9µs | BEGIN@11 | File::HomeDir::Unix::
1 | 1 | 1 | 7µs | 35µs | BEGIN@10 | File::HomeDir::Unix::
1 | 1 | 1 | 7µs | 17µs | BEGIN@6 | File::HomeDir::Unix::
1 | 1 | 1 | 3µs | 3µs | BEGIN@7 | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | _my_home | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_data | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_desktop | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_documents | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_home | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_music | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_pictures | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | my_videos | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_data | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_desktop | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_documents | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_home | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_music | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_pictures | File::HomeDir::Unix::
0 | 0 | 0 | 0s | 0s | users_videos | File::HomeDir::Unix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::HomeDir::Unix; | ||||
2 | |||||
3 | # See POD at the end of the file for documentation | ||||
4 | |||||
5 | 2 | 37µs | 1 | 14µs | # spent 14µs within File::HomeDir::Unix::BEGIN@5 which was called:
# once (14µs+0s) by File::HomeDir::Darwin::BEGIN@7 at line 5 # spent 14µs making 1 call to File::HomeDir::Unix::BEGIN@5 |
6 | 2 | 17µs | 2 | 28µs | # spent 17µs (7+10) within File::HomeDir::Unix::BEGIN@6 which was called:
# once (7µs+10µs) by File::HomeDir::Darwin::BEGIN@7 at line 6 # spent 17µs making 1 call to File::HomeDir::Unix::BEGIN@6
# spent 10µs making 1 call to strict::import |
7 | 2 | 15µs | 1 | 3µs | # spent 3µs within File::HomeDir::Unix::BEGIN@7 which was called:
# once (3µs+0s) by File::HomeDir::Darwin::BEGIN@7 at line 7 # spent 3µs making 1 call to File::HomeDir::Unix::BEGIN@7 |
8 | 2 | 84µs | 1 | 270µs | # spent 270µs (199+71) within File::HomeDir::Unix::BEGIN@8 which was called:
# once (199µs+71µs) by File::HomeDir::Darwin::BEGIN@7 at line 8 # spent 270µs making 1 call to File::HomeDir::Unix::BEGIN@8 |
9 | |||||
10 | 2 | 30µs | 2 | 64µs | # spent 35µs (7+28) within File::HomeDir::Unix::BEGIN@10 which was called:
# once (7µs+28µs) by File::HomeDir::Darwin::BEGIN@7 at line 10 # spent 35µs making 1 call to File::HomeDir::Unix::BEGIN@10
# spent 28µs making 1 call to vars::import |
11 | # spent 9µs within File::HomeDir::Unix::BEGIN@11 which was called:
# once (9µs+0s) by File::HomeDir::Darwin::BEGIN@7 at line 14 | ||||
12 | 1 | 300ns | $VERSION = '1.00'; | ||
13 | 1 | 9µs | @ISA = 'File::HomeDir::Driver'; | ||
14 | 1 | 341µs | 1 | 9µs | } # spent 9µs making 1 call to File::HomeDir::Unix::BEGIN@11 |
15 | |||||
- - | |||||
20 | ##################################################################### | ||||
21 | # Current User Methods | ||||
22 | |||||
23 | sub my_home { | ||||
24 | my $class = shift; | ||||
25 | my $home = $class->_my_home(@_); | ||||
26 | |||||
27 | # On Unix in general, a non-existant home means "no home" | ||||
28 | # For example, "nobody"-like users might use /nonexistant | ||||
29 | if ( defined $home and ! -d $home ) { | ||||
30 | $home = undef; | ||||
31 | } | ||||
32 | |||||
33 | return $home; | ||||
34 | } | ||||
35 | |||||
36 | sub _my_home { | ||||
37 | my $class = shift; | ||||
38 | if ( exists $ENV{HOME} and defined $ENV{HOME} ) { | ||||
39 | return $ENV{HOME}; | ||||
40 | } | ||||
41 | |||||
42 | # This is from the original code, but I'm guessing | ||||
43 | # it means "login directory" and exists on some Unixes. | ||||
44 | if ( exists $ENV{LOGDIR} and $ENV{LOGDIR} ) { | ||||
45 | return $ENV{LOGDIR}; | ||||
46 | } | ||||
47 | |||||
48 | ### More-desperate methods | ||||
49 | |||||
50 | # Light desperation on any (Unixish) platform | ||||
51 | SCOPE: { | ||||
52 | my $home = (getpwuid($<))[7]; | ||||
53 | return $home if $home and -d $home; | ||||
54 | } | ||||
55 | |||||
56 | return undef; | ||||
57 | } | ||||
58 | |||||
59 | # On unix by default, everything is under the same folder | ||||
60 | sub my_desktop { | ||||
61 | shift->my_home; | ||||
62 | } | ||||
63 | |||||
64 | sub my_documents { | ||||
65 | shift->my_home; | ||||
66 | } | ||||
67 | |||||
68 | sub my_data { | ||||
69 | shift->my_home; | ||||
70 | } | ||||
71 | |||||
72 | sub my_music { | ||||
73 | shift->my_home; | ||||
74 | } | ||||
75 | |||||
76 | sub my_pictures { | ||||
77 | shift->my_home; | ||||
78 | } | ||||
79 | |||||
80 | sub my_videos { | ||||
81 | shift->my_home; | ||||
82 | } | ||||
83 | |||||
- - | |||||
88 | ##################################################################### | ||||
89 | # General User Methods | ||||
90 | |||||
91 | sub users_home { | ||||
92 | my ($class, $name) = @_; | ||||
93 | |||||
94 | # IF and only if we have getpwuid support, and the | ||||
95 | # name of the user is our own, shortcut to my_home. | ||||
96 | # This is needed to handle HOME environment settings. | ||||
97 | if ( $name eq getpwuid($<) ) { | ||||
98 | return $class->my_home; | ||||
99 | } | ||||
100 | |||||
101 | SCOPE: { | ||||
102 | my $home = (getpwnam($name))[7]; | ||||
103 | return $home if $home and -d $home; | ||||
104 | } | ||||
105 | |||||
106 | return undef; | ||||
107 | } | ||||
108 | |||||
109 | sub users_desktop { | ||||
110 | shift->users_home(@_); | ||||
111 | } | ||||
112 | |||||
113 | sub users_documents { | ||||
114 | shift->users_home(@_); | ||||
115 | } | ||||
116 | |||||
117 | sub users_data { | ||||
118 | shift->users_home(@_); | ||||
119 | } | ||||
120 | |||||
121 | sub users_music { | ||||
122 | shift->users_home(@_); | ||||
123 | } | ||||
124 | |||||
125 | sub users_pictures { | ||||
126 | shift->users_home(@_); | ||||
127 | } | ||||
128 | |||||
129 | sub users_videos { | ||||
130 | shift->users_home(@_); | ||||
131 | } | ||||
132 | |||||
133 | 1 | 2µs | 1; | ||
134 | |||||
135 | =pod | ||||
136 | |||||
137 | =head1 NAME | ||||
138 | |||||
139 | File::HomeDir::Unix - Find your home and other directories on legacy Unix | ||||
140 | |||||
141 | =head1 SYNOPSIS | ||||
142 | |||||
143 | use File::HomeDir; | ||||
144 | |||||
145 | # Find directories for the current user | ||||
146 | $home = File::HomeDir->my_home; # /home/mylogin | ||||
147 | $desktop = File::HomeDir->my_desktop; # All of these will... | ||||
148 | $docs = File::HomeDir->my_documents; # ...default to home... | ||||
149 | $music = File::HomeDir->my_music; # ...directory | ||||
150 | $pics = File::HomeDir->my_pictures; # | ||||
151 | $videos = File::HomeDir->my_videos; # | ||||
152 | $data = File::HomeDir->my_data; # | ||||
153 | |||||
154 | =head1 DESCRIPTION | ||||
155 | |||||
156 | This module provides implementations for determining common user | ||||
157 | directories. In normal usage this module will always be | ||||
158 | used via L<File::HomeDir>. | ||||
159 | |||||
160 | =head1 SUPPORT | ||||
161 | |||||
162 | See the support section the main L<File::HomeDir> module. | ||||
163 | |||||
164 | =head1 AUTHORS | ||||
165 | |||||
166 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
167 | |||||
168 | Sean M. Burke E<lt>sburke@cpan.orgE<gt> | ||||
169 | |||||
170 | =head1 SEE ALSO | ||||
171 | |||||
172 | L<File::HomeDir>, L<File::HomeDir::Win32> (legacy) | ||||
173 | |||||
174 | =head1 COPYRIGHT | ||||
175 | |||||
176 | Copyright 2005 - 2011 Adam Kennedy. | ||||
177 | |||||
178 | Some parts copyright 2000 Sean M. Burke. | ||||
179 | |||||
180 | This program is free software; you can redistribute | ||||
181 | it and/or modify it under the same terms as Perl itself. | ||||
182 | |||||
183 | The full text of the license can be found in the | ||||
184 | LICENSE file included with this module. | ||||
185 | |||||
186 | =cut |