NAME
JS::PerlClass - Create native javascript clases in Perl
Constructor
- new ( %args )
-
Create a new native js class.
It expects the following arguments
- name
-
The name of the class in javascript.
name => "MyPackage",
- constructor
-
A reference to a subroutine that returns the Perl object that represents the javascript object. If omitted a default constructor will be supplied that calls the method
new
on the defined package (or name if no package is defined).constructor => sub { MyPackage->new(@_); },
- package
-
The name of the Perl package that represents this class. It will be passed as first argument to any class methods and also used in the default constructor.
package => "My::Package",
- methods (fs)
-
A hash reference of methods that we define for instances of the class. In javascript this would be
o = new MyClass(); o.method()
.The key is used as the name of the function and the value should be either a reference to a subroutine or the name of the Perl subroutine to call.
methods => { to_string => \&My::Package::to_string, random => "randomize" }
- static_methods (static_ps)
-
Like fs but these are called on the class itself. In javascript this would be
MyClass.method()
. - properties (ps)
-
A hash reference of properties that we define for instances of the class. In javascript this would be
o = new MyClass(); f = o.property;
The key is used as the name of the property and the value is used to specify what method to call as a get-operation and as a set-operation. These can either be specified using references to subroutines or name of subroutines. If the getter is undefined the property will be write-only and if the setter is undefined the property will be read-only. You can specify the getter/setter using either an array reference,
[\&MyClass::get_property, \&MyClass::set_property]
, a string,"MyClass::set_property MyClass::get_property"
or a hash reference,{ getter =
"MyClass::get_property", setter => "MyClass::set_property" }>.ps => { length => [qw(get_length)], parent => { getter => \&MyClass::get_parent, setter => \&MyClass::set_parent }, }
- static_properties (static_ps)
-
Like ps but these are defined on the class itself. In javascript this would be
f = MyClass.property
. - flags
-
A bitmask of attributes for the class. Valid attributes are:
- JS_CLASS_NO_INSTANCE
-
Makes the class throw an exception if javascript tries to instantiate the class.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 169:
=over without closing =back