Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^4: Exporter Problem

by osler (Sexton)
on Feb 20, 2013 at 02:23 UTC ( #1019684=note: print w/replies, xml ) Need Help??

in reply to Re^3: Exporter Problem
in thread Exporter Problem

Thanks for the recommendation. I think the issue is that Lingua::StanfordCoreNLP has the java code in the __DATA__ section of the PM file. My understanding is that the __DATA__ section is not read until runtime so the perl bindings to the java classes and methods can't happen until runtime. I was trying to create a Lingua::StanfordCoreNLP::Pipeline object in my package to store it as a package global. Doing this at that time, the Pipeline object is not defined yet.

My work around is to create the pipeline object at runtime and pass it along to the new method of my package.

I am also having trouble with using inline::java in a mod_perl environment -- there is information about this problem in the docs. I will pursue an Inline::Java thread if I run into more problems.

Thanks for your help!

Replies are listed 'Best First'.
Re^5: Exporter Problem
by syphilis (Chancellor) on Feb 20, 2013 at 03:18 UTC
    I think the issue is that Lingua::StanfordCoreNLP has the java code in the __DATA__ section of the PM file

    Doesn't seem to be an issue with Inline::C - though, faik, that might be quite irrelevant wrt Inline::Java.

    With a site/lib/FOO/ that contains:
    package FOO::Soldier; use warnings; use strict; use Inline 'C'; 1; __DATA__ __C__ typedef struct { char* name; char* rank; long serial; } Soldier; SV* new(char* class, char* name, char* rank, long serial) { Soldier* soldier; SV* obj_ref = newSViv(0); SV* obj = newSVrv(obj_ref, class); New(42, soldier, 1, Soldier); soldier->name = savepv(name); soldier->rank = savepv(rank); soldier->serial = serial; sv_setiv(obj, (IV)soldier); SvREADONLY_on(obj); return obj_ref; } char* get_name(SV* obj) { return ((Soldier*)SvIV(SvRV(obj)))->name; } char* get_rank(SV* obj) { return ((Soldier*)SvIV(SvRV(obj)))->rank; } long get_serial(SV* obj) { return ((Soldier*)SvIV(SvRV(obj)))->serial; } void DESTROY(SV* obj) { printf("Destroy called\n"); Soldier* soldier = (Soldier*)SvIV(SvRV(obj)); Safefree(soldier->name); Safefree(soldier->rank); Safefree(soldier); }
    I can run the following script without any trouble:
    package MyPackage; use warnings; use strict; use FOO::Soldier; my $obj1 = FOO::Soldier->new('Benjamin', 'Private', 11111); my $obj2 = FOO::Soldier->new('Sanders', 'Colonel', 22222); my $obj3 = FOO::Soldier->new('Matt', 'Sergeant', 33333); for my $obj ($obj1, $obj2, $obj3) { print $obj->get_serial, ") ", $obj->get_name, " is a ", $obj->get_rank, "\n"; }
    which outputs (as expected):
    11111) Benjamin is a Private 22222) Sanders is a Colonel 33333) Matt is a Sergeant Destroy called Destroy called Destroy called
    Good luck with it!

      Rob, But if you load your module in a file containing:
      use MyPackage ;
      then it fails with:
      Can't locate object method "new" via package "FOO::Soldier" at line 7.
      Compilation failed in require at line 3.
      BEGIN failed--compilation aborted at line 3.
      One or more DATA sections were not processed by Inline.
      I think this has to do with the eval'd INIT block in around line 200. I think it runs at "run" time, while all the "use" stuff runs at compile time. So it's basically not run yet. If you call:
      Inline->init() ;
      just before creating the FOO::Solfier objects it will fix the problem. Patrick
        Hi Patrick,
        Yes, I now recall this Inline->init(); trick having cropped up before - though I can't quite recall the context.

        I had the impression from earlier postings in this thread that, wrt Inline::Java, it wasn't necessary to load a to strike the problem. Instead it was enough to merely load the Inline::Java module into another namespace (as per my Inline::C demo).
        Perhaps that's not so - I don't currently have Inline::Java installed and therefore can't check that for myself.

        Anyway, if Inline::C and Inline::Java aren't in exactly the same boat here, it looks like they're at least part of the same fleet ;-)

        Hopefully Inline->init(); will solve the OP's problems.
        Thanks for chiming in, Patrick !

        Worked perfectly, thanks!!!!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019684]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-06-20 04:56 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.