[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] cross-platform scripts



At 8.54 -0500 2000.05.09, John Gilmore-Baldwin wrote:
>I'm looking for the syntax that will let me use Mac:: packages in my
>script when on the Mac, but have the script still compile on Unix.
>
>My script seems to hang when I use some examples from the archive,
>and thought they might be intended for the reverse (using packages
>not available on the Mac).

There are various methods.  One is this:

if ($^O eq 'MacOS') {
  eval <<EOM;
    use Mac::Files;
    use Mac::Glue ':all';
EOM
  die $@ if $@;
}



If you don't like eval(), you can try:

if ($^O eq 'MacOS') {
  require Mac::Files;
  require Mac::Glue;
  Mac::Files->import;
  Mac::Glue->import(':all');
}


You can also use autouse, which can be cool, depending on how your program
works.

# functions here take prototype
use autouse 'Mac::Files' =>
  qw[FindFolder kOnSystemDisk() kTemporaryFolderType()];

# sigh, we get subroutine redefined errors
local $SIG{__WARN__} = sub {print @_ unless $_[0]=~/Subroutine \w+ redefined/};

if ($^O eq 'MacOS') {
  $tmp = FindFolder(kOnSystemDisk(), kTemporaryFolderType());
}


-- 
Chris Nandor       |     pudge@pobox.com      |     http://pudge.net/
Andover.Net        | chris.nandor@andover.net | http://slashcode.com/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org