| 1 | 15 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 15 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package XML::Rabbit::Trait::XPathValueList; | ||||||||||
| 5 | { | ||||||||||
| 6 | 15 | $XML::Rabbit::Trait::XPathValueList::VERSION = '0.4.0'; | |||||||||
| 7 | } | ||||||||||
| 8 | 15 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 15 | with 'XML::Rabbit::Trait::XPath'; | |||||||||
| 11 | |||||||||||
| 12 | # ABSTRACT: Multiple value xpath extractor trait | ||||||||||
| 13 | |||||||||||
| 14 | around '_process_options' => sub { | ||||||||||
| 15 | 6 | ▶ | my ($orig, $self, $name, $options, @rest) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 16 | |||||||||||
| 17 | 6 | $self->$orig($name, $options, @rest); | |||||||||
| 18 | |||||||||||
| 19 | # This should really be: | ||||||||||
| 20 | # has '+isa' => ( required => 1 ); | ||||||||||
| 21 | # but for some unknown reason Moose doesn't allow that | ||||||||||
| 22 | 6 | ▶ | confess("isa attribute is required") unless defined( $options->{'isa'} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 15 | }; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | sub _build_default { | ||||||||||
| 27 | 4 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_default: called CC=1 SCAR=0.0
| |||||||||||
| 28 | return sub { | ||||||||||
| 29 | 4 | ▶ | my ($parent) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 30 | 4 | my $xpath_query = $self->_resolve_xpath_query( $parent ); | |||||||||
| 31 | 4 | my @nodes; | |||||||||
| 32 | 4 | foreach my $node ( $self->_find_nodes( $parent, $xpath_query ) ) { | |||||||||
| 33 | 4 | push @nodes, $node->to_literal . ""; | |||||||||
| 34 | } | ||||||||||
| 35 | 4 | return \@nodes; | |||||||||
| 36 | 4 | }; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 15 | Moose::Util::meta_attribute_alias('XPathValueList'); | |||||||||
| 40 | |||||||||||
| 41 | 15 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 15 | 1; | |||||||||
| 44 | |||||||||||
| 45 | __END__ | ||||||||||
| 46 | |||||||||||
| 47 | =pod | ||||||||||
| 48 | |||||||||||
| 49 | =encoding utf-8 | ||||||||||
| 50 | |||||||||||
| 51 | =head1 NAME | ||||||||||
| 52 | |||||||||||
| 53 | XML::Rabbit::Trait::XPathValueList - Multiple value xpath extractor trait | ||||||||||
| 54 | |||||||||||
| 55 | =head1 VERSION | ||||||||||
| 56 | |||||||||||
| 57 | version 0.4.0 | ||||||||||
| 58 | |||||||||||
| 59 | =head1 SYNOPSIS | ||||||||||
| 60 | |||||||||||
| 61 | package MyXMLSyntaxNode; | ||||||||||
| 62 | use Moose; | ||||||||||
| 63 | with 'XML::Rabbit::RootNode'; | ||||||||||
| 64 | |||||||||||
| 65 | has all_references => ( | ||||||||||
| 66 | isa => 'ArrayRef[Str]', | ||||||||||
| 67 | traits => [qw(XPathValueList)], | ||||||||||
| 68 | xpath_query => '//@href|//@src', | ||||||||||
| 69 | ); | ||||||||||
| 70 | |||||||||||
| 71 | no Moose; | ||||||||||
| 72 | __PACKAGE__->meta->make_immutable(); | ||||||||||
| 73 | |||||||||||
| 74 | 1; | ||||||||||
| 75 | |||||||||||
| 76 | =head1 DESCRIPTION | ||||||||||
| 77 | |||||||||||
| 78 | This module provides the extraction of primitive values from an XML node based on an XPath query. | ||||||||||
| 79 | |||||||||||
| 80 | See L<XML::Rabbit> for a more complete example. | ||||||||||
| 81 | |||||||||||
| 82 | =head1 METHODS | ||||||||||
| 83 | |||||||||||
| 84 | =head2 _build_default | ||||||||||
| 85 | |||||||||||
| 86 | Returns a coderef that is run to build the default value of the parent attribute. Read Only. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 AUTHOR | ||||||||||
| 89 | |||||||||||
| 90 | Robin Smidsrød <robin@smidsrod.no> | ||||||||||
| 91 | |||||||||||
| 92 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 93 | |||||||||||
| 94 | This software is copyright (c) 2013 by Robin Smidsrød. | ||||||||||
| 95 | |||||||||||
| 96 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 97 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||