Using Perl in Cocoa

2005-10-26 Thread Manfred Bergmann

Hi there.

Er, I first had to find out that this is a mailing list and no  
newsgroup. I signed at google groups, posted messages and wondered  
why they actually are not there when I browsed the list at  
nntp.perl.org. At www.perl.org I actually figured that this is a  
list. Ohh dear.
So if the messages that I've send through google are arriving after  
all, i'd like to appologize just now. :)


I am almost new to Perl. I like it and tried to use it in some of my  
Cocoa Projects.


Just calling perl subroutines from C in't a problem with embedding a  
Perl Interpreter. But passing arguments from and to the perl script  
over pipe isn't what I want. If I could pass and get arguments or  
variables in a OO manner that would be great. If nothing else works,  
I probably have to deal with the pure C solution. But I first wanted  
to test other possibilities.
I found there are two approaches. PerlObjCBridge and CamelBones.  
Unfortunately I couldn't find any examples covering what I try to do.  
I tested it with CamelBones first. Maybe someone can tell me whether  
this would be possible with PerlObjCBridge, too.



I played a bit and that's what I figured so far. But unfortunately
I wasn't successfull in creating a CBPerlObject. I tried it from a
Foundation Project.

objc_code
#import Foundation/Foundation.h
#import CamelBones/CamelBones.h

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// create perl interpreter
CBPerl *perl = [[CBPerl alloc] init];
//[perl useWarnings];   // activate warnings
//[perl useLib:modulePath];
[perl useModule:@SomePerl];
[perl eval:@$somePerl = new SomePerl];
CBPerlObject *perlO = [perl namedObject:@somePerl];

[pool release];

return 0;

}
/objc_code

The SomePerl.pm file looks like this:

perl_code
package SomePerl;

use strict;
use warnings;

sub new
{
my $class = shift;
my %attr = @_;
my $self = { %attr };
return bless ($self,$class);

}

1;
__END__
/perl_code

The -namedObject: returns a nil pointer, so something goes wrong  
there, but I couldn't figure out what.
As you can see I sent the -useLib: message and extended the library  
search path to where the SomePerl.pm module is. So I guess the module  
itself should be found.

Can someone please give me some hints?

Thx,
Manfred




Re: Using Perl in Cocoa

2005-10-26 Thread Manfred Bergmann

Thanks sherm for replying.


Am 27.10.2005 um 11:50 schrieb Sherm Pendley:



CBPerl is a singleton, so it's better to use the class method to  
access the shared instance:


CBPerl *perl = [CBPerl sharedPerl];


That doesn't work here. Get a nil pointer returned.


Should be:

id perlO = [[NSClassFromString(@SomePerl) alloc] init];

Note that perlO is typed as id. That's necessary because the  
compiler doesn't know about the SomePerl class at compile time. The  
call to NSClassFromString() is needed for the same reason.


That either returns a nil pointer. Where does the ObjC runtime system  
look for the SomePerl.pm file.

I placed it in some locations, so it should be found by whom ever. ;)
How does this work in general, maybe I can figure out where the  
problem is.




SomePerl.pm should look like this:

package SomePerl;

use CamelBones qw(:All);

use strict;
use warnings;

class SomePerl {
'super' = 'NSObject',
'properties' = [ 'foo', 'bar', 'baz' ],
};

sub init : Selector(init) ReturnType(@) {
my ($self) = @_;
$self = $self-SUPER::init();

# Do other initialization

return $self;
}



Ok, done that.


Regards,
Manfred



Re: Using Perl in Cocoa

2005-10-26 Thread Manfred Bergmann

Ok, that worked. Thanks.

Hmm, how come that I couldn't find any documentation about this? All  
I found was a little example code on a japaneese internet site where  
you couldn't read anything except the code snippet itself. :) This  
was, as you said, an old example with CBPerlObject but it gave me a  
hint how to begin at all with that.

Or maybe I am just incapable of searching in the internet. ;)
I figured CamelBones is pretty nice, not only for doing complete Perl- 
Cocoa applications for which a lot of examples exist.


Ok, another question.
I guess the Xcode codesence is not working for any Perl classes and  
methods, right?
And can I somehow get rid of the warning message from gcc that the  
object xxx might not respond to method yyy if calling a method of a  
Perl class?


Manfred



Am 27.10.2005 um 13:02 schrieb Sherm Pendley:


