SourceForge Project Home
Submit a bug
This is a very high-level overview of the functionality that BSFPerl provides. The current implementation details are a bit counter-intuitive and are not documented particularly well at the moment.
BSFPerl overloads Perl's import function so that you can also import Java classes into your
script. Because '
When import is invoked on a Java class, it will create a Perl package named with the class
part of the import (e.g.,
BSFPerl treats a method call to
Method calls on proxy objects will also be forwarded to Java. Various data type conversions will be performed both on the input arguments as well as the return value.
Here's an example that covers all of this functionality:
import javax::swing::JFrame; import javax::swing::JButton; import java::awt::BorderLayout; my $f = new JFrame("test"); my $b = new JButton("Go"); $f->getContentPane->setLayout(new BorderLayout()); $f->add($b); $f->pack; $f->setVisible(1);
This example will create a JFrame and display it to the user. Unfortunately, there is currently no way to implement Java interfaces from BSFPerl. This means that you cannot register an ActionListener from Perl. In future versions of BSFPerl, this will be changed so that an anonymous subroutine can be passed in place of the interface or bound to specific methods in the interface.
Note: To distinguish numeric from non-numeric scalars, we actually cheat a little bit. Although it's not supposed to expose it, Perl does differentiate between values that it thinks are strings and those that it thinks are numeric. It will freely convert between them when necessary, but it also uses this information in a few cases. In particular, the bitwise XOR operator behaves differently depending on whether its arguments are numeric (meaning they were parsed as unquoted numeric literals, or they were the result of some arithmetic calculation) or non-numeric (meaning that they were quoted literals, could not be parsed as a numeric value, or were the result of a non-arithmetic calculation). To differentiate integer vs. floating-point numerics we simply use a regular expression of BSFPerl's parsing logic.