HomeDir/Unix.pm

filter: Statementstmt 81.9% 50 / 61 Branchbran 58.3% 7 / 12 Conditioncond 42.8% 9 / 21 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 76.0% 19 / 25 Podpod 0.0% 0 / 14 totaltotal 58.9% 86 / 146 SCAR 29.5
CC
14
Cov
70%
_guess_env_home
7.8
users_home
5.3
my_home
3.6
CRAP 19.2
« HomeDir/MacOS9.pm ↑ Summary HomeDir/Test.pm »
1 package File::HomeDir::Unix;
2  
3 # See POD at the end of the file for documentation
4  
5 6 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use File::HomeDir::Driver ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use base "File::HomeDir::Driver";
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 BEGIN
15 {
16 6 ▶ $VERSION = '1.004';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 }
18  
19 #####################################################################
20 # Current User Methods
21  
22 sub my_home
23 {
24 17 ▶ my $class = shift;
Subroutine my_home: called CC=3 SCAR=12.7
Pod undocumented
25 17 my $home = $class->_guess_home(@_);
26  
27 # On Unix in general, a non-existent home means "no home"
28 # For example, "nobody"-like users might use /nonexistent
29 17 ▶ if (defined $home and not -d $home)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $home and not -d $home) 0 17 17
Condition33%1/3
defined $home and not -d $home
!ll&&!rl&&r
0170
MC/DC0%0/2
defined $home and not -d $home
defined $home not -d $home
Truth table33%1/3
A and not(B)
A= defined $homeB= not -d $home
ABresult
0X0
100
111
30 {
31 0 $home = undef;
32 }
33  
34 17 return $home;
35 }
36  
37 sub _guess_env_home
38 {
39 17 ▶ my $class = shift;
Subroutine _guess_env_home: called CC=6 SCAR=20.5
40 17 ▶ if (exists $ENV{HOME} and defined $ENV{HOME} and length $ENV{HOME})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"HOME"} and defined $ENV{"HOME"} and length $ENV{"HOME"}) 16 1 17
Condition50%3/6
exists $ENV{"HOME"} and defined $ENV{"HOME"} and length $ENV{"HOME"}
!ll&&!rl&&r
0116
exists $ENV{"HOME"} and defined $ENV{"HOME"}
!ll&&!rl&&r
0017
MC/DC33%1/3
exists $ENV{"HOME"} and defined $ENV{"HOME"} and length $ENV{"HOME"}
exists $ENV{"HOME"} defined $ENV{"HOME"} length $ENV{"HOME"}
Truth table50%2/4
A and B and C
A= exists $ENV{"HOME"}B= defined $ENV{"HOME"}C= length $ENV{"HOME"}
ABCresult
0XX0
10X0
1100
1111
41 {
42 16 return $ENV{HOME};
43 }
44  
45 # This is from the original code, but I'm guessing
46 # it means "login directory" and exists on some Unixes.
47 1 ▶ if (exists $ENV{LOGDIR} and $ENV{LOGDIR})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"LOGDIR"} and $ENV{"LOGDIR"}) 0 1 1
Condition33%1/3
exists $ENV{"LOGDIR"} and $ENV{"LOGDIR"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $ENV{"LOGDIR"} and $ENV{"LOGDIR"}
exists $ENV{"LOGDIR"} $ENV{"LOGDIR"}
Truth table33%1/3
A and B
A= exists $ENV{"LOGDIR"}B= $ENV{"LOGDIR"}
ABresult
0X0
100
111
48 {
49 0 return $ENV{LOGDIR};
50 }
51  
52 1 return;
53 }
54  
55 sub _guess_determined_home
56 {
57 1 ▶ my $class = shift;
Subroutine _guess_determined_home: called CC=3 SCAR=12.7
58  
59 # Light desperation on any (Unixish) platform
60 SCOPE:
61 {
62 1 my $home = (getpwuid($<))[7];
63 1 ▶ return $home if $home and -d $home;
Branch: 1 branch
BranchTrueFalseTotal
if $home and -d $home 1 0 1
Condition33%1/3
$home and -d $home
!ll&&!rl&&r
001
MC/DC0%0/2
$home and -d $home
$home -d $home
Truth table33%1/3
A and B
A= $homeB= -d $home
ABresult
0X0
100
111
64 }
65  
66 0 return;
67 }
68  
69 sub _guess_home
70 {
71 17 ▶ my $class = shift;
Subroutine _guess_home: called CC=2 SCAR=7.0
72 17 my $home = $class->_guess_env_home($@);
73 17 ▶ $home ||= $class->_guess_determined_home($@);
Condition66%2/3
$home ||= $class->_guess_determined_home($@)
l!l&&r!l&&!r
1610
MC/DC0%0/2
$home ||= $class->_guess_determined_home($@)
$home $class->_guess_determined_home($@)
Truth table66%2/3
A ||= B
A= $homeB= $class->_guess_determined_home($@)
ABresult
1X1
011
000
74 17 return $home;
75 }
76  
77 # On unix by default, everything is under the same folder
78 sub my_desktop
79 {
80 2 ▶ shift->my_home;
Subroutine my_desktop: called CC=1 SCAR=0.0
Pod undocumented
81 }
82  
83 sub my_documents
84 {
85 2 ▶ shift->my_home;
Subroutine my_documents: called CC=1 SCAR=0.0
Pod undocumented
86 }
87  
88 sub my_data
89 {
90 2 ▶ shift->my_home;
Subroutine my_data: called CC=1 SCAR=0.0
Pod undocumented
91 }
92  
93 sub my_music
94 {
95 2 ▶ shift->my_home;
Subroutine my_music: called CC=1 SCAR=0.0
Pod undocumented
96 }
97  
98 sub my_pictures
99 {
100 2 ▶ shift->my_home;
Subroutine my_pictures: called CC=1 SCAR=0.0
Pod undocumented
101 }
102  
103 sub my_videos
104 {
105 2 ▶ shift->my_home;
Subroutine my_videos: called CC=1 SCAR=0.0
Pod undocumented
106 }
107  
108 #####################################################################
109 # General User Methods
110  
111 sub users_home
112 {
113 1 ▶ my ($class, $name) = @_;
Subroutine users_home: called CC=4 SCAR=16.6
Pod undocumented
114  
115 # IF and only if we have getpwuid support, and the
116 # name of the user is our own, shortcut to my_home.
117 # This is needed to handle HOME environment settings.
118 1 ▶ if ($name eq getpwuid($<))
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq getpwuid $<) 0 1 1
119 {
120 0 return $class->my_home;
121 }
122  
123 SCOPE:
124 {
125 1 my $home = (getpwnam($name))[7];
126 1 ▶ return $home if $home and -d $home;
Branch: 1 branch
BranchTrueFalseTotal
if $home and -d $home 1 0 1
Condition33%1/3
$home and -d $home
!ll&&!rl&&r
001
MC/DC0%0/2
$home and -d $home
$home -d $home
Truth table33%1/3
A and B
A= $homeB= -d $home
ABresult
0X0
100
111
127 }
128  
129 0 return undef;
130 }
131  
132 sub users_desktop
133 {
134 0 ▶ shift->users_home(@_);
Subroutine users_desktop: not called CC=1 SCAR=6.9
Pod undocumented
135 }
136  
137 sub users_documents
138 {
139 0 ▶ shift->users_home(@_);
Subroutine users_documents: not called CC=1 SCAR=6.9
Pod undocumented
140 }
141  
142 sub users_data
143 {
144 0 ▶ shift->users_home(@_);
Subroutine users_data: not called CC=1 SCAR=6.9
Pod undocumented
145 }
146  
147 sub users_music
148 {
149 0 ▶ shift->users_home(@_);
Subroutine users_music: not called CC=1 SCAR=6.9
Pod undocumented
150 }
151  
152 sub users_pictures
153 {
154 0 ▶ shift->users_home(@_);
Subroutine users_pictures: not called CC=1 SCAR=6.9
Pod undocumented
155 }
156  
157 sub users_videos
158 {
159 0 ▶ shift->users_home(@_);
Subroutine users_videos: not called CC=1 SCAR=6.9
Pod undocumented
160 }
161  
162 6 1;
163  
164 =pod
165  
166 =head1 NAME
167  
168 File::HomeDir::Unix - Find your home and other directories on legacy Unix
169  
170 =head1 SYNOPSIS
171  
172 use File::HomeDir;
173
174 # Find directories for the current user
175 $home = File::HomeDir->my_home; # /home/mylogin
176 $desktop = File::HomeDir->my_desktop; # All of these will...
177 $docs = File::HomeDir->my_documents; # ...default to home...
178 $music = File::HomeDir->my_music; # ...directory
179 $pics = File::HomeDir->my_pictures; #
180 $videos = File::HomeDir->my_videos; #
181 $data = File::HomeDir->my_data; #
182  
183 =head1 DESCRIPTION
184  
185 This module provides implementations for determining common user
186 directories. In normal usage this module will always be
187 used via L<File::HomeDir>.
188  
189 =head1 SUPPORT
190  
191 See the support section the main L<File::HomeDir> module.
192  
193 =head1 AUTHORS
194  
195 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
196  
197 Sean M. Burke E<lt>sburke@cpan.orgE<gt>
198  
199 =head1 SEE ALSO
200  
201 L<File::HomeDir>, L<File::HomeDir::Win32> (legacy)
202  
203 =head1 COPYRIGHT
204  
205 Copyright 2005 - 2011 Adam Kennedy.
206  
207 Some parts copyright 2000 Sean M. Burke.
208  
209 This program is free software; you can redistribute
210 it and/or modify it under the same terms as Perl itself.
211  
212 The full text of the license can be found in the
213 LICENSE file included with this module.
214  
215 =cut
« HomeDir/MacOS9.pm ↑ Summary HomeDir/Test.pm »