The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IWL::Object - Base object module for IWL

INHERITANCE

IWL::Error -> IWL::Object

DESCRIPTION

This is the base object module for IWL. Every other module will inherit from it.

CONSTRUCTOR

IWL::Object->new (environment => IWL::Environment)

environment

If an IWL::Environment object is given as the value of the environment argument, and the object is a root object, that environment will be used to manage the shared resources of the object and its children.

IWL::Object->newMultiple (ARGS, ARGS, ...)

Returns an array of multiple objects.

Parameters: ARGS - if only one argument is passed, and it is a number, it is used to create that many number of objects. If the first argument is a number, and is followed by other arguments, the first argument will create the number of objects, with the rest of the arguments passed to the constructor. Otherwise, if the arguments are a list of hash references, they will be used to create the objects.

PROPERTIES

childNodes

An array of child objects for the current object. Null if there are no children.

parentNode

The parent for the current object. Null if it has no parent.

METHODS

firstChild

Returns the first child of the object

lastChild

Returns the last child of the object

nextChild (CURRENT_CHILD)

Obtains the next child of the object. Parameter: CURRENT_CHILD - its sibling Returns the child object, or null if there is no next child.

prevChild (CURRENT_CHILD)

Obtains the previous child of the object. Parameter: CURRENT_CHILD - its sibling Returns the child object, or null if there is no previous child.

getChildren

Returns a reference to the array of child objects

nextSibling

Returns the next sibling of the current object.

prevSibling

Returns the previous sibling of the current object.

getNextSiblings

Returns all siblings, which are after the current object.

getPreviousSiblings

Returns all siblings, which are before the current object.

getParent

Returns the parent object of the current object

getAncestors

Returns all ancestors of the current object

getDescendants

Returns all the descendants of the current object

appendChild (OBJECT)

Appends OBJECT as a child to the current object.

Parameter: OBJECT - the object to be appended (can be an array of objects)

prependChild (OBJECT)

Appends OBJECT as the first child to the current object, and moves the rest afterward.

Parameter: OBJECT - the object to be prepended (can be an array of objects)

setChild (OBJECT)

Sets OBJECT as the only child to the current object, replacing any existing children.

Parameter: OBJECT - the object to be set (can be an array of objects)

insertBefore (REFERENCE, OBJECT)

Inserts OBJECT before REFERENCE.

Parameter: OBJECT - the object to be inserted (can be an array of objects)

insertAfter (REFERENCE, OBJECT)

Inserts OBJECT after REFERENCE.

Parameter: OBJECT - the object to be inserted (can be an array of objects)

removeChild (OBJECT)

Removes OBJECT from the list of children

Parameters: OBJECT - the object to be removed (can be an array of objects)

remove

Removes itself from the child list of its parent

clone (DEPTH)

Clones itself and optionally, its children

Parameters: DEPTH - The optional depth limit of the cloning

Note: Copied the implementation from Clone::PP(3pm). Weak pointers are discarded, and not cloned. This is done to ensure that objects, such as the parent node of an object, are not cloned.

getContent

Returns the markup for the current object and its children.

print

Prints the current object and all of its children.

Warning: Deprecated. Please see IWL::Object::send(3pm)

printHTML

Prints the HTML content of current object and all of its children, along with an HTML header.

Warning: Deprecated. Please see IWL::Object::send(3pm)

getObject

Returns the object and its children as a new object, with a structure needed for JSON

getJSON

Returns a JSON object for the current object and its children.

If the html looks like this: <div attr1="1" attr2="2" style="display: none;"> <child1 /> <child2 attr3="3" /> </div>

The corresponding JSON object will look like this:

{"div": {"attributes": {"attr1": 1, "attr2": 2, "style": {"display": "none"}}, "children": ["child1", "child2": {"attributes": {"attr3": 3}}]}}

printJSON

Prints the JSON of current object and all of its children, along with a javascript header.

Warning: Deprecated. Please see IWL::Object::send(3pm)

