File Coverage

blib/lib/Portable/HomeDir.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 8 0.0
condition 0 3 0.0
subroutine 4 14 28.5
pod 0 9 0.0
total 16 74 21.6


line stmt bran cond sub pod time code
1             package Portable::HomeDir;
2            
3             # In the trivial case, only my_home is implemented
4            
5 1     1   829 use 5.008;
  1         4  
  1         35  
6 1     1   5 use strict;
  1         1  
  1         28  
7 1     1   5 use warnings;
  1         1  
  1         22  
8 1     1   4 use Portable::FileSpec;
  1         1  
  1         445  
9            
10             our $VERSION = '1.22';
11            
12             #####################################################################
13             # Portable Driver API
14            
15             sub new {
16 0     0 0   my $class = shift;
17 0           my $parent = shift;
18 0 0         unless ( Portable::_HASH($parent->portable_homedir) ) {
19 0           die('Missing or invalid HomeDir key in portable.perl');
20             }
21            
22             # Create the object
23 0           my $self = bless { }, $class;
24            
25             # Map the
26 0           my $homedir = $parent->portable_homedir;
27 0           my $root = $parent->dist_root;
28 0           foreach my $key ( sort keys %$homedir ) {
29 0 0 0       unless (
30             defined $homedir->{$key}
31             and
32             length $homedir->{$key}
33             ) {
34 0           $self->{$key} = $homedir->{$key};
35 0           next;
36             }
37 0           $self->{$key} = Portable::FileSpec::catdir(
38             $root, split /\//, $homedir->{$key}
39             );
40             }
41            
42 0           return $self;
43             }
44            
45             sub apply {
46 0     0 0   my $self = shift;
47            
48             # Shortcut if we've already applied
49 0 0         if ( $File::HomeDir::IMPLEMENTED_BY eq __PACKAGE__ ) {
50 0           return 1;
51             }
52            
53             # Load File::HomeDir and the regular platform driver
54 0           require File::HomeDir;
55            
56             # Remember the platform we're on so we can default
57             # to it properly if there's no portable equivalent.
58 0           $self->{platform} = $File::HomeDir::IMPLEMENTED_BY;
59            
60             # Hijack the implementation class to us
61 0           $File::HomeDir::IMPLEMENTED_BY = __PACKAGE__;
62            
63 0           return 1;
64             }
65            
66             sub platform {
67 0     0 0   $_[0]->{platform};
68             }
69            
70            
71            
72            
73            
74             #####################################################################
75             # File::HomeDir::Driver API
76            
77             sub _SELF {
78 0 0   0     ref($_[0]) ? $_[0] : Portable->default->homedir;
79             }
80            
81             sub my_home {
82 0     0 0   _SELF(@_)->{my_home};
83             }
84            
85             # The concept of "my_desktop" is incompatible with the idea of
86             # a Portable Perl distribution (because Windows won't overwrite
87             # the desktop with anything on the flash drive)
88             # sub my_desktop
89            
90             sub my_documents {
91 0     0 0   _SELF(@_)->{my_documents};
92             }
93            
94             sub my_music {
95 0     0 0   _SELF(@_)->{my_music};
96             }
97            
98             sub my_pictures {
99 0     0 0   _SELF(@_)->{my_pictures};
100             }
101            
102             sub my_videos {
103 0     0 0   _SELF(@_)->{my_videos};
104             }
105            
106             sub my_data {
107 0     0 0   _SELF(@_)->{my_data};
108             }
109            
110             1;