Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
The JavaScript module for Perl
Perl C Other
branch: master

This branch is 5 commits ahead, 30 commits behind claesjac:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
dev_tests
lib
t
.gitignore
CREDITS
Changes
JavaScript.h
JavaScript.xs
MANIFEST
META.yml
Makefile.PL
PJS_Call.c
PJS_Call.h
PJS_Class.c
PJS_Class.h
PJS_Common.h
PJS_Context.c
PJS_Context.h
PJS_Exceptions.c
PJS_Exceptions.h
PJS_Function.c
PJS_Function.h
PJS_PerlArray.c
PJS_PerlArray.h
PJS_PerlHash.c
PJS_PerlHash.h
PJS_PerlSub.c
PJS_PerlSub.h
PJS_Property.c
PJS_Property.h
PJS_Runtime.c
PJS_Runtime.h
PJS_Script.h
PJS_TypeConversion.c
PJS_TypeConversion.h
PJS_Types.h
README
TODO
typemap

README

------------
INTRODUCTION
------------

JavaScript.pm - Execute JavaScript from within Perl

JavaScript.pm is an interface to the SpiderMonkey JS engine. It lets you execute JS code, 
call JS functions, bind Perl classes to JS, import Perl functions to JS, precompile and exeute 
scripts among many other things. It does conversion between Perl and JS datatypes.

  use JavaScript;

  my $rt = JavaScript::Runtime->new();
  my $cx = $rt->create_context();

  $cx->bind_function(write => sub { print @_; });

  $cx->eval(q/
    for (i = 99; i > 0; i--) {
        write(i + " bottle(s) of beer on the wall, " + i + " bottle(s) of beer\n");
        write("Take 1 down, pass it around, ");
        if (i > 1) {
            write((i - 1) + " bottle(s) of beer on the wall.");
        }
        else {
            write("No more bottles of beer on the wall!");
        }
    }
  /);

------------
INSTALLATION
------------

To install JavaScript.pm, make sure you have libjs installed. Otherwize, grab a recent one from ftp://ftp.mozilla.org/pub/js. The module requires 1.7 or later.

Debian users can alternatively install the libmozjs-dev package by doing
> apt-get install libmozjs0g-dev

Makefile.PL will ask a number of questions regarding threading, utf8 and e4x support. Prompting for this can be disabled by 
setting their respective environment variable to a true (1) or false value (2)

    JS_THREADSAFE
    Enables or disables threadsafe. If you're getting errors in make test later that looks something like "Assertion failure: (uint32)2 < JS_MIN(((obj)->map)->freeslot, ((obj)->map)->nslots), at jsapi.c:1969" you probablly have a libjs that's threadsafe.

    JS_UTF8
    Enable utf-8 support for strings. This requires a modern spidermonkey (1.7 or later).

    JS_ENABLE_E4X
    SpiderMonkey 1.6 and later has something called E4X which is XML for JavaScript. In JavaScript these are objects (very very cool) and by enabling this we'll be able to flatten them to strings for now.

Where do look for headers and libraries can be specified using JS_LIB and JS_INC environment variables. They accept a colon (:) separated list.

The Makefile.PL will try to build a small test to determine if the libraries and headers can be used as well as checking what 
spidermonkey library is used. We require at least 1.7 but it *might* work on 1.6. If you don't want these test to be performed 
set the environment variable JS_FORCE to a true value before running Makefile.PL.

When ready invoke the following to build and install this module:

> perl Makefile.PL
> make
> make test
> make install

-------
SUPPORT
-------

= Mailing list at perl-javascript@perl.org, send an empty email to perl-javascript-subscribe@perl.org to subscribe.

Please send questions/patches/docs/comments to "Claes Jakobsson", claesjac@cpan.org

---------
COPYRIGHT
---------

Copyright (c) 2001 - 2008, Claes Jakobsson C<< <claesjac@cpan.org> >>. All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/artistic.html


Something went wrong with that request. Please try again.