printJSONHeader

Prints the JSON Header which is used by IWL

Warning: Deprecated. Please see IWL::Object::send(3pm)

printHTMLHeader

Prints the HTML Header which is used by IWL

Warning: Deprecated. Please see IWL::Object::send(3pm)

printTextHeader

Prints the Text Header which is used by IWL

Warning: Deprecated. Please see IWL::Object::send(3pm)

getJSONHeader

Returns the JSON Header which is used by IWL

getHTMLHeader

Returns the HTML Header which is used by IWL

getTextHeader

Returns the Text Header which is used by IWL

setAttribute (ATTR, VALUE, ESCAPING)

Appends an attribute to the opening tag. The value gets automatically URI escaped. The function fails and returns false on an attempt to set an illegal attribute. Illegal attributes are attributes that contain non US-ASCII characters or violate the XML specification.

If STRICT_LEVEL in iwl.conf is set to a value greater than 1, an exception is thrown in case of illlegal attributes.

Use setStyle for setting the style attribute

Parameter: ATTR - the attribute name to be appended VALUE - the value of the attribute ESCAPING - optional, sets the method of escaping the value - html - html entity escaping [default] - uri - uri escaping - escape - the string is escaped using IWL::String::escape(3pm) - none

setAttributes (%ATTRS, ESCAPING)

setAttributes is a wrapper to setAttribute. It sets all the attributes in the provided hash

Parameters: %ATTRS - a hash of attributes, ESCAPING - optionally provide a method of escaping (see setAttribute)

getAttribute (ATTR, UNESCAPED)

Returns the value of the given attribute. Use getStyle for getting the style attribute

Parameters: ATTR - the attribute name to be returned, UNESCAPED - optional, true if the value should be returned unescaped

hasAttribute (ATTR)

Returns true if attribute ATTR exists, false otherwise.

deleteAttribute (ATTR)

Deletes the given attribute

Parameters: ATTR - the attribute name to be deleted

appendAfter (OBJECT)

Appends an object after the current object

Parameters: OBJECT - the object to be appended

requiredJs [URLS]

Adds the list of urls (relative to JS_DIR, or absolute) as required by the object

Parameters: URLS - a list of required javascript files

requiredCSS [URLS]

Adds the list of urls (relative to CSS_DIR, or absolute) as required by the object

Parameters: URLS - a list of required CSS files

cleanStateful

Class method that initializes all state data of the library. Stateful data is for example the list of already included javascript helper files. If multiple html pages are generated within one process context, this data has to be cleared, so that new pages will start with fresh data.

You will also need to call this method, when using IWL inside of Catalyst(3pm) when running the application with the built-in http server that does not reload modules for each request.

This method is a class method! You do not need to instantiate an object in order to call it.

Note: Currently does nothing, as there is no state data to be cleaned.

getState

Returns the current state of the form as an IWL::Stash object. The form state reflects the state of all of its children of type IWL::Input.

applyState (STATE)

Returns the current state of the form to STATE, an IWL::Stash object. The form state reflects the state of all of its children of type IWL::Input.

getResponseObject

Returns the final response object, used by every IWL::Object

send (%ARGS)

Serializes and sends the object using IWL::Response::send(3pm)

Parameters: %ARGS - a hash of arguments. The following keys are supported:

type

Serializes the object to the given type, and sends the corresponding header. The following types are supported:

html

Serializes the object to HTML and sends it with a text/html header

json

Serializes the object to JSON and sends it with an application/json header

text

Serializes the object to HTML and sends it with a text/plain header

A hash reference, representing an HTTP header, can be passed. It will extend the default header for those types.

static

If true, an ETag, generated using Digest::MD5, will be added to the header of the response. If the ETag matches the HTTP_IF_NONE_MATCH, the response will also contain a Status with a value of 304, and no actual content will be passed.

etag

If provided, along with static, it will use the values as an ETag header, instead of using Digest::MD5. This is also useful, since no content needs to exist.

