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.