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

[MacPerl] Mac::Conversions using Convert::BinHex



Those of you who read comp.lang.perl.* may have seen Eryq announce
yesterday the availability of Convert::BinHex 1.19
<http://www.enteract.com/~eryq/CPAN/Convert-BinHex/>.  In the announcement
he mentions that it "does the right thing" if run under MacPerl.

The "right thing" is that, provided you have a version of MacPerl where this:

#!perl
use Fcntl;
print &Fcntl::O_RSRC."\n";

gives you 16384 instead of a complaint from the Autoloader, Convert::BinHex
can be used transform BinHex <=> native Mac files.  (The only version of
MacPerl that I know for sure will do this right is 5.14a1.  It doesn't work
under 5.13r2).  The existence of Fcntl::O_RSRC means that your MacPerl can
directly read and write the resource forks of Mac files.

I have written a Perl module which I'm tenatively calling Mac::Conversions
that will use Convert::BinHex to do the following transformations:

     native Mac <=> BinHex
     native Mac <=> MacBinary II
     BinHex     <=> MacBinary II

You can find it shortly at
<ftp://mors.gsfc.nasa.gov/pub/MacPerl/Scripts/Beta/Conversions.pm>

Documentation is in the file, which you can read by opening Conversions.pm
with Shuck.  At the moment, this module only works under MacPerl.  The
BinHex <=> MacBinary parts should work under all versions of MacPerl where
"use Mac::Files"; doesn't cause a problem, and once I rearrange a "use" or
two, they should be platform portable.  The two native Mac conversions
require the ability to read or write resouce forks, so will only work if
the script above works.

If you want to use Convert::BinHex on your own, you should be aware that
when you use the resource() method to tell Convert::BinHex where the
resource fork is, you must tell it that you want it to use the resource
fork of the file in the following manner:

$hqx = Convert::BinHex->new;
...
$hqx->resource(Path => $file, Fork => "RSRC");

Since Convert::BinHex is platform portable, it will only try to read a
resource fork when $^O eq "MacOS" *and* Fork => "RSRC".  Leave out the Fork
=> "RSRC", and even under MacPerl it will read the data fork of $file.  I
provided this modification to Eryq, and I decided to do it this way both
because it's flexible and because it minimizes the changes that need to be
made to Convert::BinHex. (And the fact that I was reading that there might
be more types of file fork under Rhapsody).

---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@leprss.gsfc.nasa.gov



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch