Removed /usr/local from CDPATH
[clearscm.git] / lib / OSDep.pm
1 =pod
2
3 =head1 NAME $RCSfile: OSDep.pm,v $
4
5 Isolate OS dependencies
6
7 =head1 VERSION
8
9 =over
10
11 =item Author
12
13 Andrew DeFaria <Andrew@ClearSCM.com>
14
15 =item Revision
16
17 $Revision: 1.12 $
18
19 =item Created
20
21 Tue Jan  3 11:36:10 PST 2006
22
23 =item Modified
24
25 $Date: 2011/11/16 19:46:13 $
26
27 =back
28
29 =head1 SYNOPSIS
30
31 This module seeks to isolate OS dependences by confining them to this
32 module as well as provide convienent references and mechanisms for
33 doing things that are different on different OSes.
34
35  print "Running on $ARCHITECTURE\n";
36  `$cmd > $NULL 2>&1`;
37  my $filename = $app_base . $SEPARATOR . "datafile.txt";
38
39 =head1 DESCRIPTION
40
41 This module exports several variables that are useful to isolate OS
42 dependencies. For example, $ARCHITECTURE is set to "windows", "cygwin" or the
43 value of $^O depending on which OS the script is running. This allows
44 you to write code that is dependant on which OS you are running
45 on. Similarly, $NULL is set to the string "NUL" when running on
46 Windows otherwise it is set to "/dev/null" (Under Cygwin /dev/null is
47 appropriate). This way if you wish to say redirect output to "null"
48 you can use $NULL.
49
50 There is currently only one subroutine exported, Chrooted, which
51 returns $TRUE if you are operating in a chrooted environment, $FALSE
52 otherwise;
53
54 =head1 ROUTINES
55
56 The following routines are exported:
57
58 =cut
59
60 package OSDep;
61
62 use strict;
63 use warnings;
64
65 use base 'Exporter';
66
67 our $ARCHITECTURE = $^O =~ /MSWin/ 
68                   ? 'windows'
69                   : $^O =~ /cygwin/
70                   ? "cygwin"
71                   : $^O;
72 our $NULL         = $^O =~ /MSWin/ ? 'NUL' : '/dev/null';
73 our $SEPARATOR    = $^O =~ /MSWin/ ? '\\'  : '/';
74 our $TRUE         = 1;
75 our $FALSE        = 0;
76 our $ROOT         = $^O =~ /MSWin/ ? $ENV {SYSTEMDRIVE} . $SEPARATOR : "/";
77
78 our @EXPORT = qw (
79   $ARCHITECTURE
80   $FALSE
81   $NULL
82   $SEPARATOR
83   $TRUE
84   Chrooted
85 );
86
87 sub Chrooted () {
88
89 =pod
90
91 =head2 Chrooted ()
92
93 Returns $TRUE  if you are operating under a chrooted environment,
94 $FALSE otherwise.
95
96 Parameters:
97
98 =begin html
99
100 <blockquote>
101
102 =end html
103
104 =over
105
106 =item None
107
108 =back
109
110 =begin html
111
112 </blockquote>
113
114 =end html
115
116 Returns:
117
118 =begin html
119
120 <blockquote>
121
122 =end html
123
124 =over
125
126 =item Boolean
127
128 =back
129
130 =begin html
131
132 </blockquote>
133
134 =end html
135
136 =cut
137
138   if ($ARCHITECTURE eq "windows" or $ARCHITECTURE eq "cygwin") {
139     # Not sure how this relates to Windows/Cygwin environment so just
140     # return false
141     return $FALSE;
142   } else {
143     return ((stat $ROOT) [1] != 2);
144   } # if
145 } # Chrooted
146
147 1;
148
149 =pod
150
151 =head1 VARIABLES
152
153 =over
154
155 =item $ARCHITECTURE
156
157 Set to either "windows", "cygwin" or $^O.
158
159 =item $NULL
160
161 Set to "NUL" for Windows, "/dev/null" otherwise.
162
163 =item $SEPARATOR}
164
165 Set to "\" for Windows, "/" otherwise.
166
167 =item $TRUE;
168
169 Convenient boolean variable set to 1 (Cause I always forget if 1 or 0
170 is true)
171
172 =item $FALSE
173
174 Convenient boolean variable set to 0 (Cause I always forget if 1 or 0
175 is false)
176
177 =item $ROOT
178
179 Set to SYSTEMDRIVE for Windows, "/" otherwise
180
181 =back
182
183 =head1 DEPENDENCIES
184
185 None
186
187 =head1 INCOMPATABILITIES
188
189 None yet...
190
191 =head1 BUGS AND LIMITATIONS
192
193 There are no known bugs in this module.
194
195 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
196
197 =head1 LICENSE AND COPYRIGHT
198
199 This Perl Module is freely available; you can redistribute it and/or
200 modify it under the terms of the GNU General Public License as
201 published by the Free Software Foundation; either version 2 of the
202 License, or (at your option) any later version.
203
204 This Perl Module is distributed in the hope that it will be useful,
205 but WITHOUT ANY WARRANTY; without even the implied warranty of
206 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
207 General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
208 details.
209
210 You should have received a copy of the GNU General Public License
211 along with this Perl Module; if not, write to the Free Software Foundation,
212 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
213 reserved.
214
215 =cut