manakai//DOM Perl Binding

manakai//DOM Perl Binding

[1] This is the work-in-progress specification for the manakai's DOM binding for Perl. This specification only scopes manakai's DOM implementation; it does not try to define what any other DOM implementation should do. However, other DOM implementation that exposes interfaces to Perl scripts MAY use this binding.
[2] TODO:

Conformance

[48] Statements about conformance in this specification are only applied to implementations that support related feature. For example, MUST-level requirements for treatement of the EventHandler objects do not apply to implementations that do not support DOM Events module.

Objects and interfaces

[3] A DOM object, i.e. an object implementing one or more DOM interfaces, MUST be represented by a Perl object, i.e. a thingly referenced by some Perl references and blessed in a Perl class, unless otherwise specified. The Perl class MUST implement the DOM interfaces implemented by the DOM object.

better wording, getFeature consideration

Methods and attributes

[5] A DOM method MUST be implemented as a Perl method.

[6] A read-only DOM attribute MUST be implemented as a Perl method that returns the value contained in the DOM attribute. The Perl method MAY throw an implementation dependent exception if any argument is specified for the Perl method.

[7] A read-write DOM attribute MUST be implemented as a Perl method. The Perl method MUST return the value contained in the DOM attribute if no argument is specified for the Perl method (i.e. the only argument to the subroutine implementing the Perl method is the object itself). Otherwise, the Perl method MUST try to set the first argument specified for the method (i.e. the second argument to the subroutine implementing the Perl method) to the DOM attribute.

Note that specifying undef as the argument to the Perl method, which set the null value to the DOM attribute, is different from specifying no argument, which returns the DOM attribute value.

[8] A DOM parameter to a method is optional if either null or boolean false value is allowed to be specified to that parameter and any following DOM parameter is optional.

The Perl method MUST act as if an undef or a Perl false value, depending on the data type of the parameter, is specified to each optional parameter if no argument corresponding to that parameter is specified.

Constants

Exceptions and errors

[9] Throwing an exception MUST be implemented by Perl die function. If the exception is one defined in DOM specification, the argument to the die function MUST be an object implementing the associated exception interface.

Implementations are encouraged to employ the Error module as a basis to construct their own exception mechanism.
Exception classes
DOMErrors

Events

Naming Rule

[15] Names of DOM methods and attributes MUST be mapped to Perl method (subroutine) name by following algorithm:

  1. Let n as the name of a DOM method or attribute.
  2. If the first column of the table >>14 contains n, then return the name contained in the cell in the second column of the same row.
  3. Otherwise, replace a sequence of one or more uppercase letters at the end of n, if any, by the lowercase variant of the sequence.
  4. Replace any sequence of two or more uppercase letters in n by a sequence of a LOW LINE character, the lowercase variant of the sequence except the last letter, a LOW LINE character, and the lowercase variant of the last letter of the sequence.
  5. Replace any uppercase letter by a LOW LINE character followed by the lowercase variant of the letter.
  6. Then, return n.

[14] Exceptions.

