HomeDir/Darwin.pm

filter: Statementstmt 39.6% 25 / 63 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 9 / 21 Podpod 0.0% 0 / 10 totaltotal 29.8% 34 / 114 SCAR 39.6
CC
11
Cov
30%
_my_home
42.0
users_home
6.0
users_desktop
6.0
CRAP 52.3
« HomeDir/Darwin/Carbon.pm ↑ Summary HomeDir/MacOS9.pm »
1 package File::HomeDir::Darwin;
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::Unix ();
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::Unix";
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 BEGIN
14 {
15 1 ▶ $VERSION = '1.004';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 }
17  
18 #####################################################################
19 # Current User Methods
20  
21 sub _my_home
22 {
23 0 ▶ my ($class, $path) = @_;
Subroutine _my_home: not called CC=6 SCAR=37.4
24 0 my $home = $class->my_home;
25 0 ▶ return undef unless defined $home;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $home 0 0 0
26  
27 0 my $folder = "$home/$path";
28 0 ▶ unless (-d $folder)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $folder) 0 0 0
29 {
30 # Make sure that symlinks resolve to directories.
31 0 ▶ return undef unless -l $folder;
Branch: 1 branch
BranchTrueFalseTotal
unless -l $folder 0 0 0
32 0 ▶ my $dir = readlink $folder or return;
Branch: 1 branch
BranchTrueFalseTotal
my $dir = readlink $folder or return 0 0 0
33 0 ▶ return undef unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
34 }
35  
36 0 return Cwd::abs_path($folder);
37 }
38  
39 sub my_desktop
40 {
41 0 ▶ my $class = shift;
Subroutine my_desktop: not called CC=1 SCAR=6.9
Pod undocumented
42 0 $class->_my_home('Desktop');
43 }
44  
45 sub my_documents
46 {
47 0 ▶ my $class = shift;
Subroutine my_documents: not called CC=1 SCAR=6.9
Pod undocumented
48 0 $class->_my_home('Documents');
49 }
50  
51 sub my_data
52 {
53 0 ▶ my $class = shift;
Subroutine my_data: not called CC=1 SCAR=6.9
Pod undocumented
54 0 $class->_my_home('Library/Application Support');
55 }
56  
57 sub my_music
58 {
59 0 ▶ my $class = shift;
Subroutine my_music: not called CC=1 SCAR=6.9
Pod undocumented
60 0 $class->_my_home('Music');
61 }
62  
63 sub my_pictures
64 {
65 0 ▶ my $class = shift;
Subroutine my_pictures: not called CC=1 SCAR=6.9
Pod undocumented
66 0 $class->_my_home('Pictures');
67 }
68  
69 sub my_videos
70 {
71 0 ▶ my $class = shift;
Subroutine my_videos: not called CC=1 SCAR=6.9
Pod undocumented
72 0 $class->_my_home('Movies');
73 }
74  
75 #####################################################################
76 # Arbitrary User Methods
77  
78 sub users_home
79 {
80 0 ▶ my $class = shift;
Subroutine users_home: not called CC=2 SCAR=17.9
Pod undocumented
81 0 my $home = $class->SUPER::users_home(@_);
82 0 ▶ return defined $home ? Cwd::abs_path($home) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $home ? : 0 0 0
83 }
84  
85 sub users_desktop
86 {
87 0 ▶ my ($class, $name) = @_;
Subroutine users_desktop: not called CC=2 SCAR=17.9
Pod undocumented
88 0 ▶ return undef if $name eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "root" 0 0 0
89 0 $class->_to_user($class->my_desktop, $name);
90 }
91  
92 sub users_documents
93 {
94 0 ▶ my ($class, $name) = @_;
Subroutine users_documents: not called CC=2 SCAR=17.9
Pod undocumented
95 0 ▶ return undef if $name eq 'root';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "root" 0 0 0
96 0 $class->_to_user($class->my_documents, $name);
97 }
98  
99 sub users_data
100 {
101 0 ▶ my ($class, $name) = @_;
Subroutine users_data: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ $class->_to_user($class->my_data, $name)
Branch: 1 branch
BranchTrueFalseTotal
$class->_to_user($class->my_data, $name) or $class->users_home($name) 0 0 0
103 || $class->users_home($name);
104 }
105  
106 # cheap hack ... not entirely reliable, perhaps, but ... c'est la vie, since
107 # there's really no other good way to do it at this time, that i know of -- pudge
108 sub _to_user
109 {
110 0 ▶ my ($class, $path, $name) = @_;
Subroutine _to_user: not called CC=2 SCAR=17.9
111 0 my $my_home = $class->my_home;
112 0 my $users_home = $class->users_home($name);
113 0 ▶ defined $users_home or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $users_home or return undef 0 0 0
114 0 $path =~ s/^\Q$my_home/$users_home/;
115 0 return $path;
116 }
117  
118 1 1;
119  
120 =pod
121  
122 =head1 NAME
123  
124 File::HomeDir::Darwin - Find your home and other directories on Darwin (OS X)
125  
126 =head1 DESCRIPTION
127  
128 This module provides Mac OS X specific file path for determining
129 common user directories in pure perl, by just using C<$ENV{HOME}>
130 without Carbon nor Cocoa API calls. In normal usage this module will
131 always be used via L<File::HomeDir>.
132  
133 =head1 SYNOPSIS
134  
135 use File::HomeDir;
136
137 # Find directories for the current user
138 $home = File::HomeDir->my_home; # /Users/mylogin
139 $desktop = File::HomeDir->my_desktop; # /Users/mylogin/Desktop
140 $docs = File::HomeDir->my_documents; # /Users/mylogin/Documents
141 $music = File::HomeDir->my_music; # /Users/mylogin/Music
142 $pics = File::HomeDir->my_pictures; # /Users/mylogin/Pictures
143 $videos = File::HomeDir->my_videos; # /Users/mylogin/Movies
144 $data = File::HomeDir->my_data; # /Users/mylogin/Library/Application Support
145  
146 =cut
« HomeDir/Darwin/Carbon.pm ↑ Summary HomeDir/MacOS9.pm »