Use Perl class in Xojo

Is it possible to use or address a Perl class from Xojo? And if so, how?

This was discussed at http://computer-programming-forum.com/14-realbasic/e5d120b350e67ecc.htm without much solution.

AFAIK there is no way to use a Perl class in Xojo the way you would do it in PHP.

You may want to consider rewriting the script in Xojo.

Web does not support shell, but maybe you could call a perl script through HTTPSocket with URL parameters, and have the script send data back as a page you fetch in the HTTPSocket.PageReceived event. Could work if speed is not an issue.

just run perl or php on a webserver and call it via HTTPSocket.

Thanks.

Speed and relyability are an issue. I trie to work around one of the many limitations in Xojo.

Couldn’t you build perlembed into a plugin? perlembed
I would be interested in having a perl interpreter available to my apps… Otherwise the end user has to have perl installed and configured… Looks like you’d need to compile in DynaLoader. Not a c guru here or I’d see if I could put together a plugin myself…

Well, I did that for PHP and it’s a mess.
The problem is that if you try to use scripts from internet they all expect your script to run in apache environment with some modules installed and some paths being correct. All that is missing in a plugin.

So I really recommend to run the scripts on apache.
You can have an apache on same computer with non public port so you can do whatever you like there.

[quote=87300:@jim mckay]Couldn’t you build perlembed into a plugin? perlembed
I would be interested in having a perl interpreter available to my apps… Otherwise the end user has to have perl installed and configured… Looks like you’d need to compile in DynaLoader. Not a c guru here or I’d see if I could put together a plugin myself…[/quote]

The end user maybe less of an issue than the developer computer which needs Perl installed for debug run.In general, a VPS has a Perl interpreter installed. Xojo Cloud may not, but that’s another channel …

I would expect a script on the local server to be fast.

Thanks all. This question was one of the many attempts to use PayPal and/or other banking API’s with Xojo. They all offer ready classes for PHP, Perl, etc. but not for Xojo. The PayPal classes that are available for Xojo (Realstudio) are outdated and do not communicate.

But the problem is solved. I build my own class from scratch for Mollie (a Dutch bank that offers all possible payments inlcuding PayPal).

I think you have not even tried.

Speed. I built a program that calls through HTTPSocket a hello word script installed on the same server. Time response is not slow at all. It will take far more time for Paypal server to respond than for the script to give its result :

PHP : 0.0014429 sec.
Perl : 0.008976 sec.

This is far from ridiculous as far as web is concerned…

As for reliability, it is as reliable as the server both WE and script is installed on.

I have a function to run both PHP and Perl from within Xojo…I will be back shortly to post them.

I know the question has been answered, but here is the solution for future people who ask… You will need perl installed and this is not a
“drop-it-in” and it works function below…as I’ve torn out proprietary code and only left the “necessary” pieces to show “How-To”…with little arranging you can fit it to any Perl-Xojo needs…the original code is used in a webserver I developed with Xojo to allow perl pages to load… you will need to change the paths appropriately…for future cases to those who stumble-upon this and have trouble, message me and I’ll be glad to help you get it running if you have trouble making the necessary changes.

