Jay,

I just uploaded 0.53_90 to CPAN, you must use that version for what
you want to do. There is an example in there:

http://cpansearch.perl.org/src/PATL/Inline-Java-0.53_90/Java/PerlInterpreter/t/02_perl_interpreter.t

At the end on that file there is a Java program that creates a
PerlInterpreter, loads a Perl script and calls
a function in it. I added an example where the Perl code processes a
ArrayList object (sum_array_list).

The Perl script loaded is here:
http://cpansearch.perl.org/src/PATL/Inline-Java-0.53_90/Java/PerlInterpreter/t/Tests.pl


Patrick



On Wed, Jan 12, 2011 at 2:46 PM, Jay Strauss <m...@heyjay.com> wrote:
> Hi Patrick, thanks for the quick response.
> I'm looking at the POD now.
> I see that you're creating a pi, then doing pi.eval, which I believe is
> doing a perl eval{} around the string being passed.
> do you have any examples of calling a perl module?  (i tried to find
> something in the tests) Maybe even walking a java variable?
> Thanks
> Jay
>
> On Wed, Jan 12, 2011 at 12:25 PM, Patrick LeBoutillier
> <patrick.leboutill...@gmail.com> wrote:
>>
>> Jay,
>>
>> You need to use the Inline::Java::PerlInterpreter for that:
>>
>> http://search.cpan.org/~patl/Inline-Java-0.53/Java/PerlInterpreter/PerlInterpreter.pod
>>
>> Once your interpreter is created you can call Callback methods on it:
>> require, CallPerlSub, eval...
>>
>> Note: Keep in mind that Inline::Java::PerlInterpreter is experimental, so
>> YMMV.
>>
>>
>> Patrick
>>
>>
>> On Wed, Jan 12, 2011 at 1:01 PM, Jay Strauss <m...@heyjay.com> wrote:
>> > Hi,
>> >
>> > 2 questions:
>> >
>> > 1) why do call yourself Sisyphus?  Is it really all for meaningless,
>> > endless
>> > :)
>> >
>> > 2) I'd like to call some perl from a running Java process.  I'm using a
>> > vendor api and framework to build custom code.  The way it works is I
>> > have
>> > to write some java (see below), then compile within Eclipse using a
>> > supplied
>> > Ant xml, which turns my code into a Jar that is deployed onto the
>> > server.
>> >  The vendor's Java app reads a DB that indicates where the Jar is
>> > located
>> > and the class and method to call under various situations.
>> >
>> > I've written a Inline::Java callback in the past, but it was initiated
>> > via
>> > Perl.  That is, I launched a perl process, that then instantiated some
>> > Java
>> > that in turn called back into the perl.
>> >
>> > In reading the callback docs I can't seem to grok how to make it all
>> > happen
>> > from Java and my Jar correctly.
>> >
>> > Below is the code.
>> >
>> > Any guidance would be hugely appreciated.
>> >
>> > Thanks
>> > Jay
>> >
>> > // this is just some test code
>> > // that doesn't really do anything but write to a file
>> >
>> > package com.my.stuff;
>> > import java.io.*;
>> > import vendorapi.mpi.*;
>> > import vendorapi.handler.*;
>> > import java.util.Map;
>> > import java.util.Date;
>> > import java.text.SimpleDateFormat;
>> >
>> > public class FileHandler extends HandlerExtBase
>> > {
>> > // Class-specific members used as keys in the handlerArgs to identify
>> > // the pre and post-ixn filename(s)
>> >
>> > private static final String ARG_PREFILENAME  = "preFileName";
>> > private static final String ARG_POSTFILENAME = "postFileName";
>> >  // Instance-specific members initialized during the overridden init()
>> > method
>> >
>> > private String preFileName = null;
>> > private String postFileName = null;
>> >  public void init(Context ctx, String handlerArgs)
>> > {
>> >  Map<?, ?> argsMap = parseArgs(handlerArgs);
>> > String madHomeDir = System.getenv("MAD_HOMEDIR");
>> >
>> > // Create the pre- and post- files in the MAD_HOMEDIR directory
>> >
>> > if (argsMap.containsKey(ARG_PREFILENAME))
>> >  {
>> > preFileName = madHomeDir + File.separator + "log" + File.separator +
>> >  (String)argsMap.get(ARG_PREFILENAME);
>> > }
>> >
>> > if (argsMap.containsKey(ARG_POSTFILENAME))
>> >  {
>> > postFileName = madHomeDir + File.separator + "log" + File.separator +
>> >  (String)argsMap.get(ARG_POSTFILENAME);
>> > }
>> >  }
>> >
>> >  protected void writeFile(String fileName, RowList rowList)
>> >  {
>> >
>> > Date todaysDate            = new java.util.Date();
>> > SimpleDateFormat formatter = new SimpleDateFormat();
>> >  String formattedDate       = formatter.format(todaysDate);
>> >
>> > PrintWriter out = null;
>> >  try {
>> > out = new PrintWriter(new BufferedWriter(new FileWriter("c:\\" +
>> > formattedDate + ".txt")));
>> >  out.println(formattedDate);
>> > } catch (IOException e) {
>> > // TODO Auto-generated catch block
>> >  e.printStackTrace();
>> > }
>> >
>> > //
>> >  // I'd like to call Perl at this point and have Perl be
>> > // able to access the RowList instance, so Perl could walk
>> >  // the list.  As opposed to flattening the list in someway
>> > // and shelling out and passing in the flattened list
>> >  //
>> > //
>> >
>> > public void preIxn(IService service) throws CallbackHandlerException
>> > {
>> >  if (preFileName != null)
>> > {
>> > writeFile(preFileName, service.getInpMemRowList());
>> >  }
>> >
>> > }
>> >
>> > public void postIxn(IService service) throws CallbackHandlerException
>> >  {
>> >
>> > if (postFileName != null)
>> > {
>> >  writeFile(postFileName, service.getOutMemRowList());
>> > }
>> >
>> > }
>> > }
>> >
>>
>>
>>
>> --
>> =====================
>> Patrick LeBoutillier
>> Rosemère, Québec, Canada
>
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada

Reply via email to