Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/File/HomeDir/Darwin.pm |
Statements | Executed 15 statements in 609µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 502µs | 849µs | BEGIN@7 | File::HomeDir::Darwin::
1 | 1 | 1 | 14µs | 14µs | BEGIN@3 | File::HomeDir::Darwin::
1 | 1 | 1 | 9µs | 9µs | BEGIN@10 | File::HomeDir::Darwin::
1 | 1 | 1 | 7µs | 36µs | BEGIN@9 | File::HomeDir::Darwin::
1 | 1 | 1 | 6µs | 17µs | BEGIN@4 | File::HomeDir::Darwin::
1 | 1 | 1 | 3µs | 3µs | BEGIN@5 | File::HomeDir::Darwin::
1 | 1 | 1 | 3µs | 3µs | BEGIN@6 | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | _my_home | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | _to_user | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_data | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_desktop | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_documents | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_home | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_music | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_pictures | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | my_videos | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | users_data | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | users_desktop | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | users_documents | File::HomeDir::Darwin::
0 | 0 | 0 | 0s | 0s | users_home | File::HomeDir::Darwin::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package File::HomeDir::Darwin; | ||||
2 | |||||
3 | 2 | 41µs | 1 | 14µs | # spent 14µs within File::HomeDir::Darwin::BEGIN@3 which was called:
# once (14µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 3 # spent 14µs making 1 call to File::HomeDir::Darwin::BEGIN@3 |
4 | 2 | 18µs | 2 | 28µs | # spent 17µs (6+11) within File::HomeDir::Darwin::BEGIN@4 which was called:
# once (6µs+11µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 4 # spent 17µs making 1 call to File::HomeDir::Darwin::BEGIN@4
# spent 11µs making 1 call to strict::import |
5 | 2 | 15µs | 1 | 3µs | # spent 3µs within File::HomeDir::Darwin::BEGIN@5 which was called:
# once (3µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 5 # spent 3µs making 1 call to File::HomeDir::Darwin::BEGIN@5 |
6 | 2 | 19µs | 1 | 3µs | # spent 3µs within File::HomeDir::Darwin::BEGIN@6 which was called:
# once (3µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 6 # spent 3µs making 1 call to File::HomeDir::Darwin::BEGIN@6 |
7 | 2 | 84µs | 1 | 849µs | # spent 849µs (502+347) within File::HomeDir::Darwin::BEGIN@7 which was called:
# once (502µs+347µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 7 # spent 849µs making 1 call to File::HomeDir::Darwin::BEGIN@7 |
8 | |||||
9 | 2 | 29µs | 2 | 64µs | # spent 36µs (7+29) within File::HomeDir::Darwin::BEGIN@9 which was called:
# once (7µs+29µs) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 9 # spent 36µs making 1 call to File::HomeDir::Darwin::BEGIN@9
# spent 29µs making 1 call to vars::import |
10 | # spent 9µs within File::HomeDir::Darwin::BEGIN@10 which was called:
# once (9µs+0s) by File::HomeDir::Darwin::Cocoa::BEGIN@7 at line 13 | ||||
11 | 1 | 300ns | $VERSION = '1.00'; | ||
12 | 1 | 9µs | @ISA = 'File::HomeDir::Unix'; | ||
13 | 1 | 393µs | 1 | 9µs | } # spent 9µs making 1 call to File::HomeDir::Darwin::BEGIN@10 |
14 | |||||
- - | |||||
19 | ##################################################################### | ||||
20 | # Current User Methods | ||||
21 | |||||
22 | sub my_home { | ||||
23 | my $class = shift; | ||||
24 | |||||
25 | if ( exists $ENV{HOME} and defined $ENV{HOME} ) { | ||||
26 | return $ENV{HOME}; | ||||
27 | } | ||||
28 | |||||
29 | my $home = (getpwuid($<))[7]; | ||||
30 | return $home if $home && -d $home; | ||||
31 | |||||
32 | return undef; | ||||
33 | } | ||||
34 | |||||
35 | sub _my_home { | ||||
36 | my($class, $path) = @_; | ||||
37 | my $home = $class->my_home; | ||||
38 | return undef unless defined $home; | ||||
39 | |||||
40 | my $folder = "$home/$path"; | ||||
41 | unless ( -d $folder ) { | ||||
42 | # Make sure that symlinks resolve to directories. | ||||
43 | return undef unless -l $folder; | ||||
44 | my $dir = readlink $folder or return; | ||||
45 | return undef unless -d $dir; | ||||
46 | } | ||||
47 | |||||
48 | return Cwd::abs_path($folder); | ||||
49 | } | ||||
50 | |||||
51 | sub my_desktop { | ||||
52 | my $class = shift; | ||||
53 | $class->_my_home('Desktop'); | ||||
54 | } | ||||
55 | |||||
56 | sub my_documents { | ||||
57 | my $class = shift; | ||||
58 | $class->_my_home('Documents'); | ||||
59 | } | ||||
60 | |||||
61 | sub my_data { | ||||
62 | my $class = shift; | ||||
63 | $class->_my_home('Library/Application Support'); | ||||
64 | } | ||||
65 | |||||
66 | sub my_music { | ||||
67 | my $class = shift; | ||||
68 | $class->_my_home('Music'); | ||||
69 | } | ||||
70 | |||||
71 | sub my_pictures { | ||||
72 | my $class = shift; | ||||
73 | $class->_my_home('Pictures'); | ||||
74 | } | ||||
75 | |||||
76 | sub my_videos { | ||||
77 | my $class = shift; | ||||
78 | $class->_my_home('Movies'); | ||||
79 | } | ||||
80 | |||||
- - | |||||
85 | ##################################################################### | ||||
86 | # Arbitrary User Methods | ||||
87 | |||||
88 | sub users_home { | ||||
89 | my $class = shift; | ||||
90 | my $home = $class->SUPER::users_home(@_); | ||||
91 | return defined $home ? Cwd::abs_path($home) : undef; | ||||
92 | } | ||||
93 | |||||
94 | sub users_desktop { | ||||
95 | my ($class, $name) = @_; | ||||
96 | return undef if $name eq 'root'; | ||||
97 | $class->_to_user( $class->my_desktop, $name ); | ||||
98 | } | ||||
99 | |||||
100 | sub users_documents { | ||||
101 | my ($class, $name) = @_; | ||||
102 | return undef if $name eq 'root'; | ||||
103 | $class->_to_user( $class->my_documents, $name ); | ||||
104 | } | ||||
105 | |||||
106 | sub users_data { | ||||
107 | my ($class, $name) = @_; | ||||
108 | $class->_to_user( $class->my_data, $name ) | ||||
109 | || | ||||
110 | $class->users_home($name); | ||||
111 | } | ||||
112 | |||||
113 | # cheap hack ... not entirely reliable, perhaps, but ... c'est la vie, since | ||||
114 | # there's really no other good way to do it at this time, that i know of -- pudge | ||||
115 | sub _to_user { | ||||
116 | my ($class, $path, $name) = @_; | ||||
117 | my $my_home = $class->my_home; | ||||
118 | my $users_home = $class->users_home($name); | ||||
119 | defined $users_home or return undef; | ||||
120 | $path =~ s/^\Q$my_home/$users_home/; | ||||
121 | return $path; | ||||
122 | } | ||||
123 | |||||
124 | 1 | 2µs | 1; | ||
125 | |||||
126 | =pod | ||||
127 | |||||
128 | =head1 NAME | ||||
129 | |||||
130 | File::HomeDir::Darwin - Find your home and other directories on Darwin (OS X) | ||||
131 | |||||
132 | =head1 DESCRIPTION | ||||
133 | |||||
134 | This module provides Mac OS X specific file path for determining | ||||
135 | common user directories in pure perl, by just using C<$ENV{HOME}> | ||||
136 | without Carbon nor Cocoa API calls. In normal usage this module will | ||||
137 | always be used via L<File::HomeDir>. | ||||
138 | |||||
139 | =head1 SYNOPSIS | ||||
140 | |||||
141 | use File::HomeDir; | ||||
142 | |||||
143 | # Find directories for the current user | ||||
144 | $home = File::HomeDir->my_home; # /Users/mylogin | ||||
145 | $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop | ||||
146 | $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents | ||||
147 | $music = File::HomeDir->my_music; # /Users/mylogin/Music | ||||
148 | $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures | ||||
149 | $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies | ||||
150 | $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support | ||||
151 | |||||
152 | =cut |