| 1 | package W3C::SOAP::Document::Node; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2012-05-26 19:04:19 | ||||||||||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 7 | our $VERSION = 0.13; | |||||||||||||||||||||||||||
| 18 | 7 | ▶ | $ENV{W3C_SOAP_NAME_STYLE} ||= 'perl'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"W3C_SOAP_NAME_STYLE"} ||= "perl"
MC/DC0%0/1
$ENV{"W3C_SOAP_NAME_STYLE"} ||= "perl"
$ENV{"W3C_SOAP_NAME_STYLE"}
Truth table50%1/2
A
A= $ENV{"W3C_SOAP_NAME_STYLE"}
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 7 | has node => ( | |||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||
| 22 | isa => 'XML::LibXML::Node', | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | 7 | has parent_node => ( | |||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||
| 27 | isa => 'Maybe[W3C::SOAP::Document::Node]', | ||||||||||||||||||||||||||||
| 28 | predicate => 'has_parent_node', | ||||||||||||||||||||||||||||
| 29 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | 7 | has document => ( | |||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | isa => 'W3C::SOAP::Document', | ||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||
| 35 | builder => '_document', | ||||||||||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||||||||||
| 37 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 38 | handles => { | ||||||||||||||||||||||||||||
| 39 | xpc => 'xpc', | ||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | 7 | has name => ( | |||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||
| 44 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 45 | predicate => 'has_name', | ||||||||||||||||||||||||||||
| 46 | builder => '_name', | ||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | has perl_name => ( | |||||||||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||||||||||
| 52 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 53 | predicate => 'has_perl_name', | ||||||||||||||||||||||||||||
| 54 | builder => '_perl_name', | ||||||||||||||||||||||||||||
| 55 | lazy => 1, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | has perl_names => ( | ||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||
| 60 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 61 | lazy => 1, | ||||||||||||||||||||||||||||
| 62 | 38 | ▶ | default => sub { return {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 7 | ); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 66 | 606 | ▶ | my ($orig, $class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||
| 67 | 606 | ▶ | my $args | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | = !@args ? {} | ||||||||||||||||||||||||||||
| 69 | : @args == 1 ? $args[0] | ||||||||||||||||||||||||||||
| 70 | : {@args}; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | confess "If document is not specified parent_node must be defined!\n" | ||||||||||||||||||||||||||||
| 73 | 606 | ▶ | if !$args->{document} && !$args->{parent_node}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args->{"document"} or $args->{"parent_node"}
MC/DC0%0/2
$args->{"document"} or $args->{"parent_node"}
$args->{"document"}
$args->{"parent_node"}
Truth table66%2/3
A or B
A= $args->{"document"}B= $args->{"parent_node"}
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 606 | return $class->$orig($args); | |||||||||||||||||||||||||||
| 76 | 7 | }; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub _document { | ||||||||||||||||||||||||||||
| 79 | 473 | ▶ | my ($self) = shift; | ||||||||||||||||||||||||||
|
Subroutine
_document: called CC=4 SCAR=16.1
| |||||||||||||||||||||||||||||
| 80 | 473 | ▶ | confess "Lazybuild $self has both no parent_node nore document!\n" if !$self->has_parent_node || !defined $self->parent_node; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_parent_node and defined $self->parent_node
MC/DC0%0/2
$self->has_parent_node and defined $self->parent_node
$self->has_parent_node
defined $self->parent_node
Truth table33%1/3
A and B
A= $self->has_parent_nodeB= defined $self->parent_node
| |||||||||||||||||||||||||||||
| 81 | 473 | ▶ | return $self->parent_node->isa('W3C::SOAP::Document') ? $self->parent_node : $self->parent_node->document; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub _name { | ||||||||||||||||||||||||||||
| 85 | 583 | ▶ | my ($self) = shift; | ||||||||||||||||||||||||||
|
Subroutine
_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 583 | my $name = $self->node->getAttribute('name'); | |||||||||||||||||||||||||||
| 87 | 583 | ▶ | $name =~ s/\W/_/gxms if $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 583 | return $name; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub _perl_name | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 487 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_perl_name: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 94 | 487 | my $name = $self->name; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 487 | ▶ | if ( $name && ( $ENV{W3C_SOAP_NAME_STYLE} ne 'original' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name and $ENV{"W3C_SOAP_NAME_STYLE"} ne "original"
MC/DC0%0/2
$name and $ENV{"W3C_SOAP_NAME_STYLE"} ne "original"
$name
$ENV{"W3C_SOAP_NAME_STYLE"} ne "original"
Truth table33%1/3
A and B
A= $nameB= $ENV{"W3C_SOAP_NAME_STYLE"} ne "original"
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 487 | $name =~ s/ (?<= [^A-Z_] ) ([A-Z]) /_$1/gxms; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # the allowed characters in XML identifiers are not the same | ||||||||||||||||||||||||||||
| 101 | # as those in Perl | ||||||||||||||||||||||||||||
| 102 | 487 | $name =~ s/\W//g; | |||||||||||||||||||||||||||
| 103 | 487 | $name = lc $name; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # horrid hack to dedupe elements Foo_Bar and Foo.Bar | ||||||||||||||||||||||||||||
| 106 | # which are obviously stupid but allowed | ||||||||||||||||||||||||||||
| 107 | 487 | ▶ | if ( defined( my $parent = $self->parent_node() ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 451 | ▶ | if ( exists $parent->perl_names()->{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 3 | $name .= '_' . $parent->perl_names()->{$name}; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 451 | $parent->perl_names()->{$name}++; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 487 | return $name; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 7 | 1; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __END__ | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head1 NAME | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | W3C::SOAP::Document::Node - The super class for document nodes | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 VERSION | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | This documentation refers to W3C::SOAP::Document::Node version 0.13. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | use W3C::SOAP::Document::Node; | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # Brief but working code example(s) here showing the most common usage(s) | ||||||||||||||||||||||||||||
| 134 | # This section will be as far as many users bother reading, so make it as | ||||||||||||||||||||||||||||
| 135 | # educational and exemplary as possible. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Base class for modules extracting information about XML nodes. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =over 4 | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =item C<perl_name ()> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Converts the node's name (if it has one) from camel case to the Perl style | ||||||||||||||||||||||||||||
| 149 | underscore separated words eg TagName -> tag_name. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 INCOMPATIBILITIES | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 BUGS AND LIMITATIONS | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | There are no known bugs in this module. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Please report problems to Ivan Wills (ivan.wills@gmail.com). | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Patches are welcome. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | Ivan Wills - (ivan.wills@gmail.com) | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Copyright (c) 2012 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | ||||||||||||||||||||||||||||
| 176 | All rights reserved. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | This module is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 179 | the same terms as Perl itself. See L<perlartistic>. This program is | ||||||||||||||||||||||||||||
| 180 | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||||||||||||||||||||||||||||
| 181 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 182 | PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||