cvsuser 05/05/14 07:04:22
Modified: App-Options/lib/App Options.pm
App-Options/t app.conf main.t old.t
Log:
fixed to work with MSWin (module and tests)
Revision Changes Path
1.15 +8 -24 p5ee/App-Options/lib/App/Options.pm
Index: Options.pm
===================================================================
RCS file: /cvs/public/p5ee/App-Options/lib/App/Options.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Options.pm 30 Jan 2005 23:07:43 -0000 1.14
+++ Options.pm 14 May 2005 14:04:21 -0000 1.15
@@ -431,29 +431,12 @@
# we will use this directory to search for the
# option file.
#################################################################
- my $is_unix = 1; # pretend we are not on Unix (use File::Spec)
my ($prog_cat, $prog_dir, $prog_file);
- if ($is_unix) {
- $prog_dir = $0;
- # i.e. /usr/local/bin/app, /app
- if ($prog_dir =~ m!^/!) { # absolute path
- # i.e. /usr/local/bin/app, /app
- $prog_dir =~ s!/[^/]+$!!; # trim off the program name
- }
- else { # relative path
- # i.e. app, ./app, ../bin/app, bin/app
- $prog_dir =~ s!/?[^/]+$!!; # trim off the program name
- $prog_dir = "." if (!$prog_dir); # if nothing left, directory is
current dir
- }
- $prog_file = $0;
- $prog_file =~ s!.*/!!;
- $prog_cat = "";
- }
- else {
- # i.e. C:\perl\bin\app, \app
- ($prog_cat, $prog_dir, $prog_file) = File::Spec->splitpath($0);
- }
+ # i.e. C:\perl\bin\app, \app
+ ($prog_cat, $prog_dir, $prog_file) = File::Spec->splitpath($0);
+ $prog_dir =~ s!\\!/!g; # transform to POSIX-compliant (forward slashes)
+
print STDERR "2. Found Directory of Program. catalog=[$prog_cat]
dir=[$prog_dir] file=[$prog_file]\n"
if ($debug_options);
@@ -488,6 +471,7 @@
if (!$prefix) { # last resort: perl's prefix
$prefix = $Config{prefix};
+ $prefix =~ s!\\!/!g; # transform to POSIX-compliant
$prefix_origin = "perl prefix";
}
print STDERR "3. Provisional prefix Set. prefix=[$prefix]
origin=[$prefix_origin]\n"
@@ -833,7 +817,7 @@
# If it has, we do *not* want to automagically guess which
directories
# should be searched and in which order.
foreach my $incdir (@INC) {
- if ($incdir =~ /^$libdir/) {
+ if ($incdir =~ m!^$libdir!) {
$libdir_found = 1;
last;
}
1.6 +1 -1 p5ee/App-Options/t/app.conf
Index: app.conf
===================================================================
RCS file: /cvs/public/p5ee/App-Options/t/app.conf,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- app.conf 28 Dec 2004 22:30:59 -0000 1.5
+++ app.conf 14 May 2005 14:04:22 -0000 1.6
@@ -1,5 +1,5 @@
var = value
-prefix = /usr/local
+#prefix = /usr/local
envtest = xy$ENV{ZZ}y
[junk]
var1 = some other junk
1.7 +8 -3 p5ee/App-Options/t/main.t
Index: main.t
===================================================================
RCS file: /cvs/public/p5ee/App-Options/t/main.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- main.t 28 Dec 2004 22:31:23 -0000 1.6
+++ main.t 14 May 2005 14:04:22 -0000 1.7
@@ -10,6 +10,8 @@
delete $ENV{DOCUMENT_ROOT};
}
+use Config;
+use File::Spec;
use Test::More qw(no_plan);
use lib "lib";
use lib "../lib";
@@ -27,9 +29,12 @@
},
);
+my $prefix = $Config{prefix};
+$prefix =~ s!\\!/!g; # transform to POSIX-compliant
+
#print "CONF:\n ", join("\n ",%App::options), "\n";
ok(%App::options, "put something in %App::options");
-is($App::options{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::options{prefix}, $prefix, "prefix = $prefix");
is($App::options{app}, "main", "app = main");
is($App::options{var}, "value", "var = value");
is($App::options{var1}, "pattern match", "pattern match");
@@ -68,7 +73,7 @@
App::Options->init(\%App::otherconf);
#print "CONF:\n ", join("\n ",%App::otherconf), "\n";
ok(%App::otherconf, "put something in %App::otherconf");
-is($App::otherconf{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::otherconf{prefix}, $prefix, "prefix = $prefix");
is($App::otherconf{app}, "main", "app = main");
is($App::otherconf{var}, "value", "var = value");
is($App::otherconf{var1}, "pattern match", "pattern match");
@@ -77,7 +82,7 @@
App::Options->init(values => \%App::options3);
#print "CONF:\n ", join("\n ",%App::options3), "\n";
ok(%App::options3, "put something in %App::options3");
-is($App::options3{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::options3{prefix}, $prefix, "prefix = $prefix");
is($App::options3{app}, "main", "app = main");
is($App::options3{var}, "value", "var = value");
is($App::options3{var1}, "pattern match", "pattern match");
1.2 +8 -3 p5ee/App-Options/t/old.t
Index: old.t
===================================================================
RCS file: /cvs/public/p5ee/App-Options/t/old.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- old.t 2 Dec 2004 16:14:56 -0000 1.1
+++ old.t 14 May 2005 14:04:22 -0000 1.2
@@ -3,6 +3,7 @@
use Test::More qw(no_plan);
use lib "lib";
use lib "../lib";
+use Config;
use_ok("App::Options");
@@ -25,9 +26,13 @@
var12 => { env => "VAR12", },
},
);
+
+my $prefix = $Config{prefix};
+$prefix =~ s!\\!/!g; # transform to POSIX-compliant
+
#print "CONF:\n ", join("\n ",%App::options), "\n";
ok(%App::options, "put something in %App::options");
-is($App::options{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::options{prefix}, $prefix, "prefix = $prefix");
is($App::options{app}, "old", "app = old");
is($App::options{var}, "value", "var = value");
is($App::options{var1}, "pattern match", "pattern match");
@@ -66,7 +71,7 @@
App::Options->init(\%App::otherconf);
#print "CONF:\n ", join("\n ",%App::otherconf), "\n";
ok(%App::otherconf, "put something in %App::otherconf");
-is($App::otherconf{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::otherconf{prefix}, $prefix, "prefix = $prefix");
is($App::otherconf{app}, "old", "app = old");
is($App::otherconf{var}, "value", "var = value");
is($App::otherconf{var1}, "pattern match", "pattern match");
@@ -75,7 +80,7 @@
App::Options->init(values => \%App::options3);
#print "CONF:\n ", join("\n ",%App::options3), "\n";
ok(%App::options3, "put something in %App::options3");
-is($App::options3{prefix}, "/usr/local", "prefix = /usr/local");
+is($App::options3{prefix}, $prefix, "prefix = $prefix");
is($App::options3{app}, "old", "app = old");
is($App::options3{var}, "value", "var = value");
is($App::options3{var1}, "pattern match", "pattern match");