On Oct 26, 2005, at 10:27 PM, Manfred Bergmann wrote:



Am 27.10.2005 um 11:50 schrieb Sherm Pendley:


CBPerl is a singleton, so it's better to use the class method to  
access the shared instance:


CBPerl *perl = [CBPerl sharedPerl];



That doesn't work here. Get a nil pointer returned.



I forgot a recent addition, sorry. Should be:

#import CamelBones/AppMain.h
[CBPerl stubInit: CBGetPerlArchver()];
CBPerl *perl = [CBPerl sharedPerl];



id perlO = [[NSClassFromString(@SomePerl) alloc] init];

Note that perlO is typed as id. That's necessary because the  
compiler doesn't know about the SomePerl class at compile time.  
The call to NSClassFromString() is needed for the same reason.




That either returns a nil pointer. Where does the ObjC runtime  
system look for the SomePerl.pm file.




As far as the ObjC runtime goes, if a class hasn't yet been  
registered, it calls a CamelBones class handler function. That  
function tries to do an ordinary use ClassName to try to load and  
register the class. That use looks in the standard @INC.


When CamelBones starts up, it adds the Resources/ sub-directories  
of all linked frameworks and bundles (including the .app bundle) to  
@INC, and platform- and version- specific subdirectories under  
that. For instance, on Tiger it would add:


Resources/
Resources/5.8.6/
Resources/5.8.6/darwin-thread-multi-2level/

This is repeated whenever a new bundle is loaded by way of NSBundle  
methods - any Objective-C classes in the bundle are automatically  
wrapped to be visible from Perl, and the bundle's Resources/ sub- 
directory is added to @INC.


sherm--

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






Howto access Perl Objects from Cocoa

2005-10-27 Thread Manfred Bergmann

Hi there.

I am almost new to Perl. I like it and tried to use it in some of my 
Cocoa Projects.


First of all. I found there are two approaches. PerlObjCBridge and 
CamelBones. Unfortunately I couldn't find any examples covering what I 
try to do. I tested it with CamelBones first. Maybe someone can tell me 
whether this would be possible with PerlObjCBridge, too.



I played a bit and that's what I figured so far. But unfortunately
I wasn't successfull in creating a CBPerlObject. I tried it from a
Foundation Project.

objc_code
#import Foundation/Foundation.h
#import CamelBones/CamelBones.h

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// create perl interpreter
CBPerl *perl = [[CBPerl alloc] init];
//[perl useWarnings];   // activate warnings
//[perl useLib:modulePath];
[perl useModule:@SomePerl];
[perl eval:@$somePerl = new SomePerl];
CBPerlObject *perlO = [perl namedObject:@somePerl];

[pool release];

return 0;

}
/objc_code

The SomePerl.pm file looks like this:

perl_code
package SomePerl;

use strict;
use warnings;

sub new
{
my $class = shift;
my %attr = @_;
my $self = { %attr };
return bless ($self,$class);

}

1;
__END__
/perl_code

What I don't understand is, where do I have to put the SomePerl.pm file
so that code above finds it. I guess it can be somewhere but then I have 
to explicitly say so by calling [perl useLib:pathOfPMFile], right?


The -namedObject: returns a nil pointer, so something ggoes wrong there, 
but I couldn't figure out what.

Can someone please give me some hints?

Thx,
Manfred


Re: Howto access Perl Objects from Cocoa

2005-10-27 Thread Manfred Bergmann


Am 28.10.2005 um 04:32 schrieb Sherm Pendley:


On Oct 26, 2005, at 7:19 PM, Manfred Bergmann wrote:


I am almost new to Perl. I like it and tried to use it in some of  
my Cocoa Projects.


First of all. I found there are two approaches. PerlObjCBridge and  
CamelBones. Unfortunately I couldn't find any examples covering  
what I try to do. I tested it with CamelBones first. Maybe someone  
can tell me whether this would be possible with PerlObjCBridge, too.




Looks like your message to nntp.perl.org finally got here. ;-)



Yea, took some time but it finally arrived.
Lets see if the messages sent through google also will arrive. I have  
sent one on the 23th. :/
I really don't understand this. Are the messages sent through google  
only available for users who browse the news with google?

Anyway.

I've posted my small CamelBones example in a german OSX developer  
forum and some guys where very happy about it.



Manfred



Re: ANN: CamelBones 1.0.0-beta4, ShuX 3.0-beta3

