| 1 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package XML::Rabbit::RootNode; | ||||||||||
| 5 | { | ||||||||||
| 6 | 14 | $XML::Rabbit::RootNode::VERSION = '0.4.0'; | |||||||||
| 7 | } | ||||||||||
| 8 | 14 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 14 | with 'XML::Rabbit::Role::Document'; | |||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: Root node base class | ||||||||||
| 12 | |||||||||||
| 13 | # Preload XPath attribute traits | ||||||||||
| 14 | 14 | ▶ | use XML::Rabbit::Trait::XPathValue; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 14 | ▶ | use XML::Rabbit::Trait::XPathValueList; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 14 | ▶ | use XML::Rabbit::Trait::XPathValueMap; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 14 | ▶ | use XML::Rabbit::Trait::XPathObject; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 14 | ▶ | use XML::Rabbit::Trait::XPathObjectList; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 14 | ▶ | use XML::Rabbit::Trait::XPathObjectMap; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 14 | with 'XML::Rabbit::Role::Node' => { | |||||||||
| 22 | 'node' => { lazy => 1, builder => '_build__node' }, | ||||||||||
| 23 | 'xpc' => { lazy => 1, builder => '_build__xpc' }, | ||||||||||
| 24 | }; | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | sub _build__node { | ||||||||||
| 28 | 13 | ▶ | return shift->_document->documentElement(); | ||||||||
|
Subroutine
_build__node: called CC=1 SCAR=0.0
| |||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | sub _build__xpc { | ||||||||||
| 33 | 13 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build__xpc: called CC=3 SCAR=11.0
| |||||||||||
| 34 | # XML::LibXML loads this class, see XML::Rabbit::Role::Document | ||||||||||
| 35 | 13 | my $xpc = XML::LibXML::XPathContext->new( $self->_document ); | |||||||||
| 36 | |||||||||||
| 37 | # Make sure namespace_map is inherited from XML::Rabbit::Role::Node | ||||||||||
| 38 | 13 | ▶ | confess("Required role 'XML::Rabbit::Role::Node' not composed") unless $self->does('XML::Rabbit::Role::Node'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | # Register all prefixes specified in namespace_map for use in xpath queries | ||||||||||
| 41 | 13 | foreach my $prefix ( keys %{ $self->namespace_map } ) { | |||||||||
| 42 | 12 | $xpc->registerNs($prefix, $self->namespace_map->{$prefix}); | |||||||||
| 43 | } | ||||||||||
| 44 | 13 | return $xpc; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 14 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | 14 | 1; | |||||||||
| 50 | |||||||||||
| 51 | __END__ | ||||||||||
| 52 | |||||||||||
| 53 | =pod | ||||||||||
| 54 | |||||||||||
| 55 | =encoding utf-8 | ||||||||||
| 56 | |||||||||||
| 57 | =head1 NAME | ||||||||||
| 58 | |||||||||||
| 59 | XML::Rabbit::RootNode - Root node base class | ||||||||||
| 60 | |||||||||||
| 61 | =head1 VERSION | ||||||||||
| 62 | |||||||||||
| 63 | version 0.4.0 | ||||||||||
| 64 | |||||||||||
| 65 | =head1 SYNOPSIS | ||||||||||
| 66 | |||||||||||
| 67 | package MyXMLSyntax; | ||||||||||
| 68 | use Moose; | ||||||||||
| 69 | with 'XML::Rabbit::RootNode'; | ||||||||||
| 70 | |||||||||||
| 71 | has title => ( | ||||||||||
| 72 | isa => 'Str', | ||||||||||
| 73 | traits => [qw(XPathValue)], | ||||||||||
| 74 | xpath_query => '/root/title', | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | no Moose; | ||||||||||
| 78 | __PACKAGE__->meta->make_immutable(); | ||||||||||
| 79 | |||||||||||
| 80 | 1; | ||||||||||
| 81 | |||||||||||
| 82 | =head1 DESCRIPTION | ||||||||||
| 83 | |||||||||||
| 84 | This module provides the base node attribute used to hold the root of the XML document. | ||||||||||
| 85 | |||||||||||
| 86 | See L<XML::Rabbit> for a more complete example. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 ATTRIBUTES | ||||||||||
| 89 | |||||||||||
| 90 | =head2 node | ||||||||||
| 91 | |||||||||||
| 92 | An instance of a L<XML::LibXML::Node> class representing the root node of an | ||||||||||
| 93 | XML document. Read Only. | ||||||||||
| 94 | |||||||||||
| 95 | It is lazily loaded from the C<document> attribute, which is inherited from | ||||||||||
| 96 | L<XML::Rabbit::Role::Document>. | ||||||||||
| 97 | |||||||||||
| 98 | =head2 xpc | ||||||||||
| 99 | |||||||||||
| 100 | An instance of a L<XML::LibXML::XPathContext> class initialized with the | ||||||||||
| 101 | C<node> attribute. Read Only. | ||||||||||
| 102 | |||||||||||
| 103 | If a subclass has an attribute named C<namespace_map> which is a HashRef it | ||||||||||
| 104 | is used to initialize namespaces using the C<registerNs> method. This is | ||||||||||
| 105 | required on XML files that use namespaces, like XHTML. | ||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Robin Smidsrød <robin@smidsrod.no> | ||||||||||
| 110 | |||||||||||
| 111 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 112 | |||||||||||
| 113 | This software is copyright (c) 2013 by Robin Smidsrød. | ||||||||||
| 114 | |||||||||||
| 115 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 116 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||