Jerrad Pierce > Data-JavaScript-1.08 > Data::JavaScript

Download:
Data-JavaScript-1.08.tgz

Dependencies

Annotate this POD

Related Modules

Data::Dumper
IO::Socket
IO::Select
Sys::Hostname
XML::LibXML
XML::Simple
XML::Writer
Getopt::Long
File::Basename
more...
By perlmonks.org

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.08   Source   Latest Release: Data-JavaScript-1.13

NAME ^

Data::JavaScript - Perl extension for dumping structures into JavaScript code

SYNOPSIS ^

  use Data::JavaScript;
  B<or>
  use Data::JavaScript {UNDEF=>0};
  
  @code = jsdump('my_array', $array_ref, 0);
  $code = jsdump('my_object', $hash_ref);
  $code = hjsdump('my_stuff', $array_ref B<or> $hash_ref);

DESCRIPTION ^

This module is aimed mainly for CGI programming, when a perl script generates a page with client side JavaScript code that needs access to structures created on the server.

It works by creating one line of JavaScript code per datum. Therefore, structures cannot be created anonymously and needed to be assigned to variables. This enables dumping big structures.

You may define a default to be substitued in dumping of undef values at compile time by supplying the default value in anonymous hash like so

  use Data::JavaScript {UNDEF=>'null'};
jsdump('name', \$reference, [$undef]);

The first argument is required, the name of JavaScript object to create.

The second argument is required, a hashref or arrayref. Structures can be nested, circular referrencing is supported EXPERIMENTALLY.

The third argument is optional, a scalar whose value is to be used en lieu of undefenied values when dumping a structure. If unspecified undef is output as ''. Other useful values might be 0, null and NaN

When called in list context, the functions return a list of lines. In scalar context, it returns a string.

hjsdump('name', \$reference, [$undef]);

hjsdump is identical to jsdump except that it adds HTML tags to embed the script inside an HTML page.

AUTHOR ^

Maintained by Jerrad Pierce<[email protected]>

Ariel Brosh, [email protected]. Inspired by WDDX.pm JavaScript support.

CREDITS ^

Garick Hamlin [email protected], fixing of quoting bug.

SEE ALSO ^

perl(1), WDDX.

syntax highlighting: