I was able to get Inline::Java working from withing a perl OO module today. However, I was hoping to be able to put all of the inline code in one method and then be able to instantiate objects from this one instance of the inline code throughout the perl module.

However, attempting to do this did not seem to work, and I was not able to persist the inline java to the rest of the perl object. I turned on the debug mode in inline and I saw that it was adding the java class to the namespace of the perl module as I was hoping for. But I wanted to avoid having to replicate the inline code in other methods throughout this module. I suspect the problem is related to lexical scoping and how inline java works. Has anyone accomplished anything like this before?



Here is the pseudo code of what I hope to accomplish
package ABC; sub new { .... } sub init { my $self = shift; use Inline Java << EOJ , .... .... EOJ ; $self->{obj} = ABC::javasclassfrominline->new() } sub somemethod { my $self = shift; $self->{obj}->callsomejavamethod(); } 1;

Update: Thanks guys, I ended up putting the code outside as fmerges suggested. I stuck it in a second BEGIN block and I was able to call it as I was hoping to.


In reply to Inline Java in a Perl OO Module by tmaly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.