The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl -w
use strict;
use warnings;

use JavaScript;
use PIL2JS::JSPM;
use UNIVERSAL::require;

my $rt = JavaScript::Runtime->new;
my $ct = $rt->create_context;

=head1 NAME

jsperl - a wrapped javascript interpreter that supports Perl5

=head1 SYNOPSIS

 $ jsperl

 Perl5.perl_use("IO::File");
 f = Perl5.perl_eval("IO::File->new('>file.txt')");
 perl_call_method(f, "print", "fnord\\n")

=head1 DESCRIPTION

This is a wrapper around JavaScript.pm, which exports a Perl5 class
that has three methods: C<perl_eval>, C<perl_use>, C<perl_can>.

The embeded JavaScript engine is capable for round-tripping perl5
closures, and exports three functions: C<perl_apply>,
C<perl_get_method>, C<perl_call_method>

You need a modified version of L<JavaScript> perl module,
L<http://home.clkao.org/~clkao/jspm>.

=cut

PIL2JS::JSPM::init_js_for_perl5($ct);

our $MAGIC_NOLF = "#PIL2JS // IGNORE NEXT LINEFEED#";

$ct->bind_function(
		   name => 'print',
		   func => sub { my $line = shift;
				 $line =~ s/$MAGIC_NOLF//;
				 print $line;
			     });

local $/;
my $foo = <>;

$ct->eval($foo);


END {
    $ct->destroy;
}

=head1 AUTHORS

Chia-liang Kao E<lt>clkao@clkao.orgE<gt>

=head1 COPYRIGHT

Copyright 2005 by Chia-liang Kao E<lt>clkao@clkao.orgE<gt>.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut