NAME

MozRepl::RemoteObject::Methods - Perl methods for mozrepl objects

SYNOPSIS

  my @links = $obj->MozRepl::RemoteObject::Methods::xpath('//a');

This module holds the routines that previously lived as injected object methods on all Javascript objects.

METHODS

$obj->MozRepl::RemoteObject::Methods::invoke(METHOD, ARGS)

The invoke() object method is an alternate way to invoke Javascript methods. It is normally equivalent to $obj->$method(@ARGS). This function must be used if the METHOD name contains characters not valid in a Perl variable name (like foreign language characters). To invoke a Javascript objects native __invoke method (if such a thing exists), please use:

    $object->MozRepl::RemoteObject::Methods::invoke('__invoke', @args);

This method can be used to call the Javascript functions with the same name as other convenience methods implemented in Perl:

    __attr
    __setAttr
    __xpath
    __click
    ...

$obj->MozRepl::RemoteObject::Methods::transform_arguments(@args)

This method transforms the passed in arguments to their JSON string representations.

Things that match /^(?:[1-9][0-9]*|0+)$/ get passed through.

MozRepl::RemoteObject::Instance instances are transformed into strings that resolve to their Javascript global variables. Use the ->expr method to get an object representing these.

It's also impossible to pass a negative or fractional number as a number through to Javascript, or to pass digits as a Javascript string.

$obj->MozRepl::RemoteObject::Methods::id

Readonly accessor for the internal object id that connects the Javascript object to the Perl object.

$obj->MozRepl::RemoteObject::Methods::on_destroy

Accessor for the callback that gets invoked from DESTROY.

$obj->MozRepl::RemoteObject::Methods::bridge

Readonly accessor for the bridge that connects the Javascript object to the Perl object.

MozRepl::RemoteObject::Methods::as_hash($obj)

MozRepl::RemoteObject::Methods::as_array($obj)

MozRepl::RemoteObject::Methods::as_code($obj)

Returns a reference to a hash/array/coderef. This is used by overload. Don't use these directly.

$obj->MozRepl::RemoteObject::Methods::xpath( $query [, $ref, $cont ] )

Executes an XPath query and returns the node snapshot result as a list.

This is a convenience method that should only be called on HTMLdocument nodes.

The optional $ref parameter can be a DOM node relative to which a relative XPath expression will be evaluated. It defaults to undef.

The optional $cont parameter can be a Javascript function that will get applied to every result. This can be used to directly map each DOM node in the XPath result to an attribute. For example for efficiently fetching the text value of an XPath query resulting in textnodes, the two snippets are equivalent, but the latter executes less roundtrips between Perl and Javascript:

    my @text = map { $_->{nodeValue} }
        $obj->MozRepl::RemoteObject::Methods::xpath( '//p/text()' )


    my $fetch_nodeValue = $bridge->declare(<<JS);
        function (e){ return e.nodeValue }
    JS
    my @text = map { $_->{nodeValue} }
        $obj->MozRepl::RemoteObject::Methods::xpath( '//p/text()', undef, $fetch_nodeValue )

Note that the result type is fetched with XPathResult.ORDERED_NODE_SNAPSHOT_TYPE . There is no support for retrieving results as XPathResult.ANY_TYPE yet.

MozRepl::RemoteObject::Methods::dive($obj)

Convenience method to quickly dive down a property chain.

If any element on the path is missing, the method dies with the error message which element was not found.

This method is faster than descending through the object forest with Perl, but otherwise identical.

  my $obj = $tab->{linkedBrowser}
                ->{contentWindow}
                ->{document}
                ->{body}

  my $obj = $tab->MozRepl::RemoteObject::Methods::dive(
      qw(linkedBrowser contentWindow document body)
  );

SEE ALSO

MozRepl::RemoteObject for the objects to use this with

REPOSITORY

The public repository of this module is http://github.com/Corion/mozrepl-remoteobject.

AUTHOR

Max Maischein corion@cpan.org

COPYRIGHT (c)

Copyright 2011-2012 by Max Maischein corion@cpan.org.

LICENSE

This module is released under the same terms as Perl itself.