File Coverage

blib/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 69     69   662 use strict;
  69         76  
  69         1586  
18 69     69   208 use warnings;
  69         69  
  69         1585  
19 69     69   636 use utf8;
  69         82  
  69         257  
20              
21             package Devel::PerlySense::Home;
22             $Devel::PerlySense::Home::VERSION = '0.0218';
23              
24              
25 69     69   3900 use Spiffy -Base;
  69         11889  
  69         420  
26 69     69   43525 use Carp;
  69     69   87  
  69     69   1066  
  69         204  
  69         70  
  69         1437  
  69         187  
  69         67  
  69         2714  
27 69     69   240 use Data::Dumper;
  69         75  
  69         2036  
28 69     69   220 use File::Basename;
  69         82  
  69         2487  
29 69     69   236 use File::Path;
  69         75  
  69         2495  
30 69     69   584 use Path::Class;
  69         26153  
  69         2268  
31              
32 69     69   1014 use Devel::PerlySense::Util;
  69         82  
  69         19278  
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 1503 sub aDirHomeCandidate {
48             return(
49 35         42 grep { $_ } (
50             $ENV{APPDATA},
51             $ENV{ALLUSERSPROFILE},
52             $ENV{USERPROFILE},
53             $ENV{HOME},
54             $ENV{TEMP},
55             $ENV{TMP},
56 5         12 "/",
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 3 sub dirHome {
73              
74 3         5 for my $dirHome( $self->aDirHomeCandidate ) {
75 3         5 my $dir = dir($dirHome, ".PerlySense");
76 3         179 mkpath([$dir]);
77 3 50       353 -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         3 my ($dirSub) = @_;
96              
97 2 50       3 my $dirHome = $self->dirHome or return "";
98 2         54 my $dir = dir($dirHome, $dirSub);
99 2         81 mkpath([$dir]);
100 2 50       273 -d $dir or return "";
101              
102 2         54 return $dir;
103             }
104 1     1 1 1 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         2 $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 Lindstrom, C<< <johanl@cpan.org> >>
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 Lindstrom, 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