The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

JSP::PerlObject - Encapsulates generic perl objects in javascript

DESCRIPTION

When a perl object enters javascript land JSP's engine will select the kind of wrapper needed for it. If the object belongs to a javascript class created by "bind_class" in JSP::Context it becomes an instance of that class. Otherwise it becomes an instance of the generic wrapper class PerlObject.

Wrapper classes, installed with bind_class, define all the semantic for objects wrapped in them. So, you should check their documentation on how to use them. This page describes the semantics of the generic wrapper.

JAVASCRIPT INTERFACE

Instances of PerlObject behave much like any other javascript object. You can get and set its properties and you can call its methods.

You can even extend them adding new properties and methods. You can override its methods with new ones writen as javascript functions.

They inherit from Object (via its prototype chain). You can use any of the functions from Object.prototype.

In fact, the PerlObject wrapper is writen as transparent as posible to avoid name clashes with the methods and properties of the associated perl object nor affect the expected javascript semantics.

Be aware that any changes you made to the instance will not normally be visible in perl land. And that's a good thing and expected behavior: If you override some method to implement an especific workarraund for something too 'perlish', you are changing your instance for javascript only, perl land will continue using the 'perlish' original method.

Instance properties

All properties defined in the associated perl object are available as properties in javascript.

When you reference a property of a PerlObject instance it will be obtain from the perl side, wrapped or converted acording to is type, see "From perl to javascript" in JSP. Unless you have override on javascript that property, of course.

The only instance property of especial interest is:

__proto__

Every object in SpiderMonkey's javascript has a readonly property named __proto__. The head of the prototype chain of the object. In it the JSP module implements PerlObject's magic. Here you will see an instance of Stash proxy, that associates the PerlObject with the original perl package (a "stash" in perl parlance) in which the object was blessed. See JSP::Stash for the details.

Instance methods

Any instance methods defined in the associated perl object and its inheritance @ISA tree.

When you call a method of a PerlObject instance you are referencing a property in it, so acordly to the previous section you will obtain a PerlSub instance. So that PerlSub instance will be called. See JSP::PerlSub for the details.