The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

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

VERSION

version 0.4.1

SYNOPSIS

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) 2015 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.