2005-10-27 Thread Manfred Bergmann

These new releases bring experimental Intel compatibility to both the
CamelBones framework and ShuX. In addition, there have been a few
minor bug fixes and additions to CamelBones - see the included
release notes for details.
I've read in earlier posts that you were concerned about the intel  
port because of something with libff (libffi).
Does this version mean, you have have a solution to this and fixed or  
implemented it already?



Manfred



Foundation in Perl script

2005-12-28 Thread Manfred Bergmann

Hi list.

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?


Thx,
Manfred



Re: Foundation in Perl script

2005-12-28 Thread Manfred Bergmann

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





Perl Modules and Universal Binary

2006-03-13 Thread Manfred Bergmann

Hi there.

I use some Perl Modules in some of my application, accessed through  
Camelbones.
I have notices that some Perl Modules use compiled C-Code, e.g. HTML- 
Parser.

Now how does it work to build these modules as Universal Binaries?
Although my application is build as Universal Binary and I have been  
told that it works with Intel-Macs the only thing that is not Intel  
native are some Perl Modules that I use. The reason that it works  
even on Intel-Macs with a PPC compiled Perl Module is Rosetta I guess.

Has someone experiences with that and can give me some hints?


Best regards,
Manfred



Re: Perl Modules and Universal Binary

2006-03-13 Thread Manfred Bergmann


Am 13.03.2006 um 23:38 schrieb Dominic Dunlop:


On 2006–03–13, at 12:53, Manfred Bergmann wrote:
I use some Perl Modules in some of my application, accessed  
through Camelbones.
I have notices that some Perl Modules use compiled C-Code, e.g.  
HTML-Parser.

Now how does it work to build these modules as Universal Binaries?


The README.macosx distributed with perl-5.8.8 tells you how to make  
a universal binary perl. Once you have built and installed such a  
perl, any modules that you build using that perl should end up as  
universal binaries.


But that means I have to replace the existing Perl with the new one.
I would do it but I fear I that could break some things in the system.


Best regards,
Manfred



Re: Perl Modules and Universal Binary

2006-03-13 Thread Manfred Bergmann


Am 14.03.2006 um 05:29 schrieb Edward Moy:


On Mar 13, 2006, at 4:38 AM, Dominic Dunlop wrote:


On 2006–03–13, at 12:53, Manfred Bergmann wrote:
I use some Perl Modules in some of my application, accessed  
through Camelbones.
I have notices that some Perl Modules use compiled C-Code, e.g.  
HTML-Parser.

Now how does it work to build these modules as Universal Binaries?


The README.macosx distributed with perl-5.8.8 tells you how to  
make a universal binary perl. Once you have built and installed  
such a perl, any modules that you build using that perl should end  
up as universal binaries.


Although my application is build as Universal Binary and I have  
been told that it works with Intel-Macs the only thing that is  
not Intel native are some Perl Modules that I use. The reason  
that it works even on Intel-Macs with a PPC compiled Perl Module  
is Rosetta I guess.


Well, maybe. I can't see why Rosetta would make ppc-architecture  
XS modules work on an Intel Mac, unless the properties of /usr/bin/ 
perl had been tweaked (I believe it's done via Get Info) to make  
it always run under Rosetta.



Has someone experiences with that and can give me some hints?


In the modules I've tried:

% make 'PASTHRU_INC=-arch i386 -arch ppc' 'OTHERLDFLAGS=-arch i386 - 
arch ppc'


was sufficient to build a 2-way universal (this is how Apple builds  
the extra CPAN modules).


I understand there are some modules that don't uses these  
variables, so hacking of the Makefile may be necessary.


Now that I think about it, we use universal systems, so I can't say  
that I've actually tried it on a non-universal system.  Seems to me  
it should work, since the bundles don't need to resolve all their  
symbols (including from libSystem).  Let me know if it doesn't  
work, as then Apple will need to figure out a solution.


That seemed to word although I couldn't test it on a intel system but  
the result of making the HTML-Parser (Parser.bundle) is a universal  
binary.


Thx,
Manfred



Re: Storable problem on Intel Mac Mini

2006-05-12 Thread Manfred Bergmann


Am 12.05.2006 um 13:05 schrieb Joel Rees:



On 2006.5.12, at 10:01 AM, Mike Schienle wrote:



Hi all -

I just installed an Intel Mac Mini as a replacement for a dual 1.8  
GHz G5 at

my colocation place a couple days ago.


Can I ask a silly question in public, or would off-list be more  
appropriate?




There are no silly questions only stupid answeres. ;)