up ([CRITERIA])
up ([options => OPTIONS, criteria => CRITERIA])

Searches upward along the object stack for objects, matching the criteria set by the options.

In scalar context, returns the first found object. In list context, returns all matching objects. Returns the parent object in scalar context, and parent objects in list context, if no criteria are given.

See IWL::Object::match(3pm) for CRITERIA documentation. If the method is invoked with the second syntax, CRITERIA must be an array reference, instead of a list.

Parameters: OPTIONS - a hash reference, with the following key-value pairs:

last

If true and in list context, the method will return the last matched object, or the last object in the stack.

down ([CRITERIA])
down ([options => OPTIONS, criteria => CRITERIA])

Searches downward along the object stack for objects, matching the criteria set by the options.

In scalar context, returns the first found object. In list context, returns all matching objects. Returns the parent object in scalar context, and parent objects in list context, if no criteria are given.

See IWL::Object::match(3pm) for CRITERIA documentation. If the method is invoked with the second syntax, CRITERIA must be an array reference, instead of a list.

Parameters: OPTIONS - a hash reference, with the following key-value pairs:

last

If true and in list context, the method will return the last matched object, or the last object in the stack.

next ([CRITERIA])
next ([options => OPTIONS, criteria => CRITERIA])

Searches the next siblings of the object for objects, matching the criteria set by the options.

In scalar context, returns the first found object. In list context, returns all matching objects. Returns the parent object in scalar context, and parent objects in list context, if no criteria are given.

See IWL::Object::match(3pm) for CRITERIA documentation. If the method is invoked with the second syntax, CRITERIA must be an array reference, instead of a list.

Parameters: OPTIONS - a hash reference, with the following key-value pairs:

last

If true and in list context, the method will return the last matched object, or the last object in the stack.

previous ([CRITERIA])
previous ([options => OPTIONS, criteria => CRITERIA])

Searches the previous siblings of the object for objects, matching the criteria set by the options.

In scalar context, returns the first found object. In list context, returns all matching objects. Returns the parent object in scalar context, and parent objects in list context, if no criteria are given.

See IWL::Object::match(3pm) for CRITERIA documentation. If the method is invoked with the second syntax, CRITERIA must be an array reference, instead of a list.

Parameters: OPTIONS - a hash reference, with the following key-value pairs:

last

If true and in list context, the method will return the last matched object, or the last object in the stack.

match (CRITERIA)

Returns the object, if it matches the given criteria. Returns false, otherwise. By default, criteria are evaluated with a logical AND.

Parameters: CRITERIA - the criteria is a list of parameters, which can have the following values:

or

A short-circuit logical OR operator.

not

A logical NOT operator. Will reverse the next criterion.

term

A term is a hash reference. The following key-value pairs are supported by IWL::Object:

package => CLASS

The package, which the object belongs to.

attribute => [NAME => VALUE]

An attribute, whose name and value should match an attribute of an object. The value of this option is a arrayref, where the first element is the attribute name, and second is the string value for that name, or a compiled reguler expression.

Other classes can expand the list, if they implement the protected _matchTerm method, which receives the term, and returns true or false, depending on whether the object matches the term.

getEnvironment

Returns the IWL::Environment of the object's top ancestor, if an environment is set

PROTECTED METHODS

The following methods should only be used by classes that inherit from IWL::Object.

_appendInitScript (SCRIPTS)

Appends SCRIPTS to the list of the object's initialization scripts

Parameters: SCRIPTS - JavaScript code, which will be inserted into an IWL::Script widget upon realization

_realize

Realizes the object. It is right before the object is serialized into HTML or JSON

LICENCE AND COPYRIGHT

Copyright (c) 2006-2007 Viktor Kojouharov. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perldoc perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 1486:

You forgot a '=back' before '=head1'

Around line 1501:

'=item' outside of any '=over'

Around line 1713:

You forgot a '=back' before '=head1'