| 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 | ▶ | use 5.008003; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Cwd (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use File::HomeDir::Darwin (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | ▶ | use base "File::HomeDir::Darwin"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | BEGIN | ||||||||||||||||||||
| 21 | { | ||||||||||||||||||||
| 22 | 1 | ▶ | $VERSION = '1.004'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | # Load early if in a forking environment and we have | ||||||||||||||||||||
| 25 | # prefork, or at run-time if not. | ||||||||||||||||||||
| 26 | 1 | local $@; ## no critic (Variables::RequireInitializationForLocalVars) | |||||||||||||||||||
| 27 | 1 | ▶ | eval "use prefork 'Mac::Files'"; ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | ##################################################################### | ||||||||||||||||||||
| 31 | # Current User Methods | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | ## no critic qw(UnusedPrivateSubroutines) | ||||||||||||||||||||
| 34 | sub _guess_determined_home | ||||||||||||||||||||
| 35 | { | ||||||||||||||||||||
| 36 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
_guess_determined_home: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | require Mac::Files; | |||||||||||||||||||
| 39 | 0 | my $home = $class->_find_folder(Mac::Files::kCurrentUserFolderType(),); | |||||||||||||||||||
| 40 | 0 | ▶ | $home ||= $class->SUPER::_guess_determined_home($@); | ||||||||||||||||||
|
Condition0%0/3
$home ||= $class->SUPER::_guess_determined_home($@)
MC/DC0%0/2
$home ||= $class->SUPER::_guess_determined_home($@)
$home
$class->SUPER::_guess_determined_home($@)
Truth table0%0/3
A ||= B
A= $homeB= $class->SUPER::_guess_determined_home($@)
| |||||||||||||||||||||
| 41 | 0 | return $home; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub my_desktop | ||||||||||||||||||||
| 45 | { | ||||||||||||||||||||
| 46 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_desktop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | require Mac::Files; | |||||||||||||||||||
| 49 | 0 | $class->_find_folder(Mac::Files::kDesktopFolderType(),); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub my_documents | ||||||||||||||||||||
| 53 | { | ||||||||||||||||||||
| 54 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_documents: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | require Mac::Files; | |||||||||||||||||||
| 57 | 0 | $class->_find_folder(Mac::Files::kDocumentsFolderType(),); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | sub my_data | ||||||||||||||||||||
| 61 | { | ||||||||||||||||||||
| 62 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | require Mac::Files; | |||||||||||||||||||
| 65 | 0 | $class->_find_folder(Mac::Files::kApplicationSupportFolderType(),); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | sub my_music | ||||||||||||||||||||
| 69 | { | ||||||||||||||||||||
| 70 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_music: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | require Mac::Files; | |||||||||||||||||||
| 73 | 0 | $class->_find_folder(Mac::Files::kMusicDocumentsFolderType(),); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub my_pictures | ||||||||||||||||||||
| 77 | { | ||||||||||||||||||||
| 78 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_pictures: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | require Mac::Files; | |||||||||||||||||||
| 81 | 0 | $class->_find_folder(Mac::Files::kPictureDocumentsFolderType(),); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | sub my_videos | ||||||||||||||||||||
| 85 | { | ||||||||||||||||||||
| 86 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_videos: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | require Mac::Files; | |||||||||||||||||||
| 89 | 0 | $class->_find_folder(Mac::Files::kMovieDocumentsFolderType(),); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | sub _find_folder | ||||||||||||||||||||
| 93 | { | ||||||||||||||||||||
| 94 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
_find_folder: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 95 | 0 | my $name = shift; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | require Mac::Files; | |||||||||||||||||||
| 98 | 0 | my $folder = Mac::Files::FindFolder(Mac::Files::kUserDomain(), $name,); | |||||||||||||||||||
| 99 | 0 | ▶ | return undef unless defined $folder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | unless (-d $folder) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | { | ||||||||||||||||||||
| 103 | # Make sure that symlinks resolve to directories. | ||||||||||||||||||||
| 104 | 0 | ▶ | return undef unless -l $folder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 0 | ▶ | my $dir = readlink $folder or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | ▶ | return undef unless -d $dir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | return Cwd::abs_path($folder); | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | ##################################################################### | ||||||||||||||||||||
| 113 | # Arbitrary User Methods | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | sub users_home | ||||||||||||||||||||
| 116 | { | ||||||||||||||||||||
| 117 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
users_home: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 118 | 0 | my $home = $class->SUPER::users_home(@_); | |||||||||||||||||||
| 119 | 0 | ▶ | return defined $home ? Cwd::abs_path($home) : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | my ($class, $name) = @_; | ||||||||||||||||||
|
Subroutine
users_desktop: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 127 | 0 | ▶ | return undef if $name eq 'root'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 0 | $class->_to_user($class->my_desktop, $name); | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | sub users_documents | ||||||||||||||||||||
| 132 | { | ||||||||||||||||||||
| 133 | 0 | ▶ | my ($class, $name) = @_; | ||||||||||||||||||
|
Subroutine
users_documents: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 134 | 0 | ▶ | return undef if $name eq 'root'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | 0 | $class->_to_user($class->my_documents, $name); | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | sub users_data | ||||||||||||||||||||
| 139 | { | ||||||||||||||||||||
| 140 | 0 | ▶ | my ($class, $name) = @_; | ||||||||||||||||||
|
Subroutine
users_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 141 | 0 | ▶ | $class->_to_user($class->my_data, $name) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | my ($class, $path, $name) = @_; | ||||||||||||||||||
|
Subroutine
_to_user: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 150 | 0 | my $my_home = $class->my_home; | |||||||||||||||||||
| 151 | 0 | my $users_home = $class->users_home($name); | |||||||||||||||||||
| 152 | 0 | ▶ | defined $users_home or return undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | 0 | $path =~ s/^\Q$my_home/$users_home/; | |||||||||||||||||||
| 154 | 0 | return $path; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 1 | 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<File::HomeDir>. | ||||||||||||||||||||
| 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<File::HomeDir::Darwin::Cocoa> and then fall back to the (pure Perl) | ||||||||||||||||||||
| 174 | L<File::HomeDir::Darwin>. | ||||||||||||||||||||
| 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 | ||||||||||||||||||||