On Mon, 18 Dec 2006 16:38:47 -0500, Michael G Schwern <[EMAIL PROTECTED]> wrote:
>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. Well, it doesn't, because Win32::* functions are now no longer defined until you call the first one of them through the AUTOLOAD. This is a user visible change and therefore not really acceptable. The current implementation also runs only once, because the Win32.xs code will replace all the stub entries with the real functions. So there is no run-time performance loss either. >One less surprise for the user. There are *no* surprises for the user with the current implementation, which is why I really want to leave it as is. The only impact is on other *core* modules that need to work with miniperl, and I've provided changes to make those work as well. I did provide some additional documentation in my previous message in this thread. Please apply it as well to make the change less obscure! Cheers, -Jan