Rabbit/Trait/XPathObject.pm

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 97.5% 39 / 40 CC 2 SCAR 2.1
CC
2
Cov
97%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Rabbit/Trait/XPathValue.pm ↑ Summary Rabbit/Role/Node.pm »
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::XPathObject;
5 {
6 15 $XML::Rabbit::Trait::XPathObject::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: XML DOM object xpath extractor trait
13  
14 around '_process_options' => sub {
15 15 ▶ my ($orig, $self, $name, $options, @rest) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
16  
17 15 $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 15 ▶ confess("isa attribute is required") unless defined( $options->{'isa'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{"isa"} 0 15 15
23 15 };
24  
25  
26 has 'isa_map' => (
27 is => 'ro',
28 isa => 'HashRef[Str]',
29 lazy => 1,
30 13 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 15 );
32  
33  
34 sub _build_default {
35 15 ▶ my ($self) = @_;
Subroutine _build_default: called CC=1 SCAR=0.0
36 return sub {
37 15 ▶ my ($parent) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
38 15 my $node = $self->_find_node(
39 $parent,
40 $self->_resolve_xpath_query( $parent ),
41 );
42 15 $self->_convert_isa_map( $parent );
43 15 my $class = $self->_resolve_class();
44 15 return $self->_create_instance( $parent, $class, $node );
45 15 };
46 }
47  
48 15 Moose::Util::meta_attribute_alias('XPathObject');
49  
50 15 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 15 1;
53  
54 __END__
55  
56 =pod
57  
58 =encoding utf-8
59  
60 =head1 NAME
61  
62 XML::Rabbit::Trait::XPathObject - XML DOM object xpath extractor trait
63  
64 =head1 VERSION
65  
66 version 0.4.0
67  
68 =head1 SYNOPSIS
69  
70 package MyXMLSyntaxNode;
71 use Moose;
72 with 'XML::Rabbit::Node';
73  
74 has 'first_person' => (
75 isa => 'MyXMLSyntax::Person',
76 traits => [qw(XPathObject)],
77 xpath_query => './person[1]',
78 );
79  
80 no Moose;
81 __PACKAGE__->meta->make_immutable();
82  
83 1;
84  
85 =head1 DESCRIPTION
86  
87 This module provides the extraction of complex values (subtrees) from an XML
88 node based on an XPath query. The subtree is used as input for the
89 constructor of the class specified in the isa attribute.
90  
91 See L<XML::Rabbit> for a more complete example.
92  
93 =head1 ATTRIBUTES
94  
95 =head2 isa_map
96  
97 Specifies the prefix:tag to class name mapping used with union xpath
98 queries. See L<XML::Rabbit> for more detailed information.
99  
100 =head1 METHODS
101  
102 =head2 _build_default
103  
104 Returns a coderef that is run to build the default value of the parent attribute. Read Only.
105  
106 =head1 AUTHOR
107  
108 Robin Smidsrød <robin@smidsrod.no>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2013 by Robin Smidsrød.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
« Rabbit/Trait/XPathValue.pm ↑ Summary Rabbit/Role/Node.pm »