DOMDOM Perl BindingNote
accessKeyaccesskeyHTMLInputElement, HTMLTextAreaElement, HTMLButtonElement, HTMLLabelElement, HTMLLegendElement, HTMLAnchorElement, HTMLAreaElement (DOM HTML)
aLinkalinkHTMLBodyElement (DOM HTML)
bgColorbgcolorHTMLDocument, HTMLBodyElement, HTMLTableElement, HTMLTableRowElement, HTMLTableCellElement (DOM HTML)
cellPaddingcellpaddingHTMLTableElement (DOM HTML)
cellSpacingcellspacingHTMLTableElement (DOM HTML)
codeBasecodebaseHTMLObjectElement, HTMLAppletElement (DOM HTML)
codeTypecodetypeHTMLObjectElement (DOM HTML)
colSpancolspanHTMLTableCellElement (DOM HTML)
createTFootcreate_tfootHTMLTableElement (DOM HTML)
createTHeadcreate_theadHTMLTableElement (DOM HTML)
dateTimedatetimeHTMLModElement (DOM HTML)
dateTimedatetimeHTMLTimeElement (DOM HTML)
deleteTFootdelete_tfootHTMLTableElement (DOM HTML)
deleteTHeaddelete_theadHTMLTableElement (DOM HTML)
findOffset16find_offset_16StringExtended (DOM Core informative)
findOffset32find_offset_32StringExtended (DOM Core informative)
frameBorderframeborderHTMLFrameElement, HTMLIFrameElement (DOM HTML)
getAbsoluteReference3986get_absolute_reference_3986URIReference (manakai's extension)
getAbsoluteReference3987get_absolute_reference_3987URIReference (manakai's extension)
getIRIReference3987get_iri_reference_3987URIReference (manakai's extension)
getURIReference3986get_uri_reference_3986URIReference (manakai's extension)
isAbsoluteIRI3987is_absolute_iri_3987URIReference (manakai's extension)
isAbsoluteURI3986is_absolute_uri_3986URIReference (manakai's extension)
isIRI3987is_iri_3987URIReference (manakai's extension)
isIRIReference3987is_iri_reference_3987URIReference (manakai's extension)
isMapismapHTMLImageElement (DOM HTML)
isRelativeIRIReference3987is_iri_reference_3987URIReference (manakai's extension)
isRelativeReference3986is_relative_reference_3986URIReference (manakai's extension)
isSameDocumentReference3986is_same_document_reference_3986URIReference (manakai's extension)
isURI3986is_uri_3986URIReference (manakai's extension)
isURIReference3986is_uri_reference_3986URIReference (manakai's extension)
longDesclongdescHTMLImageElement, HTMLFrameElement, HTMLIFrameElement (DOM HTML)
marginHeightmarginheightHTMLFrameElement, HTMLIFrameElement (DOM HTML)
marginWidthmarginwidthHTMLFrameElement, HTMLIFrameElement (DOM HTML)
maxLengthmaxlengthHTMLInputElement (DOM HTML)
noHrefnohrefHTMLAreaElement (DOM HTML)
noResizenoresizeHTMLFrameElement (DOM HTML)
noShadenoshadeHTMLHRElement (DOM HTML)
noWrapnowrapHTMLTableCellElement (DOM HTML)
readOnlyreadonlyHTMLInputElement, HTMLTextAreaElement(DOM HTML)
rowSpanrowspanHTMLTableCellElement (DOM HTML)
scrollbar3dLightShadowColorscrollbar_3dlight_colorCSSStyleDeclarationProperties (CSSOM)
scrollbarDarkShadowColorscrollbar_darkshadow_colorCSSStyleDeclarationProperties (CSSOM)
tabIndextabindexHTMLSelectElement, HTMLInputElement, HTMLTextAreaElement, HTMLButtonElement, HTMLAnchorElement, HTMLObjectElement, HTMLAreaElement (DOM HTML)
tBodiestbodiesHTMLTableElement (DOM HTML)
tFoottfootHTMLTableElement (DOM HTML)
tHeadtheadHTMLTableElement (DOM HTML)
URLurlHTMLDocument (DOM HTML)
useMapusemapHTMLInputElement , HTMLImageElement, HTMLObjectElement (DOM HTML)
utf16Offsetutf16_offsetDOMLocator (DOM Core)
utf32Offsetutf32_offsetDOMLocator (DOM Core)
vAlignvalignHTMLTableColElement , HTMLTableSectionElement, HTMLTableRowElement, HTMLTableCellElement (DOM HTML)
valueTypevaluetypeHTMLParamElement (DOM HTML)
vLinkvlinkHTMLBodyElement (DOM HTML)

Editor's note (informative): manakai//Issue//1//9

Data types

[10] In this section, number types includes: long, unsigned long, unsigned long long, short, and unsigned short.

[11] If the return value of the DOM method or the DOM attribute is of number type and a Perl method return a value in that type, jt MUST return a value that can be evaluated as a number (by, e.g., 0+ operation).

[12] If a DOM method parameter or the DOM attribute is of number type and it is necessary for a Perl method to get the specified value, it MAY evaluate the specified value as a value (by, e.g., 0+ operation).

Similary, IDL type <TYPE^^DISCore|QName::idl|boolean>
    is expected to be evaluated in the Boolean context.
    IDL type <TYPE^^DISCore|QName::idl|any> is corresponding to any scalar valu\
e
    in Perl.  IDL type <TYPE^^DISCore|QName::idl|Object> is bound to object.

null

[23] The null value in DOM is bound to undef in Perl.

[24] If something is defined to return or set null, it MUST return or set undef unless otherwise specified.

[25] Where null is allowed to be specified, an implementation MUST behave as if a null is specified when a undef is specified.

[26] Where null is not allowed to be specified, how an implementation behaves when a undef depends on the expected data type. An implementation MAY cause zero or more uninitialized warnings reported by Perl or MAY report its own uninitialized warnings, when warnings are enabled by e.g. use warnings pragma.

TODO: Make relationship to JavaScript undefined and null clearer.

DOMString

  The <TYPE::MIString> type is bound to Perl string value and
    expected to be evaluated in the string context.  A <TYPE::MIString>
    value <kwd:MUST> be interpreted as a sequence of characters rather than
    a sequence of bytes or octets.  If it is represented
    internally as a byte string, i.e. the utf8 flag turned off,
    it <kwd:MUST> be interpreted as a ISO/IEC 8859-1 <bibref::ISO8859-1> string\
.

[33] Some methods are defined to accept a scalar reference specified as a value of a parameter. Such a method, when a scalar reference is specified as a parameter value, MUST dereference the parameter value as a scalar reference (i.e. by operator ${}) before it is in use, if the ref of the parameter value is SCALAR.

DOMTimeStamp

[4] DOMTimeStamp for a Calendar Date-Time

A DOMTimeStamp value that is an absolute date-time MUST be represented by a scalar value of the number of the seconds from 1970-01-01T00:00:00Z. The scalar value MAY contain fraction part, which represents a fraction of a second.

For example, 1970-01-01T00:00:00Z is mapped to a numeric value of 0.
Leap seconds, days before 1970-01-01T00:00:00Z

Security

Features

DOMImplementationRegistry

[16] The variable $Message::DOM::DOMImplementationRegistry MUST contain a value via which methods provided by DOMImplementationRegistry object can be invoked.

For example,
$Message::DOM::DOMImplementationRegistry->get_dom_implementation

returns a DOM implementation.

The DOMImplementationRegistry object don't have to be an object in the Perl context; it might be a string representing the package name of the class implementing the DOMImplementationRegistry interface.

Operator overloading

[18] Unless otherwise specified, an object implementing DOM interface MUST NOT overload an operator by use overload in a way that breaks how that operator works for normal objects.

For example, unless otherwise specified, the "" operator of a class implementing the Element interface must not be overloaded so that an object of that class returns the XML representation of that element.

[28] In any way, when an operator is overloaded, it MUST be consistent with other operators.

For example, if the eq operator is overloaded,
my $eq = $a eq $b;
my $ne = $a ne $b;
die unless ($eq and not $ne) or (not $eq and $ne);

... must not die.

Array-like and / or hash-like objects

better wording

[17] For following interfaces, dereferencing an object as array acts as if it is an array:

That is, $obj->[$n] MUST return the same value as $obj->item ($n) if $obj is an object implementing any of interfaces listed above and $n is a non-negative integer less than $obj->length.

If $n is negative, then length - $n. If length is zero, greater than $n, smaller than -length, non-number, then?
Hash-like
Read-only array-like or hash-like objects

[29] If an array-like or hash-like object is read-only, STORE, STORESIZE, DELETE, and any other operations that implies these operations MUST throw an NO_MODIFICATION_ALLOWED_ERR DOMException.

Constructor

[19] The new method is reserved.

Cloning method

[20] The clone method is reserved.

It is planned to make Node's clone method an alias of cloneNode method.

Stringify method

[21] The stringify and as_string methods are reserved.

""
DOMError stringify may return an implementation dependent string that describes the problem.

Function-like interfaces

[22] Several interfaces are defined as function-like. Only Perl native CODE references, i.e. values whose ref is CODE, and objects for which the &{} operation is defined MUST be treated as if they implement the function-like interfaces and are referred to as objects implementing the function-like interfaces. Each function-like interface has a method, typically named as handleEvent. Invoking that method on the object implementing a function-like interface from another language binding invokes the object itself, by &{} operation. In the Perl binding itself, however, the method of the interface is not directly accessible on the object implementing the interface.

Unlike in ECMAScript language binding, arbitrary object with handle_event method (and no &{} operation defined) does not implement the function-like interfaces.

[43] Function-like interfaces are:

[44] When the method would be invoked, the &{} operation MUST be performed over the object with appropriate arguments. The return value of the &{} operation MUST be treated as if the return value of the method. If the &{} operation results in an exception is raised, it MUST be treated as if it is an exception raised by the method.

For example,
$node->add_event_listener ('click', sub {
  my $ev = shift;
  print $ev->details, "\n";
  return 0;
});

would make the subroutine invoked when the node is clicked. The subroutine, implementing the EventHandler interface and treated as if it is the handleEvent method, would prints the number of clicks and then cancel the default action for the event.

[45] Though in some of function-like interfaces constants are defined, they are not accessible via the object implemeting that interface in the Perl binding. Other interface might provide such constants alternatively. For example, objects implementing the Node interface provides contants in UserDataHandler interface (see >>42).

Specifics

The Node interface

[27] Multiple calles of the getter of attributes or childNodes on a Node MUST return the same object respectively in terms of Perl eq operator.

For example,
my $c1 = $node->child_nodes;
my $c2 = $node->child_nodes;
die unless $c1 eq $c2;

... must not die.

[34] The manakaiAppendText method of the Node interface accepts a scalar reference (>>33) as the first parameter.

[42] A package that implements the Node interface MUST implement the OperationType constant group of the UserDataHandler interface.

For example, $node->NODE_CLONED where $node is a Node object must return the value of 1.

The Document interface

The createElementNS method and the createAttributeNS method

[13] If the second parameter, qualifiedName, is an array reference, i.e. the ref operator with that parameter returns a string of ARRAY, then the parameter MUST be interpreted as following:

  • The namespace prefix part of the qualified name is the zeroth item in the array. If it is undef, then there is no namespace prefix (i.e. the qualified name has no COLON character).
  • The local name part of the qualified name is the first item in the array. It MUST NOT be undef; if it is, then it MUST be treated as if an empty string is specified.

Using an array reference, an illegal qualified name can be specified. If the qualified name is illegal, then an appropriate exception might be thrown as defined by DOM specifications.

Unlike these methods, the qualifiedName parameter of the createDocumentType method of the DOMImplementation interface has no special interpretation for an array reference, since the method does not parse the parameter as a pair of namespace prefix and local name.
Methods createTextNode, createComment, createCDATASection

[32] Methods createTextNode, createComment, and createCDATASection of the Document interface accept a scalar reference (>>33) as the first parameter.

The DOMStringList interface

==
Should we allow any Perl array reference as arg?

The NodeList interface

[30] For any NodeList object, the == operator MUST be so overloaded that it returns whether two arguments are equal in the equality defined for the isEqualNode method of the Node interface.

However, if the other operand is not a NodeList object, then it MUST return a false value.

The NamedNodeMap interface

[31] For any NamedNodeMap object, the == operator MUST be so overloaded that it returns whether two arguments are equal in the equality defined for the isEqualNode method of the Node interface.

The NSResolver Interface

[46] A Perl CODE reference (or any object that can be dereferenced as if it were a CODE reference) can be specified as if it were an NSResolver interface.

When the lookupNamespaceURI method of an NSResolver object $obj is invoked, it MUST be done by the algorithm (or its equivalents) represented by the following subroutine where $_[0] is the parameter to the method:

sub {
  my $prefix = $_[0];
  if (UNIVERSAL::can ($obj, 'lookup_namespace_uri')) {
    return $obj->lookup_namespace_uri ($prefix);
  } else {
    return $obj->($prefix);
  }
}

Since the statement above assumes that $obj is invoked, $obj is not undef.

[47] Invoking the lookupNamespaceURI method on the object implementing the NSResolver interface from another language binding MUST behave as if the algorithm above is executed. Note that in the Perl binding itself, however, the method of the interface is not directly accessible on the object implementing the interface when the object is a CODE reference in fact.

References

Normative References

[DOMBinding]
DOM Bindings

Specifications listed below are only normative for implementations that support features defined by those specification.

[DOMCore]
[DOMEvents]
[DOMLS]
[DOMTraversal]
[HTML5]
[SelectorsAPI]
Selectors API, W3C Editor's Draft, 29 August 2007, <http://dev.w3.org/cvsweb/~checkout~/2006/webapi/selectors-api/Overview.html?rev=1.28&content-type=text/html;%20charset=utf-8>. The latest published version of Selectors API is available at <http://www.w3.org/TR/selectors-api/>. (Latest version of the specifcation whose maturity level is higher than Candidate Recommendation, if any, or latest Editor's Draft is referenced.)

Informative References

[SVGPB]
SVG's Perl binding

memo

[35]

Maybe we should define "==" for DOMImplementationList (and any other array like objects) (名無しさん)

[36]

DOMImplementationList.push (non-dom-impl) (名無しさん)

[37]

DOMImplementation->new (名無しさん)

[38]

%Message::DOM::DOMImplementationRegistry::SourceClass (名無しさん)

[39] >>38 $SourceClass (名無しさん)

[40]

No INVALID_CHARACTER_ERR for create_attribute/element_ns (nsuri, ARRAYREF)

(名無しさん)

[41]

Node.isEqualNode == Node.== (名無しさん)

[49]

In binding languages that support setting to a readonly attribute setting media to a string must set the value of mediaText on the MediaList object.

[CSSOM]

(名無しさん)