A bit of clarification on the Perl->JS mappings

gh-pages
Hauke D 7 years ago
parent d00888fdc0
commit 9f5835b449

@ -500,19 +500,20 @@ Unlike the JavaScript to Perl mappings, values are (currently¹) generally *copi
Perl to JavaScript, instead of being *referenced*. Perl to JavaScript, instead of being *referenced*.
The exceptions are Perl `sub`s and `WebPerl::JSObject`s. The exceptions are Perl `sub`s and `WebPerl::JSObject`s.
- Perl arrayrefs become JavaScript arrays - Perl arrayrefs become JavaScript arrays (deep copy)
- Perl hashrefs become JavaScript objects - Perl hashrefs become JavaScript objects (deep copy)
- Perl coderefs become JavaScript functions - - Perl coderefs become JavaScript functions -
**Warning:** please see the discussion in **Warning:** please see the discussion in
["Memory Management and Anonymous `sub`s"](#memory-management-and-anonymous-subs)! ["Memory Management and Anonymous `sub`s"](#memory-management-and-anonymous-subs)!
- Perl `WebPerl::JSObject`s become references to the wrapped JavaScript objects - Perl `WebPerl::JSObject`s become references to the wrapped JavaScript objects
(i.e. the underlying JS object is passed back to JS transparently)
- Perl numbers/strings are copied to JavaScript via `Cpanel::JSON::XS::encode_json` - Perl numbers/strings are copied to JavaScript via `Cpanel::JSON::XS::encode_json`
(with its `allow_nonref` option enabled). This means that the choice (with its `allow_nonref` option enabled). This means that the choice
for whether to encode a Perl scalar as a JavaScript number or string is for whether to encode a Perl scalar as a JavaScript number or string is
left up to the module, and is subject to the usual ambiguities when left up to the module, and is subject to the usual ambiguities when
serializing Perl scalars. See serializing Perl scalars. See
[the `Cpanel::JSON::XS` documentation](https://metacpan.org/pod/Cpanel::JSON::XS). [the `Cpanel::JSON::XS` documentation](https://metacpan.org/pod/Cpanel::JSON::XS).
- Other references, including objects, are currently not supported. - Other references, including Perl objects, are currently not supported.
¹ So far, the focus of WebPerl has been to replace JavaScript with Perl, and ¹ So far, the focus of WebPerl has been to replace JavaScript with Perl, and
therefore on accessing JavaScript from Perl, and not as much the other therefore on accessing JavaScript from Perl, and not as much the other

Loading…
Cancel
Save