One advantage of doing it in this method is that you do not have to co-ordinate variable names between your HTML templates and Perl. You could use a simple Template Toolkit phrase like the following to get data into your HTML templates.

var javascript_data = [% data %];

In this way, it doesn't matter WHAT the HTML template calls a particular variables, the data dumps just the same. This could help you keep the work of JavaScript and Perl programmers ( assuming you were using different people ) seperate, without creating cross-dependencies between their code, such as variable names.

The variables you dump can also be of arbitrary depth and complexity, with a few limitations.

Since arrays and hashs are all that is supported by JavaScript, they are the only things you can use in your structs. Any references or a different underlying type will be detected and an error returned.

Note that Data::JavaScript::Anon will use the UNDERLYING type of the data. This means that the blessed classes or objects will be ignored and their data based on the object's underlying implementation type.

This can be a positive thing, as you can put objects for which you expect a certain dump structure into the data to dump, and it will convert to unblessed, more stupid, JavaScript objects cleanly.

Since circular references can't be defined in a single anonymous struct, they are not allowed. Try something like Data::JavaScript instead. Although not supported, they will be detected, and an error returned.

When generating the javascript, numbers will be printed directly and not quoted. The is_a_number method provides convenient access to the test that is used to see if something is a number. The test handles just about everything legal in JavaScript, with the one exception of the exotics, such as Infinite, -Infinit and NaN.