~ubuntu-branches/ubuntu/trusty/shutter/trusty

« back to all changes in this revision

Viewing changes to share/shutter/resources/modules/File/HomeDir/Unix.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-08-06 16:29:32 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806162932-g00c3k4obbdddb4u
Tags: 0.80.1-1
* New Upstream Version
  - update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package File::HomeDir::Unix;
 
2
 
 
3
# Unix-specific functionality
 
4
 
 
5
use 5.00503;
 
6
use strict;
 
7
use Carp                  ();
 
8
use File::HomeDir::Driver ();
 
9
 
 
10
use vars qw{$VERSION @ISA};
 
11
BEGIN {
 
12
        $VERSION = '0.86';
 
13
        @ISA     = 'File::HomeDir::Driver';
 
14
}
 
15
 
 
16
 
 
17
 
 
18
 
 
19
 
 
20
#####################################################################
 
21
# Current User Methods
 
22
 
 
23
sub my_home {
 
24
        my $class = shift;
 
25
        my $home  = $class->_my_home(@_);
 
26
 
 
27
        # On Unix in general, a non-existant home means "no home"
 
28
        # For example, "nobody"-like users might use /nonexistant
 
29
        if ( defined $home and ! -d $home ) {
 
30
                $home = undef;
 
31
        }
 
32
 
 
33
        return $home;
 
34
}
 
35
 
 
36
sub _my_home {
 
37
        my $class = shift;
 
38
        if ( exists $ENV{HOME} and defined $ENV{HOME} ) {
 
39
                return $ENV{HOME};
 
40
        }
 
41
 
 
42
        # This is from the original code, but I'm guessing
 
43
        # it means "login directory" and exists on some Unixes.
 
44
        if ( exists $ENV{LOGDIR} and $ENV{LOGDIR} ) {
 
45
                return $ENV{LOGDIR};
 
46
        }
 
47
 
 
48
        ### More-desperate methods
 
49
 
 
50
        # Light desperation on any (Unixish) platform
 
51
        SCOPE: {
 
52
                my $home = (getpwuid($<))[7];
 
53
                return $home if $home and -d $home;
 
54
        }
 
55
 
 
56
        return undef;
 
57
}
 
58
 
 
59
# On unix by default, everything is under the same folder
 
60
sub my_desktop {
 
61
        shift->my_home;
 
62
}
 
63
 
 
64
sub my_documents {
 
65
        shift->my_home;
 
66
}
 
67
 
 
68
sub my_data {
 
69
        shift->my_home;
 
70
}
 
71
 
 
72
sub my_music {
 
73
        shift->my_home;
 
74
}
 
75
 
 
76
sub my_pictures {
 
77
        shift->my_home;
 
78
}
 
79
 
 
80
sub my_videos {
 
81
        shift->my_home;
 
82
}
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
#####################################################################
 
89
# General User Methods
 
90
 
 
91
sub users_home {
 
92
        my ($class, $name) = @_;
 
93
 
 
94
        # IF and only if we have getpwuid support, and the
 
95
        # name of the user is our own, shortcut to my_home.
 
96
        # This is needed to handle HOME environment settings.
 
97
        if ( $name eq getpwuid($<) ) {
 
98
                return $class->my_home;
 
99
        }
 
100
 
 
101
        SCOPE: {
 
102
                my $home = (getpwnam($name))[7];
 
103
                return $home if $home and -d $home;
 
104
        }
 
105
 
 
106
        return undef;
 
107
}
 
108
 
 
109
sub users_desktop {
 
110
        shift->users_home(@_);
 
111
}
 
112
 
 
113
sub users_documents {
 
114
        shift->users_home(@_);
 
115
}
 
116
 
 
117
sub users_data {
 
118
        shift->users_home(@_);
 
119
}
 
120
 
 
121
sub users_music {
 
122
        shift->users_home(@_);
 
123
}
 
124
 
 
125
sub users_pictures {
 
126
        shift->users_home(@_);
 
127
}
 
128
 
 
129
sub users_videos {
 
130
        shift->users_home(@_);
 
131
}
 
132
 
 
133
1;
 
134
 
 
135
=pod
 
136
 
 
137
=head1 NAME
 
138
 
 
139
File::HomeDir::Unix - find your home and other directories, on Unix
 
140
 
 
141
=head1 DESCRIPTION
 
142
 
 
143
This module provides implementations for determining common user
 
144
directories.  In normal usage this module will always be
 
145
used via L<File::HomeDir>.
 
146
 
 
147
=head1 SYNOPSIS
 
148
 
 
149
  use File::HomeDir;
 
150
  
 
151
  # Find directories for the current user
 
152
  $home    = File::HomeDir->my_home;        # /home/mylogin
 
153
 
 
154
  $desktop = File::HomeDir->my_desktop;     # All of these will... 
 
155
  $docs    = File::HomeDir->my_documents;   # ...default to home...
 
156
  $music   = File::HomeDir->my_music;       # ...directory at the...
 
157
  $pics    = File::HomeDir->my_pictures;    # ...moment.
 
158
  $videos  = File::HomeDir->my_videos;      #
 
159
  $data    = File::HomeDir->my_data;        # 
 
160
 
 
161
=head1 TODO
 
162
 
 
163
=over 4
 
164
 
 
165
=item * Add support for common unix desktop and data directories when using KDE / Gnome / ...
 
166
 
 
167
=back