in reply to How can I include a module for Windows only??

Others have answered the direct question. I liked broquaint's solution best because, instead of trapping an error in an eval, it just makes a decision based on the OS.

Just one other thought though. It seems that if you continue down this road you're going to have a lot of "if ( $^O =~ /^Win/ ) {...} else {...}" logic scattered throughout the program. It may be advantageous to write a module that handles all this for you. The module would serve as an OS-independant wrapper interface that inherits from the OS-dependant modules you're using. Here's what I was thinking: (Warning, this is untested pseudocode):

package UniWin; BEGIN { if ( $^O =~ /^MSWin/ ) { require Win32::Setupsup; import Win32::Setupsup; @ISA = qw/Win32::Setupsup/; } else { require Expect; import Expect; @ISA = qw/Expect/; } } # Here you write a OS-generic wrapper around any OS # specific uses of Win32::Setupsup and Expect. # For example, if Setupsup has a "Win_This()" method and # Expect has a "Unix_This()" method, you would write a # wrapper called This() which invokes either method # depending on which OS you're using... 1; package main; use strict; use warnings; use UniWin; # ..........The rest of the program goes here...

This has the advantage of creating an OS-generic interface to whichever module you ended up loading in an OS-dependant fashion. That will allow the remainder of your code to concentrate on just doing things one way.

That's just a thought...


Dave

Replies are listed 'Best First'.
Re: Re: How can I include a module for Windows only??
by bart (Canon) on Dec 17, 2003 at 18:45 UTC
    Much like File::Spec. I rather like that approach.