JavaScript::Any::Context - an environment where custom functions can be defined and Javascript evaluated
use JavaScript::Any; my $context = JavaScript::Any->new_context; $context->define( say => sub { print @_, "\n" } ); $context->eval('say(1 + 2)');
This is a Role::Tiny role defining the API for objects returned by JavaScript::Any->new_context.
JavaScript::Any->new_context
$object->implementation
Returns the implementation class name as a string.
$object->define($str, $coderef)
Defines a custom Perl function which can be called by Javascript code.
The current implementation only allows the name of the function to consist of word characters. Defining a function called, for example, window.alert, would not be allowed because of the dot.
window.alert
Roughly speaking, when the function is called by Javascript, whatever arguments are passed to it are available in @_ to your Perl code, and whatever value your coderef returns is returned as the Javascript function's return value. The exact details are currently specific to the backend implementation.
@_
$object->define($str, $value)
Where $value is a non-reference value, defines a simple string or numeric variable. JavaScript is somewhat more typed than Perl, so be aware that currently whether $value is considered to be a string or a number by Javascript is currently undetermined behaviour.
$value
$object->eval($str)
Evaluates a string of Javascript code and returns the result.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=JavaScript-Any.
JavaScript::Any, Role::Tiny.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2017 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install JavaScript::Any, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JavaScript::Any
CPAN shell
perl -MCPAN -e shell install JavaScript::Any
For more information on module installation, please visit the detailed CPAN module installation guide.