XML::Rabbit::Trait::XPath - Base role for other xpath traits
version 0.1.0
package XML::Rabbit::Trait::XPathSomething; use Moose::Role; with 'XML::Rabbit::Trait::XPath'; sub _build_default { my ($self) = @_; return sub { my ($parent) = @_; ... }; } no Moose::Role; package Moose::Meta::Attribute::Custom::Trait::XPathSomething; sub register_implementation { 'XML::Rabbit::Trait::XPathSomething' } 1;
This module provides base methods for other xpath traits.
See XML::Rabbit for a more complete example.
A string or a coderef that generates a string that is the XPath query used to find the wanted value. Read Only.
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).
_build_default
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 . "" : ""; }; }
Robin Smidsrød <robin@smidsrod.no>
This software is copyright (c) 2011 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.
To install XML::Rabbit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Rabbit
CPAN shell
perl -MCPAN -e shell install XML::Rabbit
For more information on module installation, please visit the detailed CPAN module installation guide.