G
Gunnar Hjalmarsson
Since flock() results in a fatal error on Windows 95 and 98, while I'm
doing development on a W98 box, there are quite a few statements like
this:
flock FH, LOCK_EX unless $W95;
I'm thinking of making flock() generate a non-fatal error instead when
run on W95 and W98 by defining CORE::GLOBAL::flock:
BEGIN {
*CORE::GLOBAL::flock = sub(*$) {
if ($^O eq 'MSWin32') {
require Win32;
if (Win32::GetOSVersion() < 2) {
warn 'flock() unimplemented on this platform';
return 1;
}
}
my ($fh, $op) = @_;
CORE::flock $fh, $op;
};
}
For this to work, it seems as if you need to pass the filehandles with
typeglobs:
flock *FH, LOCK_EX;
Doing so works also when calling the built-in flock() function
directly, so with this solution I'm able to use code that works the
'normal' way as well. Even if this is commented on under the title
"Overriding" in the Camel book, the only thing I'm overriding is the
fatal errors on W95 and W98. The intention is that it shall work
normally on other platforms.
Would appreciate your comments. I'd like to do this, but I don't want
to jeopardize the functioning of flock() where it's implemented.
doing development on a W98 box, there are quite a few statements like
this:
flock FH, LOCK_EX unless $W95;
I'm thinking of making flock() generate a non-fatal error instead when
run on W95 and W98 by defining CORE::GLOBAL::flock:
BEGIN {
*CORE::GLOBAL::flock = sub(*$) {
if ($^O eq 'MSWin32') {
require Win32;
if (Win32::GetOSVersion() < 2) {
warn 'flock() unimplemented on this platform';
return 1;
}
}
my ($fh, $op) = @_;
CORE::flock $fh, $op;
};
}
For this to work, it seems as if you need to pass the filehandles with
typeglobs:
flock *FH, LOCK_EX;
Doing so works also when calling the built-in flock() function
directly, so with this solution I'm able to use code that works the
'normal' way as well. Even if this is commented on under the title
"Overriding" in the Camel book, the only thing I'm overriding is the
fatal errors on W95 and W98. The intention is that it shall work
normally on other platforms.
Would appreciate your comments. I'd like to do this, but I don't want
to jeopardize the functioning of flock() where it's implemented.