Manfred



Tk Aqua with Perl

2006-05-15 Thread Manfred Bergmann

Hi guys.

TclTk Aqua is shipped with Mac OSX Tiger.

Is it somehow possible to use it with Perl?
The Perl/Tk bindings are only for X11, right?


Regards,
Manfred



Re: Tk Aqua with Perl

2006-05-16 Thread Manfred Bergmann


Am 16.05.2006 um 07:11 schrieb David H. Adler:


On Mon, May 15, 2006 at 03:37:08PM -0700, Jan Dubois wrote:

You should be able to do this with the Tcl::Tk module:

http://search.cpan.org/~vkon/Tcl-Tk/

The Tkx module provides a nice interface on top of Tcl::Tk:

http://search.cpan.org/~gaas/Tkx/

I have not tried this on OS X though, so it is possible that
the modules don't work out of the box there.


I haven't checked lately, but it used to be that Perl/Tk wouldn't
compile on OS X unless you configured your perl a certain way. This  
may

have changed since I last looked, but be sure to look over the docs if
you hit any problems, as that might be it.



Perl/Tk works and compiles fine on OSX.
Had no problems so far.


Regards,
Manfred




Re: Tk Aqua with Perl

2006-05-16 Thread Manfred Bergmann


Am 16.05.2006 um 08:26 schrieb Jan Dubois:


On Mon, 15 May 2006, David H. Adler wrote:

On Mon, May 15, 2006 at 03:37:08PM -0700, Jan Dubois wrote:

You should be able to do this with the Tcl::Tk module:

http://search.cpan.org/~vkon/Tcl-Tk/

The Tkx module provides a nice interface on top of Tcl::Tk:

http://search.cpan.org/~gaas/Tkx/

I have not tried this on OS X though, so it is possible that the
modules don't work out of the box there.


I haven't checked lately, but it used to be that Perl/Tk wouldn't
compile on OS X unless you configured your perl a certain way. This
may have changed since I last looked, but be sure to look over the
docs if you hit any problems, as that might be it.


Tcl::Tk and Tkx don't use the Perl/Tk module; they call the Tcl/Tk  
code

directly. That way you get access to the latest widgets supported by
Tcl/Tk. Of course you need a working Tcl installation in addition to
just Perl. We use this at ActiveState to create natively themed cross
platform Perl applications for Windows, Linux, Solaris and HP-UX.

I have heard from other people at ActiveState that they got this to  
work

on OS X too, but I don't remember if they had to do anything special.



I tried Tkx which needs the Tcl module and this module needs to init  
tcl and I get an error that the file init.tcl is missing on my  
standard Tiger installation.


I know, this a bit offtopic but does anyone know how I can expand the  
TCL include path?

The file init.tcl is here:
/System/Library/Frameworks/Tcl.framework/Versions/8.4/Resources/ 
Scripts/init.tcl


Well, I could symlink the file to where tclinit looks for...

---
Failed to initialize Tcl with Tcl_Init:
Can't find a usable init.tcl in the following directories:
@TCL_IN_FRAMEWORK@ /usr/lib/tcl8.4 /lib/tcl8.4 /usr/library / 
library /tcl8.4.7/library @TCL_IN_FRAMEWORK@




This probably means that Tcl wasn't installed properly.

while executing
error $msg
(procedure tclInit line 42)
invoked from within
tclInit at /System/Library/Perl/5.8.6/darwin-thread-multi-2level/ 
DynaLoader.pm line 253.
Unable to initialize Tcl at /System/Library/Perl/5.8.6/darwin-thread- 
multi-2level/DynaLoader.pm line 253.

Compilation failed in require at /Library/Perl/5.8.6/Tkx.pm line 206.
---


Best regards,
Manfred



Re: Tk Aqua with Perl

2006-05-16 Thread Manfred Bergmann

Hi.


Von: Manfred Bergmann [EMAIL PROTECTED]
Datum: 16. Mai 2006 10:35:02 MESZ
An: OSX Group Perl macosx@perl.org
Betreff: Re: Tk Aqua with Perl


Am 16.05.2006 um 08:26 schrieb Jan Dubois:


On Mon, 15 May 2006, David H. Adler wrote:

