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

NAME

XML::Rabbit::Trait::XPath - Base role for other xpath traits

VERSION

version 0.4.0

SYNOPSIS

    package XML::Rabbit::Trait::XPathSomething;
    use Moose::Role;

    with 'XML::Rabbit::Trait::XPath';

    sub _build_default {
        my ($self) = @_;
        return sub {
            my ($parent) = @_;

            ...

        };
    }

    Moose::Util::meta_attribute_alias('XPathSomething');

    no Moose::Role;

    1;

DESCRIPTION

This module provides base methods for other xpath traits.

See XML::Rabbit for a more complete example.

ATTRIBUTES

xpath_query

A string or a coderef that generates a string that is the XPath query used to find the wanted value. Read Only.

METHODS

_build_default

Each trait that composes this trait will need to define a method name _build_default. The _build_default method is called as a method on the generated attribute class. It should return a code reference that will be run in the content of the parent class (i.e. the class that defined the attribute).

Below you can see an example from the XPathValue trait:

    sub _build_default {
        my ($self) = @_;
        return sub {
            my ($parent) = @_;
            my $node = $self->_find_node(
                $parent,
                $self->_resolve_xpath_query( $parent ),
            );
            return blessed($node) ? $node->to_literal . "" : "";
        };
    }

AUTHOR

Robin Smidsrød <robin@smidsrod.no>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Robin Smidsrød.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.