19.2. Python for Mac OS X Geeks

 < Day Day Up > 

19.1. Perl for Mac OS X Geeks

The following sections list a few of the extras that come with Mac OS X. You can find these in /System/Library/Perl/Extras, which is among the paths that the bundled version of Perl searches for modules.

19.1.1. Mac::Carbon

This module comes by way of MacPerl (http://www.macperl.org), a distribution of Perl for Mac OS 9 and earlier. Mac::Carbon (which is included with Mac OS X) gives Perl programmers access to the Carbon APIs. Its test suite is great; make sure you have your speaker volume turned up when you run it. One of the many modules included with Mac::Carbon is MacPerl; here's an example that pops up a dialog box and asks a question:

     #!/usr/bin/perl -w     use strict;     use MacPerl qw(:all);     my $die_in_the_vacuum_of_space = 0;     my $answer = MacPerl::Ask("Tell me how good you thought my poem was.");     if ($answer =~         /counterpoint the surrealism of the underlying metaphor/i) {       $die_in_the_vacuum_of_space = 1;     }     print $die_in_the_vacuum_of_space, "\n"; 

For more information, you can access the Mac::Carbon documentation with perldoc Mac::Carbon.

19.1.2. PerlObjCBridge.pm

This module gives you a way to call into the Objective-C runtime on Mac OS X. Given an Objective-C call of the form:

     Type x = [Class method1:arg1 method2:arg2]; 

you can use the equivalent Perl code:

     $x = Class->method1_method2_($arg1, $arg2); 

You could also create an NSString and display it with the following script:

     #!/usr/bin/perl -w     use strict;     use Foundation; # import Foundation objects     my $string = NSString->stringWithCString_("Hello, World");     print $string, "\n";      # prints NSCFString=SCALAR(0x858398)     print $string->cString( ) , "\n"; # prints Hello, World 

You can read the documentation for this module with perldoc PerlObjCBridge.

19.1.3. Mac::Glue

This module lets you invoke Apple Events from Perl. To use it with an application, you'll need to create a layer of glue between this module with the gluemac utility, which is installed along with Mac::Glue. For example, to create the glue for the Terminal application, do the following:

     $ sudo /System/Library/Perl/Extras/bin/gluemac \                  /Applications/Utilities/Terminal.app/     Password: ********     What is the glue name? [Terminal]:     Created and installed App glue for Terminal.app, v1.5 (Terminal) 

This also creates documentation for the module. To read it, use perldoc Mac::Glue::glues::appname, as in perldoc Mac::Glue::glues::Terminal.

Before you use Mac::Glue, be sure to run (as root) both the gluedialect and gluescriptadds scripts in /System/Library/Perl/Extras/bin. These scripts create supporting files and OSA bindings for Mac::Glue.

Here's a short example that uses the Terminal glue to open a telnet session to the Weather Underground:

     #!/usr/bin/perl -w     use strict;     use Mac::Glue;     my $terminal = new Mac::Glue 'Terminal';     $terminal->geturl("telnet://rainmaker.wunderground.com"); 

You can read the documentation for this module with perldoc Mac::Glue.

     < Day Day Up > 

    Mac OS X Tiger for Unix Geeks
    Mac OS X Tiger for Unix Geeks
    ISBN: 0596009127
    EAN: 2147483647
    Year: 2006
    Pages: 176

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net