blib/lib/SOAP/WSDL/Base.pm

filter: Statementstmt 55.4% 61 / 110 Branchbran 32.5% 13 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 15 / 21 Podpod 0.0% 0 / 8 totaltotal 49.7% 89 / 179 CC 22 SCAR 25.1
CC
22
Cov
49%
expand
42.0
init
30.0
__ANON__
12.0
CRAP 12.3
« blib/lib/SOAP/WSDL/Generator/Template/XSD.pm ↑ Summary blib/lib/SOAP/WSDL/XSD/SimpleType.pm »
1 package SOAP::WSDL::Base;
2 11 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Class::Std::Fast::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Carp qw(croak carp confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = 3.004;
9  
10 11 my %id_of :ATTR(:name<id> :default<()>);
11 11 my %lang_of :ATTR(:name<lang> :default<()>);
12 11 my %name_of :ATTR(:name<name> :default<()>);
13 11 my %namespace_of :ATTR(:name<namespace> :default<()>);
14 11 my %documentation_of :ATTR(:name<documentation> :default<()>);
15 11 my %annotation_of :ATTR(:name<annotation> :default<()>);
16 11 my %targetNamespace_of :ATTR(:name<targetNamespace> :default<"">);
17 11 my %xmlns_of :ATTR(:name<xmlns> :default<{}>);
18 11 my %parent_of :ATTR(:get<parent> :default<()>);
19  
20 11 my %namespaces_of :ATTR(:default<{}>);
21  
22 0 ▶sub namespaces {
Subroutine namespaces: not called CC=1 SCAR=6.9
Pod undocumented
23 0 return shift->get_xmlns();
24 }
25  
26 67 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=8.1
Pod undocumented
27 67 my ($self, $ident, $arg_ref) = @_;
28 67 ▶ if (defined $arg_ref->{ parent }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg_ref->{"parent"}) 0 67 67
29 $parent_of{ $ident } = delete $arg_ref->{ parent },
30 0 Scalar::Util::weaken($parent_of{ $ident });
31 }
32 }
33  
34 67 ▶sub START {
Subroutine START: called CC=1 SCAR=0.0
Pod undocumented
35 67 my ($self, $ident, $arg_ref) = @_;
36 67 $xmlns_of{ $ident }->{ 'xml' } = 'http://www.w3.org/XML/1998/namespace';
37 67 $namespaces_of{ $ident }->{ '#default' } = $self->get_xmlns()->{ '#default' };
38 67 $namespaces_of{ $ident }->{ 'xml' } = 'http://www.w3.org/XML/1998/namespace';
39 }
40  
41 #
42 # set_parent is hand-implemented to break up (weaken) the circular reference
43 # between an object and it's parent
44 #
45 0 ▶sub set_parent {
Subroutine set_parent: not called CC=1 SCAR=6.9
Pod undocumented
46 0 $parent_of{ ${ $_[0]} } = $_[1];
47 0 Scalar::Util::weaken($parent_of{ ${ $_[0]} });
48 }
49  
50 # _accept is here to be called by visitor.
51 # The visitor pattern is a level of indirection - here the visitor calls
52 # $object->_accept($visitor) on each object, which in turn calls
53 # $visitor->visit_$class( $object ) where $class is the object's class.
54 #
55 0 ▶sub _accept {
Subroutine _accept: not called CC=1 SCAR=2.6
56 0 my $self = shift;
57 0 my $class = ref $self;
58 0 $class =~ s{ \A SOAP::WSDL:: }{}xms;
59 0 $class =~ s{ (:? :: ) }{_}gxms;
60 0 my $method = "visit_$class";
61 11 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
62 0 return shift->$method( $self );
63 }
64  
65 # unfortunately, AUTOMETHOD is SLOW.
66 # Re-implement in derived package wherever speed is an issue...
67 #
68 15 ▶sub AUTOMETHOD {
Subroutine AUTOMETHOD: called CC=5 SCAR=17.4
Pod undocumented
69 15 my ($self, $ident, @values) = @_;
70 15 my $subname = $_; # Requested subroutine name is passed via $_
71  
72 # we're called as $self->push_something(@values);
73 15 ▶ if ($subname =~s{^push_}{}xms) {
Branch: 3 branches
BranchTrueFalseTotal
if ($subname =~ s/^push_//msx) { } 7 8 15
elsif ($subname =~ s/^find_/get_/msx) { } 8 0 8
elsif ($subname =~ s/^first_/get_/msx) { } 0 0 0
74 7 my $getter = "get_$subname";
75 7 my $setter = "set_$subname";
76 # Checking here is paranoid - will fail fatally if there is no setter.
77 # And we would have to check getters, too.
78 # Maybe do it the Conway way via the Symbol table...
79 # ... can is way slow...
80 7 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
81 11 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
82 7 my $old_value = $self->$getter();
83 # Listify if not a list ref
84 7 ▶ $old_value = $old_value ? [ $old_value ] : [] if not ref $old_value;
Branch: 2 branches
BranchTrueFalseTotal
unless ref $old_value 2 5 7
$old_value ? : 1 1 2
85  
86 7 push @$old_value , @values;
87 7 $self->$setter( $old_value );
88 7 };
89 }
90  
91 # we're called as $obj->find_something($ns, $key)
92 elsif ($subname =~s {^find_}{get_}xms) {
93 8 ▶ @values = @{ $values[0] } if ref $values[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $values[0] eq "ARRAY" 1 7 8
94 8 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
95 5 ▶ return List::Util::first {
Subroutine __ANON__: called CC=2 SCAR=6.9
96 5 ▶ $_->get_targetNamespace() eq $values[0] &&
Branch: 1 branch
BranchTrueFalseTotal
$_->get_targetNamespace eq $values[0] and $_->get_name eq $values[1] 2 1 3
97 $_->get_name() eq $values[1]
98 }
99 8 @{ $self->$subname() };
100 }
101 8 }
102 elsif ($subname =~s {^first_}{get_}xms) {
103 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
104 0 my $result_ref = $self->$subname();
105 0 ▶ return if not $result_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $result_ref 0 0 0
106 0 ▶ return $result_ref if (not ref $result_ref eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result_ref eq "ARRAY" 0 0 0
107 0 return $result_ref->[0];
108 0 };
109 }
110  
111 0 return;
112 }
113  
114 0 ▶sub init {
Subroutine init: not called CC=5 SCAR=34.0
Pod undocumented
115 0 my ($self, @args) = @_;
116 0 foreach my $value (@args) {
117 0 ▶ croak @args if (not defined ($value->{ Name }));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value->{"Name"} 0 0 0
118  
119 0 ▶ if ($value->{ Name } =~m{^xmlns\:}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{"Name"} =~ /^xmlns\:/msx) 0 0 0
120 # add namespaces
121 0 $xmlns_of{ ident $self }->{ $value->{ LocalName } } = $value->{ Value };
122 0 next;
123 }
124  
125 # check for namespae-qualified attributes.
126 # neither XML Schema, nor WSDL1.1, nor the SOAP binding allow
127 # namespace-qualified attribute names
128 0 my ($ns, $localname) = split /\|/, $value->{ Name };
129 0 ▶ if ($ns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ns) 0 0 0
130 0 warn "found unrecognised attribute \{$ns}$localname (ignored)";
131 0 next;
132 }
133  
134 0 my $name = $value->{ LocalName };
135 0 my $method = "set_$name";
136 0 $self->$method( $value->{ Value } );
137 }
138 0 return $self;
139 }
140  
141 0 ▶sub expand {
Subroutine expand: not called CC=6 SCAR=37.4
Pod undocumented
142 0 my ($self, $qname) = @_;
143 0 my $ns_of = $self->namespaces();
144 0 my $parent;
145 0 ▶ if (not $qname=~m{:}xm) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($qname =~ /:/mx) 0 0 0
146 0 ▶ if (defined $ns_of->{ '#default' }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ns_of->{"#default"}) 0 0 0
147 # TODO check. Returning the targetNamespace for the default ns
148 # is probably wrong
149 #return $self->get_targetNamespace(), $qname;
150 0 return $ns_of->{ '#default' }, $qname;
151 }
152 0 ▶ if ($parent = $self->get_parent()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent = $self->get_parent) 0 0 0
153 0 return $parent->expand($qname);
154 }
155 0 die "un-prefixed element name <$qname> found, but no default namespace set\n"
156 }
157  
158 0 my ($prefix, $localname) = split /:/x, $qname;
159  
160 0 ▶ return ($ns_of->{ $prefix }, $localname) if ($ns_of->{ $prefix });
Branch: 1 branch
BranchTrueFalseTotal
if $ns_of->{$prefix} 0 0 0
161 0 ▶ if ($parent = $self->get_parent()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent = $self->get_parent) 0 0 0
162 0 return $parent->expand($qname);
163 }
164 croak "unbound prefix $prefix found for $prefix:$localname. Bound prefixes are "
165 0 . join(', ', keys %{ $ns_of });
166 }
167 sub _expand;
168 11 *_expand = \&expand;
169  
170 1 ▶sub schema {
Subroutine schema: called CC=3 SCAR=16.5
Pod undocumented
171 1 my $parent = $_[0]->get_parent();
172 1 ▶ return if ! defined $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent 1 0 1
173 0 ▶ return $parent if $parent->isa('SOAP::WSDL::XSD::Schema');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("SOAP::WSDL::XSD::Schema") 0 0 0
174 0 return $parent->schema();
175 }
176  
177 11 1;
178  
179 __END__
« blib/lib/SOAP/WSDL/Generator/Template/XSD.pm ↑ Summary blib/lib/SOAP/WSDL/XSD/SimpleType.pm »