Function CGI_Perl(.............) As String
  #pragma DisableBackgroundTasks
  Dim CGIScript as string
  Dim fHeader as TextOutputStream
  Dim Header as FolderItem
  Dim XOutFile as FolderItem
  Dim fPerl as TextOutputStream
  Dim Path as FolderItem
  Dim UID as String
  Dim Xout as new Shell
  
  
  //any Unique string will do...
  UID = NewFileSafeUUID
  
  
  #if DebugBuild then
    Path = GetFolderItem("").Parent.Child("temp").Child(UID + ".pl")
    Header = GetFolderItem("").Parent.Child("temp").Child(UID + ".hdr")
    XOutFile = GetFolderItem("").Parent.Child("temp").Child(UID + ".out")
  #else
    Path = GetFolderItem("").Child("temp").Child(UID + ".pl")
    Header = GetFolderItem("").Child("temp").Child(UID + ".header")
    XOutFile = GetFolderItem("").Child("temp").Child(UID + ".out")
    
  #endif
  
  //the included variables ARE NOT REQUIRED but can be used with a perl script...
  //to use QUERY_STRING ... a=1&b=hello world (passing xojo variables to a perlscript)
  CGIScript = "" +_
  "#!C:\\www\\perl\\bin\\perl" + EndOfLine +_
  "$ENV{QUERY_STRING} = '" + QUERY_STRING + "';" + EndOfLine +_
  "$ENV{REMOTE_ADDR} = '" + REMOTE_ADDR + "';" + EndOfLine + _
  "$ENV{SERVER_SOFTWARE} = '" + "iAnu Webserver/1.2" + "';" + EndOfLine + _
  "$ENV{GATEWAY_INTERFACE} = '" + "CGI/1.1" + "';" + EndOfLine  +_
  "$ENV{DOCUMENT_ROOT} = '" + DOCUMENT_ROOT + "';" + EndOfLine + _
  "$ENV{SERVER_PROTOCOL} = '" + "HTTP/1.1" + "';" + EndOfLine + _
  "$ENV{REQUEST_METHOD} = '" + REQUEST_METHOD + "';" + EndOfLine + _
  "$ENV{SERVER_ADDR} = '" + SERVER_ADDR + "';" + EndOfLine + _
  "$ENV{SCRIPT_FILENAME} = '" + SCRIPT_FILENAME + "';" + EndOfLine +  _
  "$ENV{SCRIPT_NAME} = '" + Replace(SCRIPT_NAME, "/", "\") + "';" + EndOfLine + _
  "$ENV{SERVER_NAME} = '" + SERVER_NAME + "';" + EndOfLine + _
  "$ENV{SERVER_PORT} = '" + str(SERVER_PORT) + "';" + EndOfLine + _
  "$ENV{HTTP_USER_AGENT} = '" + HTTP_USER_AGENT + "';" + EndOfLine  +_
  "$ENV{HTTP_REFERER} = '" + HTTP_REFERER + "';" + EndOfLine  +_
  "$ENV{HTTP_ACCEPT_LANGUAGE} = '" + HTTP_ACCEPT_LANGUAGE + "';" + EndOfLine + _
  "$ENV{HTTP_ACCEPT} = '" + HTTP_ACCEPT + "';" + EndOfLine + _
  "$ENV{HTTP_COOKIE} = '" + HTTP_COOKIE + "';" + EndOfLine  +_
  "$ENV{CONTENT_TYPE} = '" + CONTENT_TYPE + "';" + EndOfLine + _
  "$ENV{CONTENT_LENGTH} = '" + CONTENT_LENGTH + "';" + EndOfLine + _
  "$ENV{PATH_INFO} = '" + DOCUMENT_ROOT + "';" + EndOfLine  +_
  "open STDIN," + chr(34)+ Header.AbsolutePath + chr(34) + ";" + EndOfLine + _
  "do '" + path.AbsolutePath + "';" + EndOfLine + _
  "close STDIN;"
  
  
  Dim ppath as FolderItem 
  #if DebugBuild then
    ppath = GetFolderItem("").Parent.Child("perl").Child("bin").Child("perl.exe")
  #else
    ppath = GetFolderItem("").Child("perl").Child("bin").Child("perl.exe")
  #endif
  
''you may need to increase the xout.timeout if the script will take some time.

  Xout.Execute "cmd /c " + ppath.ShellPath + " " + GetFolderItem(SCRIPT_FILENAME).ShellPath + ">" + XOutFile.ShellPath
  
  Xout.Close
  
  'alernately if you don't wish the contents to be output to file, you can return xout.Result and remove the > xoutfile.shellpath
  return XOutFile.ShellPath
End Function

[quote=87521:@Matthew Combatti] know the question has been answered, but here is the solution for future people who ask… You will need perl installed and this is not a
“drop-it-in” and it works function[/quote]

Thank you Matthew. This is for PC, right ?

For Mac, Perl and PHP are already in the system and scripts can be run with a shell to “Perl <myscript.pl>” or “php <myscript.php>”.

yes…using the above you can tailor it for mac and linux using the correct paths though (ie to feed variables to your php/perl scripts…for seamless interaction between xojo and your scripts)

Passing CGIScript string an argument to the perl executable (left that part out)

IMPORTANT : This is in the WEB channel, whereas we started discussing shell solutions that work only for Desktop. Sorry for the OT.

Web should use the HTTPSocket method posted above.

The shell solutions would work, they’re just another way to do the same thing.

Why did I think Web did not have Shell ? The LR states : “Used to execute Unix or DOS shell commands under Windows, OS X, or Linux.”. No Web.

But it does work fine. So indeed it is better, as it does not go through http, and is probably faster. Thanks.