Config-Find-0.26/0000755000175000017500000000000011112503662012517 5ustar salvasalvaConfig-Find-0.26/Changes0000755000175000017500000000655111112503527014024 0ustar salvasalvaRevision history for Perl extension Config::Find. 0.26 Nov 24, 2008 - remove warning from File::Spec 0.25 Nov 20, 2008 - paths began with '//' on cygwin, use catpath to undo splitpath (bug report from Pablo Torres). 0.24 12 Nov, 2008 - add Config::Find::Where->script_dir() - some minor doc improvements 0.23 17 Sep, 2008 - add Config::Find::Where->lib_dir method - Config::Find::Where->application_dir documented - update to use new File::HomeDir API 0.22 22 Sep 2005 - pod errors corrected on Config::Find::Where and now using Test::Pod for automatically finding those errors. 0.21 8 Aug 2005 - added work around on WinAny module when ${APPDATA} or ${LOCAL_APPDATA} point to the user desktop to ignore them. 0.20 27 Jul 2005 - look for ~/.foo.conf and ~/.foo.cfg in addition to ~/.foo 0.19 13 Jul 2005 - bug on look_for_dir_file passing the wrong app name to app_dir. 0.18 13 Apr 2005 - bug on parent_dir('') going to an inf. loop corrected. - convert path to absolute on create_dir and create_parent_dir - create_parent_dirs renamed to create_parent_dir and exported via Config::Find::Where. 0.17 13 Apr 2005 - bug on var_dir corrected, when using scope 'app' a 'var' part was missing on the path. - Config::Find::Where::var_dir documented 0.16 16 Sep 2004 - create_dir function exported on Config::Find::Where - support for 'dir' option on Where module functions. 0.15 11 Feb 2004 - Corrected bug on "names" handling reported by Bart Schaefer - Better handling of Win32::GetFolderPath returning invalid results 0.14 15 Jan 2004 - Win2k3.pm missing from MANIFEST - Use regexps to match Win OSs - corrected bug on guess_script_dir 0.13 13 Jan 2004 - NT4 was not being recognised as NT (bug reported by Philip Grivell). 0.12 30 Sep 2003 - Unix module accepts .cfg extension for read mode 0.11 12 Jun 2003 - improved Config::Find::Where->var_dir(scope=>user) on Unix. - new Config::Find::Where->helper_path method 0.10 12 Jun 2003 - corrected several bugs in Windows modules - new test script 2_where.t 0.09 5 Jun 2003 - new file layout, now all the .pm files are under a common lib dir. - new Config::Find::Where module with some utility methods (maybe unrelated to Config::Find, but useful anyway). - Win32.pm module deleted. - added supoprt for Windows 2003 - corrected some errors in the docs 0.08 29 May 2003 - look for script on current dir when it doesn't have the path included in its name and it has not been found on the system path. 0.07 29 Apr 2003 - Accept "WinXP/.NET" as OS 0.06 Tue Apr 15 2003 - File::HomeDir dependency added to main module, CPANPLUS doesn't catch it on the inner module 0.05 Mon Apr 14 2003 - support for one liners added to Unix module 0.04 Thu Apr 10 2003 - added File::HomeDir dependecy to Config::Find::Unix 0.03 Wed Apr 9 2003 - corrected bug in open that returned a valid file handler even when the configuration file was not found 0.02 Wed Apr 9 2003 - corrected bug in 'parent_dir' that was not correctly handling trailing '/' - corrected bug in 'guess_script_dir' that was not removing the script name - support for 'file' option added - dependencies added in Makefile.PL 0.01 Mon Mar 31 13:09:40 2003 - original version; created by h2xs 1.22 with options -AX -n Config::Find Config-Find-0.26/META.yml0000644000175000017500000000075211112503662013774 0ustar salvasalva--- #YAML:1.0 name: Config-Find version: 0.26 abstract: ~ license: ~ author: - Salvador Fandino generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: File::HomeDir: 0 File::Spec: 0 File::Which: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Config-Find-0.26/README0000755000175000017500000000116210347053754013415 0ustar salvasalvaConfig/Find version =================== Config::Find implements a set of heuristics to find the configuration files for your applications in an OS dependant and friendly manner. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: File::HomeDir File::Which File::Spec Test::More COPYRIGHT AND LICENCE Copyright (C) 2003, 2004 Salvador Fandiño García This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Config-Find-0.26/Makefile.PL0000755000175000017500000000053511111275411014474 0ustar salvasalvause 5.006; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Config::Find', VERSION_FROM => 'lib/Config/Find.pm', PREREQ_PM => {'File::Which' => 0, 'File::Spec' => 0, 'File::HomeDir' => 0 }, AUTHOR => 'Salvador Fandino ' ); Config-Find-0.26/MANIFEST0000755000175000017500000000071610347053754013672 0ustar salvasalvaChanges lib/Config/Find/Any.pm lib/Config/Find.pm lib/Config/Find/Unix.pm lib/Config/Find/Where.pm lib/Config/Find/Win2k.pm lib/Config/Find/Win2k3.pm lib/Config/Find/Win95.pm lib/Config/Find/Win98.pm lib/Config/Find/WinAny.pm lib/Config/Find/WinCE.pm lib/Config/Find/WinME.pm lib/Config/Find/WinNT.pm lib/Config/Find/WinXP.pm Makefile.PL MANIFEST README t/1.t t/2_where.t t/3_pods.t META.yml Module meta-data (added by MakeMaker) Config-Find-0.26/lib/0000755000175000017500000000000011112503662013265 5ustar salvasalvaConfig-Find-0.26/lib/Config/0000755000175000017500000000000011112503662014472 5ustar salvasalvaConfig-Find-0.26/lib/Config/Find/0000755000175000017500000000000011112503662015352 5ustar salvasalvaConfig-Find-0.26/lib/Config/Find/WinME.pm0000755000175000017500000000146110347053753016706 0ustar salvasalvapackage Config::Find::WinME; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::WinME - WinME idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::WinME; use Config::Find; =head1 ABSTRACT Implements WinME specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::WinME, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/WinAny.pm0000755000175000017500000001315510347053753017137 0ustar salvasalvapackage Config::Find::WinAny; our $VERSION = '0.18'; use strict; use warnings; use Carp; use Config::Find::Any; use Win32 qw(CSIDL_LOCAL_APPDATA CSIDL_APPDATA CSIDL_DESKTOPDIRECTORY); our @ISA = qw(Config::Find::Any); sub app_dir { my ($class, $name)=@_; $name=$class->guess_script_name unless defined $name; my $ename = uc($name).'_HOME'; if (exists $ENV{$ename}) { return $ENV{$ename} } $class->guess_script_dir; } my $winlocalappdir=Win32::GetFolderPath(CSIDL_LOCAL_APPDATA); my $winappdir=Win32::GetFolderPath(CSIDL_APPDATA); my $windesktop=Win32::GetFolderPath(CSIDL_DESKTOPDIRECTORY); if (defined $windesktop and $windesktop ne '') { undef $winlocalappdir if (defined($winlocalappdir) and index($winlocalappdir, $windesktop) == 0); undef $winappdir if (defined($winappdir) and index($winappdir, $windesktop) == 0); } sub app_user_dir { my ($class, $name)=@_; return ( (defined $winlocalappdir) && ($winlocalappdir ne "") ? $winlocalappdir : (defined $winappdir) && ($winappdir ne "") ? $winappdir : File::Spec->catdir($class->app_dir($name), 'Users', $class->my_getlogin)); } sub system_temp { my $class=shift; return $ENV{TEMP} if defined $ENV{TEMP}; return $ENV{TMP} if defined $ENV{TMP}; return File::Spec->catfile($ENV{windir}, 'Temp') if defined $ENV{windir}; return 'C:\Temp'; } sub _var_dir { my ($class, $name, $more_name, $scope)=@_; if ($scope eq 'user') { File::Spec->catdir($class->app_user_dir($name), $name, 'Data', $more_name) } else { File::Spec->catdir($class->app_dir($name), 'Data', $more_name); } } sub _bin_dir { my ($class, $name, $more_name, $scope)=@_; if ($scope eq 'app') { $class->app_dir($name); } else { die "unimplemented option scope => $scope"; } } sub look_for_helper { my ($class, $dir, $helper)=@_; my @ext=('', ( defined $ENV{PATHEXT} ? (split /;/, $ENV{PATHEXT}) : qw(.COM .EXE .BAT .CMD))); for my $ext (@ext) { my $path=File::Spec->catfile($dir, $helper.$ext); -e $path and -x $path and return $path; } croak "helper '$helper' not found"; } sub look_for_file { my ($class, $name, $write, $global)=@_; my $fn; my $fnwe=$class->add_extension($name, 'cfg'); if ($write) { if ($global) { return File::Spec->catfile($class->app_dir($name), $fnwe) } else { # my $login=getlogin(); return File::Spec->catfile($class->app_user_dir($name), $fnwe ); } } else { unless ($global) { $fn=File::Spec->catfile($class->app_user_dir, $fnwe ); return $fn if -f $fn; } $fn=File::Spec->catfile($class->app_dir($name), $fnwe); return $fn if -f $fn; } return undef; } sub look_for_dir_file { my ($class, $dir, $name, $write, $global)=@_; my $fn; my $fnwe=$class->add_extension($name, 'cfg'); if ($write) { if ($global) { return File::Spec->catfile($class->app_dir($dir), $dir, $fnwe) } else { # my $login=getlogin(); return File::Spec->catfile($class->app_user_dir($dir), $dir, $fnwe ); } } else { unless ($global) { $fn=File::Spec->catfile($class->app_user_dir($name), $dir, $fnwe ); return $fn if -f $fn; } $fn=File::Spec->catfile($class->app_dir($name), $fnwe); return $fn if -f $fn; } return undef; } 1; __END__ =head1 NAME Config::Find::WinAny - Behaviours common to any Win32 OS for Config::Find =head1 SYNOPSIS # don't use Config::Find::WinAny; use Config::Find; =head1 ABSTRACT Implements features common to all the Win32 OS's =head1 DESCRIPTION This module implements Config::Find for Win32 OS's. B Configuration file placement has changed on version 0.15 to be more Windows friendly (see note below). Order for config files searching is... (see note at the end for entries marked as 1b and 2b) 1 ${LOCAL_APPDATA}/$name.cfg [user] (1b /$path_to_script/Users/$user/$name.cfg [user]) 2 /$path_to_script/$name.cfg [global] unless when C<$ENV{${name}_HOME}> is defined. That changes the search paths to... (1b $ENV{${name}_HOME}/Users/$user/$name.cfg [user]) 2 $ENV{${name}_HOME}/$name.cfg [global] When the "several configuration files in one directory" aproach is used, the order is something different... 1 ${LOCAL_APPDATA}/$dir/$name.cfg [user] (1b /$path_to_script/Users/$user/$dir/$name.cfg [user]) 2 /$path_to_script/$name.cfg [global] (2b /$path_to_script/$dir/$name.dfg [global]) (it is also affected by C<$ENV{${name}_HOME}> variable) Note: entries marked as 1b were the default behaviour for versions of Config::Find until 0.14. New behaviour is to put user application configuration data under ${LOCAL_APPDATA} as returned by C (if this call fails, the old approach is used). Also, global configuration files were stored under a new directory placed in the same dir as the script but this is unnecesary because windows apps already go in their own directory. It seems that, sometimes, ${LOCAL_APPDATA} points to the user desktop and placing configuration files there would be obviusly wrong. As a work around, the module will ignore ${LOCAL_APPDATA} or ${APPDATA} if they point to any place below the desktop path. =head2 EXPORT None by default. =head1 SEE ALSO L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Unix.pm0000755000175000017500000001446611064216435016656 0ustar salvasalvapackage Config::Find::Unix; use 5.006; our $VERSION = '0.23'; use strict; use warnings; use Carp; use File::HomeDir; use Config::Find::Any; our @ISA=qw(Config::Find::Any); sub app_dir { my ($class, $name)=@_; $name=$class->guess_script_name unless defined $name; my $ename = uc($name).'_HOME'; if (exists $ENV{$ename}) { return $ENV{$ename} } $class->parent_dir($class->guess_script_dir); } sub _my_home { my $home = File::HomeDir->my_home; return $home if defined $home; my ($user, $dir) = (getpwuid $>)[0, 7]; return $dir if defined $dir; return "/home/$user" if defined $user; return "/" }; sub system_temp { '/tmp' } sub _var_dir { my ($class, $name, $more_name, $scope) = @_; if ($scope eq 'global') { $class->my_catfile('/var', $name, $more_name); } elsif ($scope eq 'user') { File::Spec->catfile(_my_home(), '.'.$name, 'var', $more_name); } elsif ($scope eq 'app') { $class->my_catfile($class->app_dir($name), 'var', $more_name); } else { croak "scope '$scope' is not valid for var_dir method"; } } sub _bin_dir { my ($class, $name, $more_name, $scope) = @_; if ($scope eq 'global') { '/usr/bin'; } elsif ($scope eq 'user') { File::Spec->catfile(_my_home(), 'bin'); } elsif ($scope eq 'app') { File::Spec->catfile($class->app_dir($name), 'bin'); } else { croak "scope '$scope' is not valid for bin_dir method"; } } sub _lib_dir { my ($class, $name, $more_name, $scope) = @_; if ($scope eq 'global') { '/usr/lib'; } elsif ($scope eq 'user') { File::Spec->catfile(_my_home(), 'lib'); } elsif ($scope eq 'app') { File::Spec->catfile($class->app_dir($name), 'lib'); } else { croak "scope '$scope' is not valid for lib_dir method"; } } sub look_for_file { my ($class, $name, $write, $global)=@_; my $fn; if ($write) { if ($global) { my $fnwe=$class->add_extension($name, 'conf'); unless ($class->is_one_liner) { my $etc=File::Spec->catfile($class->app_dir($name), 'etc'); return File::Spec->catfile($etc, $fnwe) if -e $etc; $etc=File::Spec->catfile($class->app_dir($name), 'conf'); return File::Spec->catfile($etc, $fnwe) if -e $etc; } return File::Spec->catfile('/etc', $fnwe); } else { return File::Spec->catfile(_my_home(), ".$name"); } } else { # looks in ~/.whatever unless ($global) { $fn=File::Spec->catfile(_my_home(), ".$name"); return $fn if -f $fn; for my $ext (qw(conf cfg)) { return "$fn.$ext" if -f "$fn.$ext"; } } for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) { unless ($class->is_one_liner) { # looks in ./../etc/whatever.conf relative to the running script $fn=File::Spec->catfile($class->app_dir($name), 'etc', $fnwe); return $fn if -f $fn; # looks in ./../conf/whatever.conf relative to the running script $fn=File::Spec->catfile($class->app_dir($name), 'conf', $fnwe); return $fn if -f $fn; } # looks in /etc/whatever.conf $fn=File::Spec->catfile('/etc', $fnwe); return $fn if -f $fn; } } return undef; } sub look_for_helper { my ($class, $dir, $helper)=@_; my $path=File::Spec->catfile($dir, $helper); -e $path or croak "helper '$helper' not found"; ((-f $path or -l $path) and -x $path) or croak "helper '$helper' found at '$path' but it is not executable"; return $path } sub look_for_dir_file { my ($class, $dir, $name, $write, $global)=@_; my $fn; if ($write) { my $fnwe=$class->add_extension($name, 'conf'); if ($global) { unless ($class->is_one_liner) { my $etc=File::Spec->catfile($class->app_dir($dir), 'etc'); return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc; $etc=File::Spec->catfile($class->app_dir($dir), 'conf'); return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc; } return File::Spec->catfile('/etc', $dir, $fnwe); } else { return File::Spec->catfile(_my_home(), ".$dir", $fnwe); } } else { # looks in ~/.whatever for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) { unless ($global) { my $fn=File::Spec->catfile(_my_home(), ".$dir", $fnwe); return $fn if -f $fn; } unless ($class->is_one_liner and not defined $dir) { # looks in ./../etc/whatever.conf relative to the running script $fn=File::Spec->catfile($class->app_dir($dir), 'etc', $dir, $fnwe); return $fn if -f $fn; # looks in ./../conf/whatever.conf relative to the running script $fn=File::Spec->catfile($class->app_dir($dir), 'conf', $dir, $fnwe); return $fn if -f $fn; } # looks in system /etc/whatever.conf $fn=File::Spec->catfile('/etc', $dir, $fnwe); return $fn if -f $fn; } } return undef; } 1; __END__ =head1 NAME Config::Find::Unix - Config::Find plugin for Unixen =head1 SYNOPSIS # don't use Config::Find::Unix; use Config::Find; =head1 ABSTRACT Config::Find plugin for Unixen =head1 DESCRIPTION This module implements Config::Find for Unix The order for searching the config files is: 1 ~/.$name [user] 1b ~/.$name.conf [user] 2 /$path_to_script/../etc/$name.conf [global] 3 /$path_to_script/../conf/$name.conf [global] 4 /etc/$name.conf [global] although if the environment variable C<$ENV{${name}_HOME}> is defined it does 1 ~/.$name [user] 1b ~/.$name.conf [user] 2 $ENV{${name}_HOME}/etc/$name.conf [global] 3 $ENV{${name}_HOME}/conf/$name.conf [global] 4 /etc/$name.conf [global] instead. When the "several configuration files in one directory" aproach is used, the order is somewhat different: 1 ~/.$dir/$name.conf [user] 2 /$path_to_script/../etc/$dir/$name.conf [global] 3 /$path_to_script/../conf/$dir/$name.conf [global] 4 /etc/$dir/$name.conf [global] (also affected by C<$ENV{${name}_HOME}>) =head2 EXPORT None. =head1 SEE ALSO L, L. =head1 AUTHOR Salvador Fandiño García, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño García This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/WinCE.pm0000644000175000017500000000146110347053753016671 0ustar salvasalvapackage Config::Find::WinCE; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::WinCE - WinCE idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::WinCE; use Config::Find; =head1 ABSTRACT Implements WinCE specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::WinCE, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Any.pm0000755000175000017500000001127611112503536016451 0ustar salvasalvapackage Config::Find::Any; our $VERSION = '0.26'; use strict; use warnings; use Carp; use File::Spec; use File::Which; use IO::File; sub _find { my ($class, $write, $global, @names)=@_; for my $n (@names) { my $fn; if ($n=~/^(.*?)\/(.*)$/) { my ($dir, $file)=($1, $2); $fn=$class->look_for_dir_file($dir, $file, $write, $global); } else { $fn=$class->look_for_file($n, $write, $global); } return $fn if defined $fn; } return undef; } sub _open { my ($class, $write, $global, $fn)=@_; if ($write) { $class->create_parent_dir($fn); return IO::File->new($fn, 'w'); } defined($fn) ? IO::File->new($fn, 'r') : undef; } sub _install { my ($class, $orig, $write, $global, $fn)=@_; croak "install mode has to be 'write'" unless $write; my $oh=IO::File->new($orig, 'r') or croak "unable to open '$orig'"; my $fh=$class->_open($write, $global, $fn) or croak "unable to create config file '$fn'"; while(<$oh>) { $fh->print($_) } close $fh or die "unable to write config file '$fn'"; close $oh or die "unable to read '$orig'"; return $fn; } sub _temp_dir { my ($class, $name, $more_name, $scope)=@_; my $stemp=$class->system_temp; if ($scope eq 'global') { $class->my_catdir($stemp, $name, $more_name) } elsif ($scope eq 'user') { $class->my_catdir($stemp, $class->my_getlogin, $name, $more_name) } elsif ($scope eq 'app') { $class->my_catdir($class->app_dir($name), 'tmp', $more_name) } elsif ($scope eq 'process') { $class->my_catdir($stemp, $class->my_getlogin, $name, $$, $more_name) } else { croak "scope '$scope' is not valid for temp_dir method"; } } sub guess_full_script_name { my $path = (File::Spec->splitpath($0))[1]; if ($path eq '') { if (my $script=File::Which::which($0)) { return File::Spec->rel2abs($script); } } return File::Spec->rel2abs($0) if -e $0; carp "unable to determine script '$0' location"; } sub guess_script_name { my $name; (undef, undef, $name)=File::Spec->splitpath($0); $name=~/^(.+)\..*$/ and return $1; return undef if $name eq ''; return $name; } sub guess_script_dir { my $class=shift; my $script=$class->guess_full_script_name; my ($unit, $dir)=File::Spec->splitpath($script, 0); File::Spec->catpath($unit, $dir, ''); } sub is_one_liner { return $0 eq '-e' } sub add_extension { my ($class, $name, $ext)=@_; return $name if ($name=~/\./); return $name.'.'.$ext; } sub create_parent_dir { my ($class, $fn)=@_; my $parent=$class->parent_dir($fn); if (-e $parent) { -d $parent or croak "'$parent' exists but is not a directory"; -W $parent or croak "not allowed to write on directory '$parent'"; } else { $class->create_parent_dir($parent); mkdir $parent or die "unable to create directory '$parent' ($!)"; } } sub parent_dir { my ($class, $dir)=@_; # print "creating dir $dir\n"; my @dirs=File::Spec->splitdir($dir); pop(@dirs) eq '' and pop(@dirs); File::Spec->catfile(@dirs ? @dirs : File::Spec->rootdir); } sub create_dir { my ($class, $dir)=@_; if (-e $dir) { -d $dir or croak "'$dir' exists but is not a directory"; } else { $class->create_parent_dir($dir); mkdir $dir or die "unable to create directory '$dir' ($!)"; } $dir; } sub look_for_file { my $class=shift; die "unimplemented virtual method $class->look_for_file() called"; } sub look_for_dir_file { my $class=shift; die "unimplemented virtual method $class->look_for_dir_file() called"; } sub my_catfile { my $class=shift; pop @_ unless defined $_[-1]; File::Spec->catfile(@_); } sub my_catdir { my $class=shift; pop @_ unless defined $_[-1]; File::Spec->catdir(@_); } sub my_getlogin { my $login=getlogin(); $login = '_UNKNOW_' unless defined $login; $login; } 1; __END__ =head1 NAME Config::Find::Any - Perl base class for Config::Find =head1 SYNOPSIS # don't use Config::Find::Any; use Config::Find; =head1 ABSTRACT This module implements basic methods for L. =head1 DESCRIPTION Every L class has to be derived from this one and two methods have to be redefined: =over 4 =item $class->look_for_file($name, $write, $global) =item $class->look_for_dir_file($dir, $name, $write, $global) =back =head2 EXPORT None. =head1 SEE ALSO L, L, L. =head1 AUTHOR Salvador FandiEo, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003-2005 by Salvador FandiEo This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Win2k3.pm0000644000175000017500000000146710347053753017007 0ustar salvasalvapackage Config::Find::Win2k3; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::Win2k - Win2k idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::Win2k3; use Config::Find; =head1 ABSTRACT Implements Win2003 specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::Win2003, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Win2k.pm0000644000175000017500000000146110347053753016716 0ustar salvasalvapackage Config::Find::Win2k; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::Win2k - Win2k idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::Win2k; use Config::Find; =head1 ABSTRACT Implements Win2k specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::Win2k, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/WinNT.pm0000755000175000017500000000146110347053753016726 0ustar salvasalvapackage Config::Find::WinNT; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::WinNT - WinNT idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::WinNT; use Config::Find; =head1 ABSTRACT Implements WinNT specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::WinNT, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/WinXP.pm0000755000175000017500000000146110347053753016734 0ustar salvasalvapackage Config::Find::WinXP; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::WinXP - WinXP idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::WinXP; use Config::Find; =head1 ABSTRACT Implements WinXP specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::WinXP, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Win95.pm0000755000175000017500000000146110347053753016642 0ustar salvasalvapackage Config::Find::Win95; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::Win95 - Win95 idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::Win95; use Config::Find; =head1 ABSTRACT Implements Win95 specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::Win95, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Win98.pm0000755000175000017500000000146110347053753016645 0ustar salvasalvapackage Config::Find::Win98; our $VERSION = '0.01'; use strict; use warnings; use Config::Find::WinAny our @ISA = qw(Config::Find::WinAny); 1; __END__ =head1 NAME Config::Find::Win98 - Win98 idiosyncrasies for Config::Find =head1 SYNOPSIS # don't use Config::Find::Win98; use Config::Find; =head1 ABSTRACT Implements Win98 specific features for Config::Find =head1 DESCRIPTION Stub documentation for Config::Find::Win98, created by h2xs. =head2 EXPORT None by default. =head1 SEE ALSO L, L, L =head1 AUTHOR Salvador Fandiño, Esfandino@yahoo.comE =head1 COPYRIGHT AND LICENSE Copyright 2003 by Salvador Fandiño This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find/Where.pm0000644000175000017500000001510311106531362016763 0ustar salvasalvapackage Config::Find::Where; our $VERSION = '0.24'; 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); } =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 searchs for locations using OS dependant heuristics. =head1 DESCRIPTION After releasing L 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 hiden functionallity. =head2 OPTIONS As in L, all the methods in this package accept a common set of options: =over 4 =item name => C or C specifies the primary application name used to generate the location paths or to search for them. =item scope => C, C, C or C - =item create => 1 creates any unexistant 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-Etemp_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. =item $path=Config::Find::Where-Ebin_dir(%opts) returns a place to find/place binary files. The default scope for this method is C. 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 below. =item $path=Config::Find::Where-Evar_dir(%opts) returns a place to find/place working files. The default scope for this method is C. =item $path = Config::Find::Where-Elib_dir(%opts) returns a place to find/place library files. The default scope for this method is C. For instance: use lib => Config::Find::Where->lib_dir; =item $path = Config::Find::Where-Eapplication_dir(%opts) returns the application root directory. =item $name=Config::Find::Where-Escript_name() returns the name of the running script without any path information =item $path=Config::Find::Where-Escript_full_path() returns the name of the script as the absolute full path to it. =item $path=Config::Find::Where-Escript_dir() returns the name of the directory containing the current script =item Config::Find::Where-Ecreate_dir($dir) creates directory C<$dir> and any needed parents =item Config::Find::Where-Ecreate_parent_dir($file) recursively creates all the non existant parent dirs for C<$file>. =back =head2 EXPORT None, this module has an OO interface. =head1 BUGS Some Win32 OSs 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 =head1 COPYRIGHT AND LICENSE Copyright 2003-2008 by Salvador FandiEo GarcEa (sfandino@yahoo.com) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/lib/Config/Find.pm0000755000175000017500000001447011112503546015722 0ustar salvasalvapackage Config::Find; our $VERSION = '0.26'; use strict; use warnings; use Carp; # selects implementation module: our @ISA; BEGIN { if ($^O=~/Win32/) { require Win32; my $OS=uc Win32::GetOSName(); if ($OS=~/^WIN95/) { require Config::Find::Win95; @ISA=qw(Config::Find::Win95); } elsif ($OS=~/^WIN98/) { require Config::Find::Win98; @ISA=qw(Config::Find::Win98); } elsif ($OS=~/^WINME/) { require Config::Find::WinME; @ISA=qw(Config::Find::WinME); } elsif ($OS=~/^WINNT/) { require Config::Find::WinNT; @ISA=qw(Config::Find::WinNT); } elsif ($OS=~/^WIN2000/) { require Config::Find::Win2k; @ISA=qw(Config::Find::Win2k); } elsif ($OS=~/^WIN2003/) { require Config::Find::Win2k3; @ISA=qw(Config::Find::Win2k3); } elsif ($OS=~/^WINXP/) { require Config::Find::WinXP; @ISA=qw(Config::Find::WinXP); } elsif ($OS=~/^WINCE/) { require Config::Find::WinCE; @ISA=qw(Config::Find::WinCE); } else { croak "Unknow MSWin32 OS '$OS'"; } } else { require Config::Find::Unix; @ISA=qw(Config::Find::Unix); } } sub find { my $class=shift; my ($write, $global, $fn, @names)=$class->parse_opts(@_); if (defined $fn) { return ($write or -f $fn) ? $fn : undef; } $class->_find($write, $global, @names); } sub open { my $class=shift; my ($write, $global, $fn, @names)=$class->parse_opts(@_); defined($fn) or $fn=$class->_find($write, $global, @names); $class->_open($write, $global, $fn); } sub install { my $class=shift; my $orig=shift; my ($write, $global, $fn, @names)=$class->parse_opts( mode => 'w', @_); defined($fn) or $fn=$class->_find($write, $global, @names); $class->_install($orig, $write, $global, $fn); } sub parse_opts { my ($class, %opts)=@_; my $fn=$opts{file}; my @names; if (exists $opts{name}) { @names=$opts{name}; } elsif (exists $opts{names}) { UNIVERSAL::isa($opts{names}, 'ARRAY') or croak "invalid argument for 'names', expecting an array ref"; @names=@{$opts{names}} } else { @names=$class->guess_script_name(); } my $write; if (exists $opts{mode}) { if ($opts{mode}=~/^r(ead)?$/i) { # yes, do nothing! } elsif ($opts{mode}=~/w(rite)?$/i) { $write=1; } else { croak "invalid option mode => '$opts{mode}'"; } } my $global; if (exists $opts{scope}) { if ($opts{scope}=~/^u(ser)?$/i) { # yes, do nothing! } elsif ($opts{scope}=~/g(lobal)?$/i) { $global=1; } else { croak "invalid option scope => '$opts{scope}'"; } } return ($write, $global, $fn, @names) } 1; __END__ =head1 NAME Config::Find - Find configuration files in the native OS fashion =head1 SYNOPSIS use Config::Find; my $filename=Config::Find->find; ... my $fn_foo=Config::Find->find( name => 'my_app/foo', mode => 'write', scope => 'user' ); my $fn_bar=Config::Find->find( names => [qw(my_app/bar appbar)] ); my $fh=Config::Find->open( name => 'foo', scope => 'global', mode => 'w' ) my $fn=Config::Find->install( 'original/config/file.conf', name => 'foo' ); my $fn=Config::Find->find( file => $opt_c, name => foo ); =head1 ABSTRACT Config::Find searchs for configuration files using OS dependant heuristics. =head1 DESCRIPTION Every OS has different rules for configuration files placement, this module allows to easily find and create your app configuration files following those rules. Config::Find references configuration files by the application name or by the application name and the configuration file name when the app uses several application files, i.e C, C, C, C. By default the $0 value is used to generate the configuration file name. To define it explicitly the keywords C or C have to be used: =over 4 =item name => C or C picks the first configuration file matching that name. =item names => [qw(foo bar foo/bar)] picks the first configuration file matching any of the names passed. =back Alternatively, the exact position for the file can be specified with the C keyword: =over 4 =item file => C explicit position of the configuration file. If undef is passed this entry is ignored and the search for the configuration file continues with the apropiate OS rules. This allows for: use Config::Find; use Getopt::Std; our $opt_c; getopts('c:'); my $fn=Config::Find->find(file => $opt_c) =back Methods in this package also accept the optional arguments C and C: =over 4 =item scope => C or C Configuration files can be private to the application user or global to the OS, i.e. in unix there is the global C and the user C<~/.profile>. =item mode => C or C In C mode already existant file names are returned, in C mode the file names point to where the configuration file has to be stored. =back =head2 METHODS All the methods in this package are class methods (you don't need an object to call them). =over 4 =item $fn=Config::Find-Efind(%opts) returns the name of the configuration file. =item $fh=Config::Find-Eopen(%opts) returns a open file handle for the configuration file. In write mode, the file and any nonexistant parent directories are created. =item $fn=Config::Find-Einstall($original, %opts) copies a configuration file to a convenient place. =back =head2 EXPORT None, this module has an OO interface. =head1 BUGS Some Win32 OSs 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, L for descriptions of the heuristics used to find the configuration files. L for information about adding support for a new OS. L give me the idea for this module. =head1 COPYRIGHT AND LICENSE Copyright 2003-2008 by Salvador FandiEo GarcEa (sfandino@yahoo.com) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Config-Find-0.26/t/0000755000175000017500000000000011112503662012762 5ustar salvasalvaConfig-Find-0.26/t/2_where.t0000755000175000017500000000072610347053752014523 0ustar salvasalva# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 1.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Config::Find::Where') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. Config-Find-0.26/t/1.t0000755000175000017500000000071710347053752013330 0ustar salvasalva# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 1.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 1; BEGIN { use_ok('Config::Find') }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. Config-Find-0.26/t/3_pods.t0000644000175000017500000000027210347053752014350 0ustar salvasalva#!/usr/bin/perl use strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok( all_pod_files( qw(blib) ) );