File Coverage

lib/Devel/PerlySense/Home.pm
Criterion Covered Total %
statement 55 56 98.2
branch 3 6 50.0
condition n/a
subroutine 17 17 100.0
pod 4 4 100.0
total 79 83 95.1


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Devel::PerlySense::Home - A User Home root directory
4              
5              
6             =head1 DESCRIPTION
7              
8             The User Home is the place where User specific settings/cache,
9             etc. are kept.
10              
11             =cut
12              
13              
14              
15              
16              
17 64     64   223 use strict;
  64         104  
  64         1832  
18 64     64   215 use warnings;
  64         71  
  64         1515  
19 64     64   616 use utf8;
  64         78  
  64         245  
20              
21             package Devel::PerlySense::Home;
22              
23              
24              
25 64     64   3255 use Spiffy -Base;
  64         28645  
  64         414  
26 64     64   45655 use Carp;
  64     64   73  
  64     64   1691  
  64         212  
  64         68  
  64         1296  
  64         220  
  64         73  
  64         3348  
27 64     64   230 use Data::Dumper;
  64         101  
  64         2589  
28 64     64   245 use File::Basename;
  64         77  
  64         6100  
29 64     64   236 use File::Path;
  64         86  
  64         2779  
30 64     64   471 use Path::Class;
  64         29739  
  64         2611  
31              
32 64     64   1115 use Devel::PerlySense::Util;
  64         69  
  64         22690  
33              
34              
35              
36              
37              
38             =head1 PROPERTIES
39              
40             =head2 aDirHomeCandidate
41              
42             List of candidates for User Home root dirs.
43              
44             Readonly.
45              
46             =cut
47 5     5 1 2 sub aDirHomeCandidate {
48             return(
49 5         12 grep { $_ } (
  35         45  
50             $ENV{APPDATA},
51             $ENV{ALLUSERSPROFILE},
52             $ENV{USERPROFILE},
53             $ENV{HOME},
54             $ENV{TEMP},
55             $ENV{TMP},
56             "/",
57             ),
58             );
59             }
60              
61              
62              
63              
64              
65             =head2 dirHome
66              
67             The User Home root dir, or "" if no home dir could be identified.
68              
69             Readonly.
70              
71             =cut
72 3     3 1 2 sub dirHome {
73              
74 3         5 for my $dirHome( $self->aDirHomeCandidate ) {
75 3         5 my $dir = dir($dirHome, ".PerlySense");
76 3         236 mkpath([$dir]);
77 3 50       486 -d $dir and return $dir;
78             }
79              
80 0         0 return "";
81             }
82              
83              
84              
85              
86              
87             =head2 dirHomeCache
88              
89             The User Home cache dir, or "" if no home dir could be identified.
90              
91             Readonly.
92              
93             =cut
94 2     2   2 sub _dirSubHomeCreate {
95 2         2 my ($dirSub) = @_;
96              
97 2 50       3 my $dirHome = $self->dirHome or return "";
98 2         59 my $dir = dir($dirHome, $dirSub);
99 2         119 mkpath([$dir]);
100 2 50       310 -d $dir or return "";
101              
102 2         57 return $dir;
103             }
104 1     1 1 3 sub dirHomeCache {
105 1         2 $self->_dirSubHomeCreate("cache");
106             }
107              
108              
109              
110              
111              
112             =head2 dirHomeLog
113              
114             The User Home log dir, or "" if no home dir could be identified.
115              
116             Readonly.
117              
118             =cut
119 1     1 1 1 sub dirHomeLog {
120 1         3 $self->_dirSubHomeCreate("log");
121             }
122              
123              
124              
125              
126              
127             1;
128              
129              
130              
131              
132              
133             __END__
134              
135             =encoding utf8
136              
137             =head1 AUTHOR
138              
139             Johan Lindström, C<< <johanl[ÄT]DarSerMan.com> >>
140              
141             =head1 BUGS
142              
143             Please report any bugs or feature requests to
144             C<bug-devel-perlysense@rt.cpan.org>, or through the web interface at
145             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense>.
146             I will be notified, and then you'll automatically be notified of progress on
147             your bug as I make changes.
148              
149             =head1 ACKNOWLEDGEMENTS
150              
151             =head1 COPYRIGHT & LICENSE
152              
153             Copyright 2005 Johan Lindström, All Rights Reserved.
154              
155             This program is free software; you can redistribute it and/or modify it
156             under the same terms as Perl itself.
157              
158             =cut