[libinline-java-perl] 80/398: *** empty log message ***

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:42:50 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.55
in repository libinline-java-perl.

commit 0a2cf5a75d68f227ad268f32826ad997a6775929
Author: patrick <>
Date:   Tue May 8 19:47:15 2001 +0000

    *** empty log message ***
---
 Java.pm          | 464 ++++++++++++++++++++++++++++++++++++++-----------------
 Java.pod         |  81 +++++++++-
 Java/Protocol.pm |   2 +-
 t/08_study.t     |   3 +-
 4 files changed, 400 insertions(+), 150 deletions(-)

diff --git a/Java.pm b/Java.pm
index 9d75948..3373039 100644
--- a/Java.pm
+++ b/Java.pm
@@ -2,12 +2,12 @@ package Inline::Java ;
 @Inline::Java::ISA = qw(Inline Exporter) ;
 
 # Export the cast function if wanted
- at EXPORT_OK = qw(cast) ;
+ at EXPORT_OK = qw(cast study_classes) ;
 
 
 use strict ;
 
-$Inline::Java::VERSION = '0.20' ;
+$Inline::Java::VERSION = '0.21' ;
 
 
 # DEBUG is set via the DEBUG config
@@ -146,6 +146,10 @@ sub _validate {
 	my $o = shift ;
 	my $ignore_other_configs = shift ;
 
+	if ($o->get_INLINE_nb() == 1){
+		croak "Inline::Java does not currently support multiple Inline sections" ;
+	}
+
 	if (! exists($o->{Java}->{PORT})){
 		$o->{Java}->{PORT} = 7890 ;
 	}
@@ -164,6 +168,9 @@ sub _validate {
 	if (! exists($o->{Java}->{WARN_METHOD_SELECT})){
 		$o->{Java}->{WARN_METHOD_SELECT} = '' ;
 	}
+	if (! exists($o->{Java}->{AUTOSTUDY})){
+		$o->{Java}->{AUTOSTUDY} = 0 ;
+	}
 
 	while (@_) {
 		my ($key, $value) = (shift, shift) ;
@@ -195,9 +202,17 @@ sub _validate {
 		elsif ($key eq 'JNI'){
 			$o->{Java}->{$key} = $value ;
 		}
+		elsif ($key eq 'AUTOSTUDY'){
+			$o->{Java}->{$key} = $value ;
+		}
+		elsif ($key eq 'STUDY'){
+			$o->{Java}->{$key} = $o->check_config_array(
+				$key, $value,
+				"Java class names") ;
+		}
 		else{
 			if (! $ignore_other_configs){
-				croak "'$key' is not a valid config option for Inline::Java\n";
+				croak "'$key' is not a valid config option for Inline::Java";
 			}
 		}
 	}
@@ -206,41 +221,30 @@ sub _validate {
 		$o->{Java}->{JNI} = $ENV{PERL_INLINE_JAVA_JNI} ;
 	}
 
-	my $install_lib = $o->{install_lib} ;
-	my $modpname = $o->{modpname} ;
-	my $install = "$install_lib/auto/$modpname" ;
-
-	$o->set_classpath($install) ;
-
 	$o->set_java_bin() ;
 
 	Inline::Java::debug("validate done.") ;
 }
 
 
-# This function builds the CLASSPATH environment variable
-sub set_classpath {
+sub check_config_array {
 	my $o = shift ;
-	my $path = shift ;
+	my $key = shift ;
+	my $value = shift ;
+	my $desc = shift ;
 
-	my @list = () ;
-	if (defined($ENV{CLASSPATH})){
-		push @list, $ENV{CLASSPATH} ;
-	}
-	if (defined($o->{Java}->{CLASSPATH})){
-		push @list, $o->{Java}->{CLASSPATH} ;
+	if (ref($value) eq 'ARRAY'){
+		foreach my $c (@{$value}){
+			if (ref($c)){
+				croak "config '$key' must be an array of $desc" ;
+			}
+		}
 	}
-	if (defined($path)){
-		push @list, $path ;
+	else{
+		croak "config '$key' must be an array of $desc" ;
 	}
 
-	my $sep = portable("ENV_VAR_PATH_SEP") ;
-	my @cp = split(/$sep/, join($sep, @list)) ;
-	my %cp = map { ($_ !~ /^\s*$/ ? ($_, 1) : ()) } @cp ;
-
-	$ENV{CLASSPATH} = join($sep, keys %cp) ;
-
-	Inline::Java::debug("  classpath: " . $ENV{CLASSPATH}) ;
+	return $value ;
 }
 
 
@@ -345,9 +349,11 @@ sub build {
 		return ;
 	}
 
-	$o->write_java ;
+	my $code = $o->{code} ;
+	my $study_only = ($code eq 'STUDY') ;
 
-	$o->compile ;
+	$o->write_java($study_only) ;
+	$o->compile($study_only) ;
 
 	$o->{Java}->{built} = 1 ;
 }
@@ -356,6 +362,7 @@ sub build {
 # Writes the java code.
 sub write_java {
 	my $o = shift ;
+	my $study_only = shift ;
 
 	my $build_dir = $o->{build_dir} ;
 	my $modfname = $o->{modfname} ;
@@ -363,10 +370,12 @@ sub write_java {
 
 	$o->mkpath($o->{build_dir}) ;
 
-	open(JAVA, ">$build_dir/$modfname.java") or
-		croak "Can't open $build_dir/$modfname.java: $!" ;
-	Inline::Java::Init::DumpUserJavaCode(\*JAVA, $modfname, $code) ;
-	close(JAVA) ;
+	if (! $study_only){
+		open(JAVA, ">$build_dir/$modfname.java") or
+			croak "Can't open $build_dir/$modfname.java: $!" ;
+		Inline::Java::Init::DumpUserJavaCode(\*JAVA, $modfname, $code) ;
+		close(JAVA) ;
+	}
 
 	open(JAVA, ">$build_dir/InlineJavaServer.java") or
 		croak "Can't open $build_dir/InlineJavaServer.java: $!" ;
@@ -380,14 +389,17 @@ sub write_java {
 # Run the build process.
 sub compile {
 	my $o = shift ;
+	my $study_only = shift ;
 
 	my $build_dir = $o->{build_dir} ;
 	my $modpname = $o->{modpname} ;
 	my $modfname = $o->{modfname} ;
+	my $suffix = $o->{ILSM_suffix} ;
 	my $install_lib = $o->{install_lib} ;
 
 	my $install = "$install_lib/auto/$modpname" ;
-	$o->mkpath($install) ;
+
+	$o->mkpath("$install") ;
 
 	my $javac = $o->{Java}->{BIN} . "/javac" . portable("EXE_EXTENSION") ;
 
@@ -401,17 +413,21 @@ sub compile {
 
 	my $debug = ($Inline::Java::DEBUG ? "true" : "false") ;
 
+	my $source = ($study_only ? '' : "$modfname.java") ;
+
 	# When we run the commands, we quote them because in WIN32 you need it if
 	# the programs are in directories which contain spaces. Unfortunately, in
 	# WIN9x, when you quote a command, it masks it's exit value, and 0 is always
 	# returned. Therefore a command failure is not detected.
-	# copy_pattern will take care of checking whether there are actually files
+	# copy_classes will take care of checking whether there are actually files
 	# to be copied, and if not will exit the script.
+	# This strategy doesn't work that well if you have many classes in the same 
+	# file, but we can't penalize the other users just to give better support
+	# for Win9x...
 	foreach my $cmd (
-		"\"$pjavac\" InlineJavaServer.java $modfname.java > cmd.out $predir",
-		["copy_pattern", $o, "InlineJavaServer*.class"],
-		["copy_pattern", $o, "*.class"],
-		["touch_file", $o, "$install/$modfname.jdat"],
+		"\"$pjavac\" InlineJavaServer.java $source > cmd.out $predir",
+		["copy_classes", $o, $install],
+		["touch_file", $o, "$install/$modfname.$suffix"],
 		) {
 
 		if ($cmd){
@@ -487,6 +503,60 @@ MSG
 }
 
 
+sub copy_classes {
+	my $o = shift ;
+	my $install = shift ;
+
+	my $build_dir = $o->{build_dir} ;
+	my $modpname = $o->{modpname} ;
+	my $install_lib = $o->{install_lib} ;
+	my $pinstall = portable("RE_FILE", $install) ;
+
+	my $src_dir = $build_dir ;
+	my $dest_dir = $pinstall ;
+
+	my @flist = glob("*.class") ;
+
+	if (portable('COMMAND_COM')){
+		if (! scalar(@flist)){
+			croak "No files to copy. Previous command failed under command.com?" ;
+		}
+		foreach my $file (@flist){
+			if (! (-s $file)){
+				croak "File $file has size zero. Previous command failed under WIN9x?" ;
+			}
+		}
+	}
+
+	foreach my $file (@flist){
+		if ($o->{config}->{UNTAINT}){
+			($file) = $file =~ /(.*)/ ;
+		}
+		Inline::Java::debug("copy_classes: $file, $dest_dir/$file") ;
+		if (! File::Copy::copy($file, "$dest_dir/$file")){
+			return "Can't copy $src_dir/$file to $dest_dir/$file: $!" ;
+		}
+	}
+
+	return '' ;
+}
+
+
+sub touch_file {
+	my $o = shift ;
+	my $file = shift ;
+
+	my $pfile = portable("RE_FILE", $file) ;
+
+	if (! open(TOUCH, ">$pfile")){
+		croak "Can't create file $pfile" ;
+	}
+	close(TOUCH) ;
+
+	return '' ;
+}
+
+
 # Load and Run the Java Code.
 sub load {
 	my $o = shift ;
@@ -495,32 +565,74 @@ sub load {
 		return ;
 	}
 
+	my $install_lib = $o->{install_lib} ;
 	my $modfname = $o->{modfname} ;
+	my $modpname = $o->{modpname} ;
+	my $install = "$install_lib/auto/$modpname" ;
+	my $pinstall = portable("RE_FILE", $install) ;
 
 	# Make sure the default options are set.
 	$o->_validate(1, %{$o->{config}}) ;
 
 	# If the JVM is not running, we need to start it here.
 	if (! $JVM){
+		$o->set_classpath($pinstall) ;
 		$JVM = new Inline::Java::JVM($o) ;
 	}
-	
-	# Now that the JVM is running, we make sure it knows where all 
-	# the classes are.
-	my $pc = new Inline::Java::Protocol(undef, $o) ;
-	$pc->SetClassPath($ENV{CLASSPATH}) ;
+
+	# Add our Inline object to the list.
+	$INLINES->{$modfname} = $o ;
+
+	$o->_study() ;
+	if ((defined($o->{Java}->{STUDY}))&&(scalar($o->{Java}->{STUDY}))){
+		$o->_study($o->{Java}->{STUDY}) ;
+	}
+
+	$o->{Java}->{loaded} = 1 ;
+}
+
+
+# This function builds the CLASSPATH environment variable for the JVM
+sub set_classpath {
+	my $o = shift ;
+	my $path = shift ;
+
+	my @list = () ;
+	if (defined($ENV{CLASSPATH})){
+		push @list, $ENV{CLASSPATH} ;
+	}
+	if (defined($o->{Java}->{CLASSPATH})){
+		push @list, $o->{Java}->{CLASSPATH} ;
+	}
+	if (defined($path)){
+		push @list, $path ;
+	}
+
+	my $sep = portable("ENV_VAR_PATH_SEP") ;
+	my @cp = split(/$sep/, join($sep, @list)) ;
+	my %cp = map { ($_ !~ /^\s*$/ ? ($_, 1) : ()) } @cp ;
+
+	$ENV{CLASSPATH} = join($sep, keys %cp) ;
+
+	Inline::Java::debug("  classpath: " . $ENV{CLASSPATH}) ;
+}
+
+
+
+# This function 'studies' the specified classes and binds them to 
+# Perl
+sub _study {
+	my $o = shift ;
+	my $classes = shift ;
 
 	# Then we ask it to give us the public symbols from the classes
 	# that we got.
-	my @lines = $o->report() ;
+	my @lines = $o->report($classes) ;
 
 	# Now we read up the symbols and bind them to Perl.
-	$o->load_jdat(@lines) ;
-
-	$INLINES->{$modfname} = $o ;
-	$o->bind_jdat() ;
-
-	$o->{Java}->{loaded} = 1 ;
+	$o->bind_jdat(
+		$o->load_jdat(@lines)
+	) ;
 }
 
 
@@ -532,20 +644,74 @@ sub report {
 
 	my $install_lib = $o->{install_lib} ;
 	my $modpname = $o->{modpname} ;
+	my $modfname = $o->{modfname} ;
+	my $suffix = $o->{ILSM_suffix} ;
 	my $install = "$install_lib/auto/$modpname" ;
 	my $pinstall = portable("RE_FILE", $install) ;
 
+	my $use_cache = 0 ;
 	if (! defined($classes)){
+		$classes = [] ;
+
+		$use_cache = 1 ;
+
 		# We need to take the classes that are in the directory...
 		my @cl = glob("$pinstall/*.class") ;
 		foreach my $class (@cl){
 			$class =~ s/^\Q$pinstall\E\/(.*)\.class$/$1/ ;
+			if ($class !~ /^InlineJavaServer/){
+				push @{$classes}, $class ;
+			}
+		}
+	}
+
+	my @new_classes = () ;
+	foreach my $class (@{$classes}){
+		$class = Inline::Java::Class::ValidateClass($class) ;
+
+		if (! Inline::Java::known_to_perl($o->{pkg}, $class)){
+			push @new_classes, $class ;
 		}
-		$classes = \@cl ;
 	}
 
-	my $pc = new Inline::Java::Protocol(undef, $o) ;
-	my $resp = $pc->Report(join(" ", @{$classes})) ;
+	if (! scalar(@new_classes)){
+		return () ;
+	}
+
+	my $resp = undef ;
+	if (($use_cache)&&(! $o->{Java}->{built})){
+		# Since we didn't build the module, this means that 
+		# it was up to date. We can therefore use the data 
+		# from the cache
+		Inline::Java::debug("using jdat cache") ;
+		my $size = (-s "$install/$modfname.$suffix") || 0 ;
+		if ($size > 0){
+			if (open(CACHE, "<$install/$modfname.$suffix")){
+				$resp = join("", <CACHE>) ;
+				close(CACHE) ;
+			}
+			else{
+				croak "Can't open $modfname.$suffix file for reading" ;
+			}
+		}
+	}
+
+	if (! defined($resp)){
+		my $pc = new Inline::Java::Protocol(undef, $o) ;
+		$resp = $pc->Report(join(" ", @new_classes)) ;
+	}
+
+	if (($use_cache)&&($o->{Java}->{built})){
+		# Update the cache.
+		Inline::Java::debug("updating jdat cache") ;
+		if (open(CACHE, ">$install/$modfname.$suffix")){
+			print CACHE $resp ;
+			close(CACHE) ;
+		}
+		else{
+			croak "Can't open $modfname.$suffix file for writing" ;
+		}
+	}
 
 	return split("\n", $resp) ;
 }
@@ -557,10 +723,18 @@ sub load_jdat {
 	my $o = shift ;
 	my @lines = @_ ;
 
-	Inline::Java::debug(join("\n", @lines)) ;
+	if (Inline::Java::debug_all()){
+		Inline::Java::debug(join("\n", @lines)) ;
+	}
 
-	$o->{Java}->{data} = {} ;
-	my $d = $o->{Java}->{data} ;
+	# We need an array here since the same object can have many 
+	# load sessions.
+	if (! defined($o->{Java}->{data})){
+		$o->{Java}->{data} = [] ;
+	}
+	my $d = {} ;
+	my $data_idx = scalar(@{$o->{Java}->{data}}) ;
+	push @{$o->{Java}->{data}}, $d ;
 	
 	my $re = '[\w.\$\[;]+' ;
 
@@ -570,9 +744,10 @@ sub load_jdat {
 		chomp($line) ;
 		if ($line =~ /^class ($re)$/){
 			# We found a class definition
-			$current_class = $1 ;
-			$current_class =~ s/[\$.]/::/g ;
+			my $java_class = $1 ;
+			$current_class = Inline::Java::java2perl($java_class) ;
 			$d->{classes}->{$current_class} = {} ;
+			$d->{classes}->{$current_class}->{java_class} = $java_class ;
 			$d->{classes}->{$current_class}->{constructors} = {} ;
 			$d->{classes}->{$current_class}->{methods} = {} ;
 			$d->{classes}->{$current_class}->{fields} = {} ;
@@ -624,24 +799,33 @@ sub load_jdat {
 		$idx++ ;
 	}
 
-	Inline::Java::debug_obj($d) ;
+	if (Inline::Java::debug_all()){
+		Inline::Java::debug_obj($d) ;
+	}
+
+	return ($d, $data_idx) ;
 }
 
 
 # Binds the classes and the methods to Perl
 sub bind_jdat {
 	my $o = shift ;
+	my $d = shift ;
+	my $idx = shift ;
 
-	my $d = $o->{Java}->{data} ;
 	my $modfname = $o->{modfname} ;
 
+	if (! defined($d->{classes})){
+		return ;
+	}
+
 	my %classes = %{$d->{classes}} ;
 	foreach my $class (sort keys %classes) {
-		my $java_class = $class ;
-		$java_class =~ s/::/\$/g ;
 		my $class_name = $class ;
 		$class_name =~ s/^(.*)::// ;
 
+		my $java_class = $d->{classes}->{$class}->{java_class} ;
+
 		my $colon = ":" ;
 		my $dash = "-" ;
 		
@@ -681,7 +865,7 @@ sub new {
 	my \@args = \@_ ;
 
 	my \$o = Inline::Java::get_INLINE('$modfname') ;
-	my \$d = \$o->{Java}->{data} ;
+	my \$d = \$o->{Java}->{data}->[$idx] ;
 	my \$signatures = \$d->{classes}->{'$class'}->{constructors} ;
 	my (\$proto, \$new_args, \$static) = \$class->__validate_prototype('new', [\@args], \$signatures, \$o) ;
 
@@ -703,10 +887,14 @@ CODE
 		}
 
 		while (my ($method, $sign) = each %{$d->{classes}->{$class}->{methods}}){
-			$code .= $o->bind_method($class, $method) ;
+			$code .= $o->bind_method($idx, $class, $method) ;
+		}
+
+		if (Inline::Java::debug_all()){
+			Inline::Java::debug($code) ;
 		}
 
-		Inline::Java::debug($code) ;
+		# open (CODE, ">>code") and print CODE $code and close(CODE) ;
 
 		eval $code ;
 
@@ -717,6 +905,7 @@ CODE
 
 sub bind_method {
 	my $o = shift ;
+	my $idx = shift ;
 	my $class = shift ;
 	my $method = shift ;
 	my $static = shift ;
@@ -731,7 +920,7 @@ sub $method {
 	my \@args = \@_ ;
 
 	my \$o = Inline::Java::get_INLINE('$modfname') ;
-	my \$d = \$o->{Java}->{data} ;
+	my \$d = \$o->{Java}->{data}->[$idx] ;
 	my \$signatures = \$d->{classes}->{'$class'}->{methods}->{'$method'} ;
 	my (\$proto, \$new_args, \$static) = \$this->__validate_prototype('$method', [\@args], \$signatures, \$o) ;
 
@@ -759,10 +948,14 @@ sub get_fields {
 	my $class = shift ;
 
 	my $fields = {} ;
-	my $d = $o->{Java}->{data} ;
+	my $data_list = $o->{Java}->{data} ;
 
-	while (my ($field, $value) = each %{$d->{classes}->{$class}->{fields}}){
-		$fields->{$field} = $value ;
+	foreach my $d (@{$data_list}){
+		if (exists($d->{classes}->{$class})){
+			while (my ($field, $value) = each %{$d->{classes}->{$class}->{fields}}){
+				$fields->{$field} = $value ;
+			}
+		}
 	}
 
 	return $fields ;
@@ -785,92 +978,44 @@ sub info {
 	}
 
 	my $info = '' ;
-	my $d = $o->{Java}->{data} ;
-
-	my %classes = %{$d->{classes}} ;
-	$info .= "The following Java classes have been bound to Perl:\n" ;
-	foreach my $class (sort keys %classes) {
-		$info .= "\n  class $class:\n" ;
+	my $data_list = $o->{Java}->{data} ;
 
-		$info .= "    public methods:\n" ;
-		while (my ($k, $v) = each %{$d->{classes}->{$class}->{constructors}}){
-			my $name = $class ;
-			$name =~ s/^(.*)::// ;
-			$info .= "      $name($k)\n" ;
+	foreach my $d (@{$data_list}){
+		if (! defined($d->{classes})){
+			next ;
 		}
 
-		while (my ($k, $v) = each %{$d->{classes}->{$class}->{methods}}){
-			while (my ($k2, $v2) = each %{$d->{classes}->{$class}->{methods}->{$k}}){
-				my $static = ($v2->{STATIC} ? "static " : "") ;
-				$info .= "      $static$k($k2)\n" ;
-			}
-		}
+		my %classes = %{$d->{classes}} ;
 
-		$info .= "    public member variables:\n" ;
-		while (my ($k, $v) = each %{$d->{classes}->{$class}->{fields}}){
-			my $static = ($v->{STATIC} ? "static " : "") ;
-			my $type = $v->{TYPE} ;
+		$info .= "The following Java classes have been bound to Perl:\n" ;
+		foreach my $class (sort keys %classes) {
+			$info .= "\n  class $class:\n" ;
 
-			$info .= "      $static$type $k\n" ;
-		}
-	}
-
-    return $info ;
-}
-
-
-sub copy_pattern {
-	my $o = shift ;
-	my $pattern = shift ;
-
-	my $build_dir = $o->{build_dir} ;
-	my $modpname = $o->{modpname} ;
-	my $install_lib = $o->{install_lib} ;
-	my $install = "$install_lib/auto/$modpname" ;
-	my $pinstall = portable("RE_FILE", $install) ;
+			$info .= "    public methods:\n" ;
+			while (my ($k, $v) = each %{$d->{classes}->{$class}->{constructors}}){
+				my $name = $class ;
+				$name =~ s/^(.*)::// ;
+				$info .= "      $name($k)\n" ;
+			}
 
-	my $src_dir = $build_dir ;
-	my $dest_dir = $pinstall ;
+			while (my ($k, $v) = each %{$d->{classes}->{$class}->{methods}}){
+				while (my ($k2, $v2) = each %{$d->{classes}->{$class}->{methods}->{$k}}){
+					my $static = ($v2->{STATIC} ? "static " : "") ;
+					$info .= "      $static$k($k2)\n" ;
+				}
+			}
 
-	my @flist = glob($pattern) ;
+			$info .= "    public member variables:\n" ;
+			while (my ($k, $v) = each %{$d->{classes}->{$class}->{fields}}){
+				my $static = ($v->{STATIC} ? "static " : "") ;
+				my $type = $v->{TYPE} ;
 
-	if (portable('COMMAND_COM')){
-		if (! scalar(@flist)){
-			croak "No files to copy. Previous command failed under command.com?" ;
-		}
-		foreach my $file (@flist){
-			if (! (-s $file)){
-				croak "File $file has size zero. Previous command failed under WIN9x?" ;
+				$info .= "      $static$type $k\n" ;
 			}
 		}
 	}
 
-	foreach my $file (@flist){
-		if ($o->{config}->{UNTAINT}){
-			($file) = $file =~ /(.*)/ ;
-		}
-		Inline::Java::debug("copy_pattern: $file, $dest_dir/$file") ;
-		if (! File::Copy::copy($file, "$dest_dir/$file")){
-			return "Can't copy $src_dir/$file to $dest_dir/$file: $!" ;
-		}
-	}
-
-	return '' ;
-}
-
-
-sub touch_file {
-	my $o = shift ;
-	my $file = shift ;
-
-	my $pfile = portable("RE_FILE", $file) ;
-
-	if (! open(TOUCH, ">$pfile")){
-		croak "Can't create file $pfile for writing" ;
-	}
-	close(TOUCH) ;
-
-	return '' ;
+    return $info ;
 }
 
 
@@ -890,11 +1035,22 @@ sub get_INLINE {
 }
 
 
+sub get_INLINE_nb {
+
+	return scalar(keys %{$INLINES}) ;
+}
+
+
 sub get_DEBUG {
 	return $Inline::Java::DEBUG ;
 }
 
 
+sub debug_all {
+	return (Inline::Java::get_DEBUG() > 1) ;
+}
+
+
 sub get_DONE {
 	return $DONE ;
 }
@@ -1044,6 +1200,26 @@ sub cast {
 }
 
 
+sub study_classes {
+	my $classes = shift ;
+
+	Inline::Java::debug("Selecting random module to house studied classes...") ;
+
+	# Select a random Inline object to be responsible for these
+	# classes
+	my @modules = keys %{$INLINES} ;
+	srand() ;
+	my $idx = int rand @modules ;
+	my $module = $modules[$idx] ;
+
+	Inline::Java::debug("  Selected $module") ;
+
+	my $o = Inline::Java::get_INLINE($module) ;
+
+	return $o->_study($classes) ;
+}
+
+
 
 1 ;
 
diff --git a/Java.pod b/Java.pod
index 5b2c56d..95f3e42 100644
--- a/Java.pod
+++ b/Java.pod
@@ -2,6 +2,7 @@
 
 Inline::Java - Write Perl classes in Java.
 
+
 =head1 SYNOPSIS
 
    my $alu = new alu() ;
@@ -23,12 +24,14 @@ Inline::Java - Write Perl classes in Java.
       }   
    END_OF_JAVA_CODE
 
+
 =head1 WARNING 
 
 THIS IS ALPHA SOFTWARE. It is incomplete and possibly unreliable. 
 It is also possible that some elements of the interface (API) will 
 change in future releases.
 
+
 =head1 DESCRIPTION
 
 The C<Inline::Java> module allows you to put Java source code
@@ -42,6 +45,7 @@ The process of interrogating the Java classes for public methods
 occurs the first time you run your Java code. The namespace is
 cached, and subsequent calls use the cached version.
 
+
 =head1 USING THE Inline::Java MODULE
 
 C<Inline::Java> is driven by fundamentally the same idea as other
@@ -81,6 +85,7 @@ on your machine. This is done using one of the following techniques:
    - set the PERL_INLINE_JAVA_BIN environment variable to the correct directory
    - put the correct directory in your PATH environment variable
 
+
 =head1 CONFIGURATION OPTIONS
 
 There are a number of configuration options that dictate the 
@@ -108,10 +113,6 @@ behavior of C<Inline::Java>:
       Enables debugging info
       Ex: DEBUG => 1
 
-   CLASSPATH:
-      Adds the specified CLASSPATH to the environment CLASSPATH.
-      Ex: CLASSPATH => 'my/other/java/classses'
-
    WARN_METHOD_SELECT:
       Throws a warning when C<Inline::Java> has to 'choose' between 
       different method signatures. The warning states the possible 
@@ -127,6 +128,17 @@ behavior of C<Inline::Java>:
       environment variable to 1.
       Ex: JNI => 1
 
+   STUDY:
+      Takes an array of Java classes that you wish to have C<Inline::Java>
+      learn about so that you can use thme inside Perl.
+      Ex: STUDY => ['java.lang.HashMap', 'my.class'] ;
+
+   AUTOSTUDY:
+      Makes C<Inline::Java> automatically study unknown classes it 
+      encounters.
+      Ex: STUDY => ['java.lang.HashMap', 'my.class'] ;
+
+
 =head1 CLASSES AND OBJECTS
 
 Because Java is object oriented, any interface between Perl and Java
@@ -202,6 +214,7 @@ to an outer class object as the first parameter of the constructor:
    my $obj = new Foo() ;
    my $obj2 = new Bar($obj) ;
 
+
 =head1 METHODS
 
 In the previous example we have seen how to call a method. You can also
@@ -257,6 +270,7 @@ are not known to C<Inline::Java>. This is also true for return types:
 Objects of types unknown to Perl can exist in the Perl space, you just 
 can't call any of their methods.
 
+
 =head1 MEMBER VARIABLES
 
 You can also access all public member variables (static or not) from Perl.
@@ -283,6 +297,7 @@ be known to Perl:
 Note: Watch out for typos when accessing members in the static fashion,
 'use strict' will not catch them since they have a package name...
 
+
 =head1 ARRAYS
 
 You can also send and receive arrays. This is done by using Perl lists:
@@ -316,6 +331,7 @@ You can also send and receive arrays. This is done by using Perl lists:
    ]) ; # String [][]
    print $a2->[1]->[0] ; # "10"
 
+
 =head1 TYPE CASTING
 
 Sometimes when a class as many signatures for the same method, 
@@ -401,6 +417,59 @@ Java array reference obtained from elsewhere, you don't even need to cast:
    $obj->{o} = $obj->{a} ;
 
 
+=head1 STUDYING
+
+As of version 0.21, C<Inline::Java> can learn about other Java classes
+and use them just like the Java code you write inside your Perl script.
+In fact you are not even required to write Java code inside your Perl
+script anymore. Here's how to use the 'studying' function:
+
+   use Inline {
+      Java => 'STUDY',
+      STUDY => ['java.lang.HashMap'],
+   ) ;
+
+   my $hm = new java::lang::HashMap() ;
+   $hm->put("key", "value") ;
+   my $v = $hm->get("key") ;
+
+If you do not wish to put any Java code inside you Perl script, you must
+use the string 'STUDY' as your code. This will skip the build section.
+
+You can also use the AUTOSTUDY option to tell C<Inline::Java> that you wish
+to study all classes that it comes across:
+
+   use Inline {
+      Java => 'DATA',
+      AUTOSTUDY => 1,
+   ) ;
+
+   my $obj = new Foo8() ;
+   my $hm = $obj->get_hm() ;
+   $hm->put("key", "value") ;
+   my $v = $hm->get("key") ;
+
+   __END__
+   __Java__
+  
+   import java.util.* ;
+
+   class Foo8 {
+      public Foo8() {
+      }
+
+      public HashMap get_hm(){
+         HashMap hm = new HashMap() ;
+         return hm ;
+      }
+   }
+
+In this case C<Inline::Java> intercepts the return value of the get_hm()
+method, sees that it's of a type that it doesn't know about (java.lang.HashMap),
+and immediately studies the class. After that call the java::lang::HashMap
+class is available to use through Perl.
+
+
 =head1 JNI vs CLIENT/SERVER MODES
 
 Starting in version 0.20, it is possible to use the JNI (Java Native 
@@ -419,6 +488,7 @@ Note: C<Inline::Java> only creates one virtual machine instance. Therefore
 you can't use JNI for some sections and client/server for others. The first
 section determines the execution mode.
 
+
 =head1 SUPPORTED PLATFORMS
 
 This is an ALPHA release of Inline::Java. Further testing and
@@ -432,6 +502,7 @@ focus for future releases. It has been tested on:
 
 It likely will work with many other configurations.
 
+
 =head1 HOW IT WORKS
 
 This is how C<Inline::Java> works. Once the user's code is compiled by the 
@@ -448,6 +519,7 @@ the JNI mode). Then each object creation or method invocation on "Java
 objects" send requests to the server, which processes them and returns 
 object ids to Perl which keeps them the reference te objects in the future.
 
+
 =head1 SEE ALSO 		   
 
 For information about using C<Inline>, see L<Inline>.
@@ -458,6 +530,7 @@ Inline::Java's mailing list is inline at perl.org
 
 The subscribe, send email to inline-subscribe at perl.org
 
+
 =head1 BUGS AND DEFICIENCIES
 
 When reporting a bug, please do the following:
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 383030c..bdd37a2 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -3,7 +3,7 @@ package Inline::Java::Protocol ;
 
 use strict ;
 
-$Inline::Java::Protocol::VERSION = '0.20' ;
+$Inline::Java::Protocol::VERSION = '0.21' ;
 
 use Inline::Java::Object ;
 use Inline::Java::Array ;
diff --git a/t/08_study.t b/t/08_study.t
index dd70316..fac85bd 100644
--- a/t/08_study.t
+++ b/t/08_study.t
@@ -8,6 +8,7 @@ use Inline(
 	Java => 'STUDY',
 	AUTOSTUDY => 1,
 ) ;
+use Inline::Java qw(study_classes) ;
 
 
 
@@ -16,7 +17,7 @@ BEGIN {
 }
 
 
-Inline::Java::study_it(['t.types']) ;
+study_classes(['t.types']) ;
 
 my $t = new t::types() ;
 ok($t->func(), "study") ;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git



More information about the Pkg-perl-cvs-commits mailing list