/usr/share/perl5/Config/Find/Where.pm is in libconfig-find-perl 0.31-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | package Config::Find::Where;
use strict;
use warnings;
use Carp;
use Config::Find;
our @ISA=@Config::Find::ISA;
sub temp_dir {
my $class = shift;
my ($name, $more_name, $create, $dn, $scope)=
$class->parse_opts(scope=> 'user', @_);
$class->create_dir_if( (defined $dn
? $dn
: $class->_temp_dir($name, $more_name, $scope)),
$create)
}
sub var_dir {
my $class = shift;
my ($name, $more_name, $create, $dn, $scope)=
$class->parse_opts(scope => 'app', @_);
$class->create_dir_if( (defined $dn
? $dn
: $class->_var_dir($name, $more_name, $scope) ),
$create)
}
sub bin_dir {
my $class = shift;
my ($name, $more_name, $create, $dn, $scope)=
$class->parse_opts(scope=> 'app', @_);
$class->create_dir_if( (defined $dn
? $dn
: $class->_bin_dir($name, $more_name, $scope) ),
$create);
}
sub lib_dir {
my $class = shift;
my ($name, $more_name, $create, $dn, $scope) =
$class->parse_opts(scope => 'app', @_);
$class->create_dir_if( (defined $dn
? $dn
: $class->_lib_dir($name, $more_name, $scope) ),
$create);
}
sub application_dir {
my $class=shift;
my ($name, $more_name, $create, $dn, $scope)=
$class->parse_opts(@_);
$class->create_dir_if( (defined $dn
? $dn
: $class->app_dir($name) ),
$create)
}
sub create_dir_if {
my ($class, $dir, $create)=@_;
# warn ("$class->create_dir($dir, $create)");
if ($create) {
$class->create_dir($dir);
}
$dir;
}
sub create_dir {
my ($class, $dir)=@_;
$class->SUPER::create_dir(File::Spec->rel2abs($dir));
}
sub create_parent_dir {
my ($class, $dir)=@_;
$class->SUPER::create_parent_dir(File::Spec->rel2abs($dir));
}
sub script_full_path { shift->guess_full_script_name }
sub script_name { shift->guess_script_name }
sub script_dir { shift->guess_script_dir }
sub helper_path {
my $class=shift;
my $helper=shift;
my $path=$class->bin_dir(@_);
$class->look_for_helper($path, $helper);
}
sub parse_opts {
my ($class, %opts)=@_;
my ($name, $more_name, $create, $dn, $scope);
$dn=$opts{dir};
$create=$opts{create};
if (defined $opts{name}) {
$opts{name}=~m{^([^/]*)(?:/(.*))?$}
or croak "invalid name '$opts{name}' specification";
$name=$1;
$more_name=$2;
} else {
$name=$class->guess_script_name;
}
if (defined $opts{scope}) {
if ($opts{scope}=~/^u(ser)?$/i) {
$scope='user'
} elsif ($opts{scope}=~/^g(lobal)?$/i) {
$scope='global'
} elsif ($opts{scope}=~/^a(pp(lication)?)?$/i) {
$scope='app'
} elsif ($opts{scope}=~/^p(rocess)?$/i) {
$scope='process'
} else {
croak "invalid option scope => '$opts{scope}'";
}
} else {
$scope='global';
}
return ($name, $more_name, $create, $dn, $scope);
}
1;
__END__
=encoding latin1
=head1 NAME
Config::Find::Where - Find locations in the native OS fashion
=head1 SYNOPSIS
use Config::Find::Where;
my $temp_dir=Config::Find::Where->temp_dir( name => 'my_app',
scope => 'process',
create => 1 );
my $path=Config::Find::Where->bin_dir( scope => 'app' );
system $path."/app_helper.exe";
=head1 ABSTRACT
Config::Find searches for locations using OS dependent heuristics.
=head1 DESCRIPTION
After releasing L<Config::Find> I found much of its code could be
reused to also find other interesting things like temporary
directories, the script location, etc.
This module adds a public API to all the hidden functionality.
=head2 OPTIONS
As in L<Config::Find>, all the methods in this package accept a common
set of options:
=over 4
=item name => C<name> or C<name/more/names>
specifies the primary application name used to generate the location
paths or to search for them.
=item scope => C<user>, C<global>, C<app> or C<process>
-
=item create => 1
creates any nonexistent directory in the path returned
=back
=head2 METHODS
All the methods in this package are class methods (you don't need an
object to call them).
=over 4
=item $path=Config::Find::Where-E<gt>temp_dir(%opts)
returns a directory path inside a system temporary location. i.e.:
Config::Find::Where->temp_dir( name =>'hello/world',
scope => 'process',
create => 1 )
returns something similar to
'/tmp/jacks/hello/974/world/'
on unix like systems and
'C:\Windows\Temp\jacks\hello\974\world'
on some Windows ones ('jacks' is supposed to be the current user name
and '974' the process number).
The default scope for this method is C<user>.
=item $path=Config::Find::Where-E<gt>bin_dir(%opts)
returns a place to find/place binary files. The default scope for this
method is C<app>.
i.e.
Config::Find::Where->bin_dir()
returns the path to the directory where binaries are located.
Note that this directory is not necessarily the same as the one
containing the running script. See documentation for C<script_dir>
below.
=item $path=Config::Find::Where-E<gt>var_dir(%opts)
returns a place to find/place working files.
The default scope for this method is C<app>.
=item $path = Config::Find::Where-E<gt>lib_dir(%opts)
returns a place to find/place library files.
The default scope for this method is C<app>.
For instance:
use lib => Config::Find::Where->lib_dir;
=item $path = Config::Find::Where-E<gt>application_dir(%opts)
returns the application root directory.
=item $name=Config::Find::Where-E<gt>script_name()
returns the name of the running script without any path information
=item $path=Config::Find::Where-E<gt>script_full_path()
returns the name of the script as the absolute full path to it.
=item $path=Config::Find::Where-E<gt>script_dir()
returns the name of the directory containing the current script
=item Config::Find::Where-E<gt>create_dir($dir)
creates directory C<$dir> and any needed parents
=item Config::Find::Where-E<gt>create_parent_dir($file)
recursively creates all the nonexistent parent directories for
C<$file>.
=item Config::Find::Where-E<gt>helper_path($file, %opts)
searches for a script, based on the directories given in %opts, which are the
same as bin_dir() method.
=back
=head1 BUGS
Some Win32 operating systems are not completely implemented and
default to inferior modes, but hey, this is a work in progress!!!
Contributions, bug reports, feedback and any kind of comments are
welcome.
=head1 SEE ALSO
L<Config::Find>
=head1 AUTHOR
Salvador FandiE<ntilde>o GarcE<iacute>a, E<lt>sfandino@yahoo.comE<gt>
=head1 CONTRIBUTORS
Barbie, E<lt>barbie@missbarbell.co.ukE<gt> (some bug fixes and documentation)
=head1 COPYRIGHT AND LICENSE
Copyright 2003-2015 by Salvador FandiE<ntilde>o GarcE<iacute>a (sfandino@yahoo.com)
Copyright 2015 by Barbie (barbie@missbarbell.co.uk)
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|