Jan Dubois wrote:
>> How about something more direct...
>>
>> $IsWin95 = defined &Win32::IsWin95 ? Win32::IsWin95() : !defined
>> $ENV{SYSTEMROOT};
>>
>> The outwardly unrelated DynaLoader is completely removed from the equation,
>> this better
>> future proofs uses of Win32::, and the purpose of using SYSTEMROOT as a
>> fallback
>> is made plain.
>
> Sure, the problem is that your code doesn't work. The function is always
> defined
> for backward compatibility reasons. It just implemented something like this
> (in XS):
>
> sub Win32::IsWin95 {
> eval "use Win32 0.27";
> die $@ if $@;
> goto &Win32::IsWin95;
> }
Perhaps instead use an AUTOLOAD?
package Win32;
sub AUTOLOAD {
eval "use Win32 0.27";
die $@ if $@;
# Once we've loaded Win32.pm we no longer need the AUTOLOAD
delete $Win32::{AUTOLOAD};
no strict 'refs';
goto &{$AUTOLOAD};
}
It will be called once to automatically load Win32.pm and then never again so
no run-time performance loss. It also means defined &Win32::foo works as
expected. One less surprise for the user.