On Mon, May 15, 2006 at 03:37:08PM -0700, Jan Dubois wrote:

You should be able to do this with the Tcl::Tk module:

http://search.cpan.org/~vkon/Tcl-Tk/

The Tkx module provides a nice interface on top of Tcl::Tk:

http://search.cpan.org/~gaas/Tkx/

I have not tried this on OS X though, so it is possible that the
modules don't work out of the box there.


I haven't checked lately, but it used to be that Perl/Tk wouldn't
compile on OS X unless you configured your perl a certain way. This
may have changed since I last looked, but be sure to look over the
docs if you hit any problems, as that might be it.


Tcl::Tk and Tkx don't use the Perl/Tk module; they call the Tcl/Tk  
code

directly. That way you get access to the latest widgets supported by
Tcl/Tk. Of course you need a working Tcl installation in addition to
just Perl. We use this at ActiveState to create natively themed cross
platform Perl applications for Windows, Linux, Solaris and HP-UX.

I have heard from other people at ActiveState that they got this  
to work

on OS X too, but I don't remember if they had to do anything special.



I tried Tkx which needs the Tcl module and this module needs to  
init tcl and I get an error that the file init.tcl is missing on my  
standard Tiger installation.


I know, this a bit offtopic but does anyone know how I can expand  
the TCL include path?

The file init.tcl is here:
/System/Library/Frameworks/Tcl.framework/Versions/8.4/Resources/ 
Scripts/init.tcl


Well, I could symlink the file to where tclinit looks for...

---
Failed to initialize Tcl with Tcl_Init:
Can't find a usable init.tcl in the following directories:
@TCL_IN_FRAMEWORK@ /usr/lib/tcl8.4 /lib/tcl8.4 /usr/library / 
library /tcl8.4.7/library @TCL_IN_FRAMEWORK@




This probably means that Tcl wasn't installed properly.

while executing
error $msg
(procedure tclInit line 42)
invoked from within
tclInit at /System/Library/Perl/5.8.6/darwin-thread-multi-2level/ 
DynaLoader.pm line 253.
Unable to initialize Tcl at /System/Library/Perl/5.8.6/darwin- 
thread-multi-2level/DynaLoader.pm line 253.

Compilation failed in require at /Library/Perl/5.8.6/Tkx.pm line 206.
---


I finally got Tkx working.

The Perl Tcl error can be fixed by setting the env var:
TCL_LIBRARY=/System/Library/Frameworks/Tcl.framework/Versions/Current/ 
Resources/Scripts



Best regards,
Manfred



Re: Should Mac::PropertyList read everything as UTF8

2006-05-18 Thread Manfred Bergmann


Am 18.05.2006 um 16:01 schrieb Gavin Brock:




   * Actually hook into the Mac libraries and let the OS parse it and
give me back the data. That's the best solution, but only if I  
give up

being pure-Perl and portable, which are both very important to me. I
will gladly add something to do that if someone writes it for me, but
alongside the pure Perl version.

   * Can I hook into the Mac stuff with something like Inline::Java?


Actually, you can do this without resorting to Java - there was a  
great article on using the Objective-C bridge (Foundation.pm) at:


http://www.macdevcenter.com/pub/a/mac/2005/07/29/plist.html



You also can use Camelbones for reading and writing PropertyLists in  
Perl.

I use it in my build processes and it works great.


Manfred




Re: Tk Aqua with Perl

2006-05-19 Thread Manfred Bergmann


Am 19.05.2006 um 03:55 schrieb Robert Hicks:


Jan Dubois wrote:

On Mon, 15 May 2006, Manfred Bergmann wrote:

TclTk Aqua is shipped with Mac OSX Tiger.

Is it somehow possible to use it with Perl?

You should be able to do this with the Tcl::Tk module:
http://search.cpan.org/~vkon/Tcl-Tk/
I get a whole lot of errors when I try to install Tcl::Tk. I am  
using AS Perl and AS Tcl.


=== ERROR ===
Tcl config file '/usr/local/lib/tclConfig.sh' not found
Running make test
  Make had some problems, maybe interrupted? Won't test
Running make install
  Make had some problems, maybe interrupted? Won't install
=

Should I try the Tkx one?


Didn't try the Tcl::Tk module.
Tkx works for me. Maybe you should try it. It also has a better  
documentation. At least I didn't find one for Tcl::Tk.



Manfred