Thx. That works like a charm.

The toll-free bridge also includes something like this?
my $str = NSString->stringWithString("astring");

where with PerlObjCBridge you have to use this:
my $str = NSString->stringWithCString_("astring");


Best regards,
Manfred



Am 29.12.2005 um 12:34 schrieb Sherm Pendley:

On Dec 28, 2005, at 7:05 PM, Manfred Bergmann wrote:

I want to use some Foundation objects like NSDictionary and others in a Perl script (because of writing a plist of that).
I succeeded with using PerlObjCBridge (use Foundation).

Is this possible with CamelBones, too? Sherm?

Yes, it is. When you install CamelBones, it installs a "embedded" framework and Perl module in /Developer/CamelBones; that's the one that gets copied into .app bundles for GUI apps. It also installs a "shared" framework in /Library/Frameworks, and a Perl module that uses that framework under /Library/Perl, so you can use those from standalone .pl scripts.

Because a .pl file isn't a bundle, you can't package it up with an embedded copy of the framework. If other people want to use your script, they'll need to install the CamelBones package.

CamelBones and PerlObjCBridge are very similar, but there are some differences.

CamelBones supports subclassing of Cocoa classes.

Cocoa exceptions in CamelBones are caught with an eval {} block. PerlObjCBridge handles exceptions with a callback function.

CamelBones has support for toll-free bridging. If you call a method in scalar context that returns an NSDictionary or NSArray, you get an object returned. But, if you call it in list context, you get a tied hash or array instead. So you can use "for (keys %foo)" instead of NSEnumerator to access the elements of an NSDictionary, for instance.

The toll-free bridging works the other way too - you can pass an array or hash ref wherever an NSArray or NSDictionary is expected. NSPoint, NSRange, NSRect, and NSSize structs can also be passed as array or hash refs.

With CamelBones, the trailing underscore when you call Cocoa methods that take one or more arguments is optional. So you could write either $object->doFoo_($bar) or $object->doFoo($bar). PerlObjCBridge requires the trailing underscore.

Of course, there's this:
use CamelBones qw(:All); # Or qw(:Foundation) if you don't want AppKit imports
vs. this:
    use PerlObjCBridge;

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Reply via email to