| 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::Role::Node; | ||
| 5 | { | ||
| 6 | 15 | $XML::Rabbit::Role::Node::VERSION = '0.4.0'; | |
| 7 | } | ||
| 8 | 15 | ▶ | use MooseX::Role::Parameterized; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 15 | ▶ | use Encode (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | # ABSTRACT: Base role for all nodes | ||
| 13 | |||
| 14 | |||
| 15 | 0 | ▶ | parameter 'node' => ( isa => 'HashRef', default => sub { +{} } ); |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 16 | |||
| 17 | |||
| 18 | 0 | ▶ | parameter 'xpc' => ( isa => 'HashRef', default => sub { +{} } ); |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 19 | |||
| 20 | |||
| 21 | 14 | ▶ | parameter 'namespace_map' => ( isa => 'HashRef', default => sub { +{} } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | role { | ||
| 24 | 27 | ▶ | my ($p) = @_; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | has '_xpc' => ( | ||
| 27 | is => 'ro', | ||
| 28 | isa => 'XML::LibXML::XPathContext', | ||
| 29 | reader => 'xpc', | ||
| 30 | init_arg => 'xpc', | ||
| 31 | 27 | %{ $p->xpc } | |
| 32 | ); | ||
| 33 | |||
| 34 | has '_node' => ( | ||
| 35 | is => 'ro', | ||
| 36 | isa => 'XML::LibXML::Node', | ||
| 37 | reader => 'node', | ||
| 38 | init_arg => 'node', | ||
| 39 | 27 | %{ $p->node } | |
| 40 | ); | ||
| 41 | |||
| 42 | has 'namespace_map' => ( | ||
| 43 | is => 'ro', | ||
| 44 | isa => 'HashRef[Str]', | ||
| 45 | lazy => 1, | ||
| 46 | 6 | ▶ | default => sub { +{} }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 47 | 27 | %{ $p->namespace_map }, | |
| 48 | ); | ||
| 49 | |||
| 50 | 15 | }; | |
| 51 | |||
| 52 | |||
| 53 | sub dump_xml { | ||
| 54 | 1 | ▶ | my ($self) = @_; |
|
Subroutine
dump_xml: called CC=1 SCAR=0.0
Pod
documented
| |||
| 55 | 1 | return $self->node->toString(1); | |
| 56 | } | ||
| 57 | |||
| 58 | 15 | ▶ | no MooseX::Role::Parameterized; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 59 | |||
| 60 | 15 | 1; | |
| 61 | |||
| 62 | __END__ | ||
| 63 | |||
| 64 | =pod | ||
| 65 | |||
| 66 | =encoding utf-8 | ||
| 67 | |||
| 68 | =head1 NAME | ||
| 69 | |||
| 70 | XML::Rabbit::Role::Node - Base role for all nodes | ||
| 71 | |||
| 72 | =head1 VERSION | ||
| 73 | |||
| 74 | version 0.4.0 | ||
| 75 | |||
| 76 | =head1 SYNOPSIS | ||
| 77 | |||
| 78 | See L<XML::Rabbit::RootNode> or L<XML::Rabbit::Node> for examples. | ||
| 79 | |||
| 80 | =head1 DESCRIPTION | ||
| 81 | |||
| 82 | This module provides attributes and methods common to all nodes. | ||
| 83 | |||
| 84 | See L<XML::Rabbit> for a more complete example. | ||
| 85 | |||
| 86 | =head1 ATTRIBUTES | ||
| 87 | |||
| 88 | =head2 node | ||
| 89 | |||
| 90 | An instance of a L<XML::LibXML::Node> class representing the a node in an XML document. Read Only. | ||
| 91 | |||
| 92 | =head2 xpc | ||
| 93 | |||
| 94 | An instance of a L<XML::LibXML::XPathContext> class initialized with the C<node> attribute. Read Only. | ||
| 95 | |||
| 96 | =head2 namespace_map | ||
| 97 | |||
| 98 | A HashRef of strings that defines the prefix/namespace XML mappings for the | ||
| 99 | XPath parser. Usually overriden in a subclass like this: | ||
| 100 | |||
| 101 | has '+namespace_map' => ( | ||
| 102 | default => sub { { | ||
| 103 | myprefix => "http://my.example.com", | ||
| 104 | myotherprefix => "http://other.example2.org", | ||
| 105 | } }, | ||
| 106 | ); | ||
| 107 | |||
| 108 | =head1 METHODS | ||
| 109 | |||
| 110 | =head2 dump_xml | ||
| 111 | |||
| 112 | Dumps the XML of the current node as a native perl string. | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Robin Smidsrød <robin@smidsrod.no> | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | This software is copyright (c) 2013 by Robin Smidsrød. | ||
| 121 | |||
| 122 | This is free software; you can redistribute it and/or modify it under | ||
| 123 | the same terms as the Perl 5 programming language system itself. | ||
| 124 | |||
| 125 | =cut | ||