| 1 | package File::HomeDir::Darwin::Cocoa; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008003; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Cwd (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use File::HomeDir::Darwin (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use base "File::HomeDir::Darwin"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | BEGIN | ||||||||||||||||||||
| 14 | { | ||||||||||||||||||||
| 15 | 1 | ▶ | $VERSION = '1.004'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # Load early if in a forking environment and we have | ||||||||||||||||||||
| 18 | # prefork, or at run-time if not. | ||||||||||||||||||||
| 19 | 1 | local $@; ## no critic (Variables::RequireInitializationForLocalVars) | |||||||||||||||||||
| 20 | 1 | ▶ | eval "use prefork 'Mac::SystemDirectory'"; ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | ##################################################################### | ||||||||||||||||||||
| 24 | # Current User Methods | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | ## no critic qw(UnusedPrivateSubroutines) | ||||||||||||||||||||
| 27 | sub _guess_determined_home | ||||||||||||||||||||
| 28 | { | ||||||||||||||||||||
| 29 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
_guess_determined_home: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 32 | 0 | my $home = Mac::SystemDirectory::HomeDirectory(); | |||||||||||||||||||
| 33 | 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($@)
| |||||||||||||||||||||
| 34 | 0 | return $home; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # from 10.4 | ||||||||||||||||||||
| 38 | sub my_desktop | ||||||||||||||||||||
| 39 | { | ||||||||||||||||||||
| 40 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_desktop: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 43 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSDesktopDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | || $class->SUPER::my_desktop; | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # from 10.2 | ||||||||||||||||||||
| 48 | sub my_documents | ||||||||||||||||||||
| 49 | { | ||||||||||||||||||||
| 50 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_documents: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 53 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSDocumentDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | || $class->SUPER::my_documents; | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # from 10.4 | ||||||||||||||||||||
| 58 | sub my_data | ||||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 63 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSApplicationSupportDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | || $class->SUPER::my_data; | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # from 10.6 | ||||||||||||||||||||
| 68 | sub my_music | ||||||||||||||||||||
| 69 | { | ||||||||||||||||||||
| 70 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_music: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 73 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSMusicDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | || $class->SUPER::my_music; | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # from 10.6 | ||||||||||||||||||||
| 78 | sub my_pictures | ||||||||||||||||||||
| 79 | { | ||||||||||||||||||||
| 80 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_pictures: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 83 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSPicturesDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | || $class->SUPER::my_pictures; | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | # from 10.6 | ||||||||||||||||||||
| 88 | sub my_videos | ||||||||||||||||||||
| 89 | { | ||||||||||||||||||||
| 90 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
my_videos: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 93 | 0 | ▶ | eval { $class->_find_folder(Mac::SystemDirectory::NSMoviesDirectory()) } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | || $class->SUPER::my_videos; | ||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | sub _find_folder | ||||||||||||||||||||
| 98 | { | ||||||||||||||||||||
| 99 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
_find_folder: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 100 | 0 | my $name = shift; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | require Mac::SystemDirectory; | |||||||||||||||||||
| 103 | 0 | my $folder = Mac::SystemDirectory::FindDirectory($name); | |||||||||||||||||||
| 104 | 0 | ▶ | return undef unless defined $folder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | unless (-d $folder) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | { | ||||||||||||||||||||
| 108 | # Make sure that symlinks resolve to directories. | ||||||||||||||||||||
| 109 | 0 | ▶ | return undef unless -l $folder; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | ▶ | my $dir = readlink $folder or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | ▶ | return undef unless -d $dir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | return Cwd::abs_path($folder); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | 1; | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =pod | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head1 NAME | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | File::HomeDir::Darwin::Cocoa - Find your home and other directories on Darwin (OS X) | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 DESCRIPTION | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | This module provides Darwin-specific implementations for determining | ||||||||||||||||||||
| 128 | common user directories using Cocoa API through | ||||||||||||||||||||
| 129 | L<Mac::SystemDirectory>. In normal usage this module will always be | ||||||||||||||||||||
| 130 | used via L<File::HomeDir>. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | Theoretically, this should return the same paths as both of the other | ||||||||||||||||||||
| 133 | Darwin drivers. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | Because this module requires L<Mac::SystemDirectory>, if the module | ||||||||||||||||||||
| 136 | is not installed, L<File::HomeDir> will fall back to L<File::HomeDir::Darwin>. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 SYNOPSIS | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | use File::HomeDir; | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | # Find directories for the current user | ||||||||||||||||||||
| 143 | $home = File::HomeDir->my_home; # /Users/mylogin | ||||||||||||||||||||
| 144 | $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop | ||||||||||||||||||||
| 145 | $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents | ||||||||||||||||||||
| 146 | $music = File::HomeDir->my_music; # /Users/mylogin/Music | ||||||||||||||||||||
| 147 | $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures | ||||||||||||||||||||
| 148 | $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies | ||||||||||||||||||||
| 149 | $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||