blib/lib/SOAP/WSDL/XSD/SimpleType.pm

filter: Statementstmt 88.3% 76 / 86 Branchbran 57.6% 15 / 26 Conditioncond 53.3% 8 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 74.3% 110 / 148 CC 23 SCAR 24.8
CC
23
Cov
78%
_serialize_single
28.5
serialize
9.3
set_restriction
3.0
CRAP 12.0
« blib/lib/SOAP/WSDL/Base.pm ↑ Summary blib/lib/SOAP/WSDL/Generator/Iterator/WSDL11.pm »
1 package SOAP::WSDL::XSD::SimpleType;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Class::Std::Fast::Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(SOAP::WSDL::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 3.004;
8  
9 1 my %length_of :ATTR(:name<length> :default<[]>);
10 1 my %minLength_of :ATTR(:name<minLength> :default<[]>);
11 1 my %maxLength_of :ATTR(:name<maxLength> :default<[]>);
12 1 my %pattern_of :ATTR(:name<pattern> :default<[]>);
13 1 my %enumeration_of :ATTR(:name<enumeration> :default<[]>);
14 1 my %whiteSpace_of :ATTR(:name<whiteSpace> :default<[]>);
15 1 my %totalDigits_of :ATTR(:name<totalDigits> :default<[]>);
16 1 my %fractionDigits_of :ATTR(:name<fractionDigits> :default<[]>);
17 1 my %minExclusive :ATTR(:name<minExclusive> :default<[]>);
18 1 my %minInclusive :ATTR(:name<minInclusive> :default<[]>);
19 1 my %maxExclusive :ATTR(:name<maxExclusive> :default<[]>);
20 1 my %maxInclusive :ATTR(:name<maxInclusive> :default<[]>);
21  
22 1 my %fixed :ATTR(:name<fixed> :default<[]>);
23  
24 1 my %annotation_of :ATTR(:name<annotation> :default<()>);
25 1 my %base_of :ATTR(:name<base> :default<()>);
26 1 my %itemType_of :ATTR(:name<itemType> :default<()>);
27  
28  
29 # TODO rename flavor to variety to be consistent with the XML Schema
30 # specs - though flavor is the cooler name..
31 # set to restriction|list|union|enumeration
32 1 my %flavor_of :ATTR(:name<flavor> :default<()>);
33  
34 # for simpleType containing atomic simple types
35 1 my %type_of :ATTR(:name<type> :default<()>);
36  
37 1 sub get_simpleType; *get_simpleType = \&get_type;
38 1 sub set_simpleType; *set_simpleType = \&set_type;
39  
40 1 sub get_variety; *get_variety = \&get_flavor;
41  
42 1 ▶sub set_restriction {
Subroutine set_restriction: called CC=3 SCAR=11.0
Pod undocumented
43 1 my $self = shift;
44 1 my @attributes = @_;
45 1 $self->set_flavor( 'restriction' );
46  
47 1 for (@attributes) {
48 2 ▶ next if (not $_->{ LocalName } eq 'base');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"LocalName"} eq "base" 1 1 2
49 1 $self->set_base( $_->{ Value } );
50 }
51 }
52  
53 1 ▶sub set_list {
Subroutine set_list: called CC=3 SCAR=11.0
Pod undocumented
54 1 my $self = shift;
55 1 my @attributes = @_;
56 1 $self->set_flavor( 'list' );
57 1 for (@attributes) {
58 2 ▶ next if (not $_->{ LocalName } eq 'itemType');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"LocalName"} eq "itemType" 1 1 2
59 1 $self->set_itemType( $_->{ Value } );
60 }
61 }
62  
63 2 ▶sub set_union {
Subroutine set_union: called CC=3 SCAR=11.0
Pod undocumented
64 2 my $self = shift;
65 2 my @attributes = @_;
66 2 $self->set_flavor( 'union' );
67 2 for (@attributes) {
68 4 ▶ next if (not $_->{ LocalName } eq 'memberTypes');
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"LocalName"} eq "memberTypes" 2 2 4
69 2 $self->set_base( [ split /\s/, $_->{ Value } ] );
70 }
71 }
72  
73 4 ▶sub serialize {
Subroutine serialize: called CC=9 SCAR=22.3
Pod undocumented
74 4 my $self = shift;
75 4 my $name = shift;
76 4 my $value = shift;
77 4 my $opt = shift;
78 4 my $ident = ident $self;
79  
80 4 ▶ $opt->{ attributes } ||= [];
Condition50%1/2
$opt->{"attributes"} ||= []
l!l
04
MC/DC0%0/1
$opt->{"attributes"} ||= []
$opt->{"attributes"}
Truth table50%1/2
A
A= $opt->{"attributes"}
Aresult
11
00
81 4 ▶ $opt->{ indent } ||= q{};
Condition50%1/2
$opt->{"indent"} ||= ""
l!l
04
MC/DC0%0/1
$opt->{"indent"} ||= ""
$opt->{"indent"}
Truth table50%1/2
A
A= $opt->{"indent"}
Aresult
11
00
82  
83 return $self->_serialize_single($name, $value , $opt)
84 if ( $flavor_of{ $ident } eq 'restriction'
85 or $flavor_of{ $ident } eq 'union'
86 4 ▶ or $flavor_of{ $ident } eq 'enumeration');
Branch: 1 branch
BranchTrueFalseTotal
if $flavor_of{$ident} eq "restriction" or $flavor_of{$ident} eq "union" or $flavor_of{$ident} eq "enumeration" 2 2 4
Condition83%5/6
$flavor_of{$ident} eq "restriction" or $flavor_of{$ident} eq "union" or $flavor_of{$ident} eq "enumeration"
l!l&&r!l&&!r
112
$flavor_of{$ident} eq "restriction" or $flavor_of{$ident} eq "union"
l!l&&r!l&&!r
013
MC/DC66%2/3
$flavor_of{$ident} eq "restriction" or $flavor_of{$ident} eq "union" or $flavor_of{$ident} eq "enumeration"
$flavor_of{$ident} eq "restriction" $flavor_of{$ident} eq "union" $flavor_of{$ident} eq "enumeration"
Truth table75%3/4
A or B or C
A= $flavor_of{$ident} eq "restriction"B= $flavor_of{$ident} eq "union"C= $flavor_of{$ident} eq "enumeration"
ABCresult
1XX1
01X1
0011
0000
87  
88 2 ▶ if ($flavor_of{ $ident } eq 'list' )
Branch: 1 branch
BranchTrueFalseTotal
if ($flavor_of{$ident} eq "list") 1 1 2
89 {
90 1 ▶ $value ||= [];
Condition50%1/2
$value ||= []
l!l
10
MC/DC0%0/1
$value ||= []
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
91 1 ▶ $value = [ $value ] if ( ref( $value) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $value ne "ARRAY" 0 1 1
92 1 return $self->_serialize_single($name, join( q{ }, @{ $value } ), $opt);
93 }
94 }
95  
96 3 ▶sub _serialize_single {
Subroutine _serialize_single: called CC=9 SCAR=33.5
97 3 my ($self, $name, $value, $opt) = @_;
98 3 my $xml = '';
99 3 ▶ $xml .= $opt->{ indent } if ($opt->{ readable }); # add indentation
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"readable"} 0 3 3
100 3 $xml .= '<' . join ' ', $name, @{ $opt->{ attributes } };
101 3 ▶ if ( $opt->{ autotype }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"autotype"}) 0 3 3
102 # reverse namespace by prefix hash
103 0 my $ns = $self->get_targetNamespace();
104  
105 # build a list of hash keys (eg '#default', 'tns') whose values match our namespace (eg 'urn:myNamespace')
106 0 (my @possible_namespace_names) = grep { $opt->{ namespace }->{$_} eq $ns } keys %{ $opt->{ namespace } };
107  
108 # put any '#default' option last
109 0 ▶ @possible_namespace_names = sort { $a eq '#default' ? 1 : $b eq '#default' ? -1 : $a cmp $b } @possible_namespace_names;
Branch: 2 branches
BranchTrueFalseTotal
$a eq '#default' ? : 0 0 0
$b eq '#default' ? : 0 0 0
110  
111 0 ▶ if( grep( $_ ne '#default', @possible_namespace_names ) > 1 or ! @possible_namespace_names ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($_ ne "#default"), @possible_namespace_names) > 1 or not @possible_namespace_names) 0 0 0
Condition0%0/3
grep(($_ ne "#default"), @possible_namespace_names) > 1 or not @possible_namespace_names
l!l&&r!l&&!r
000
MC/DC0%0/2
grep(($_ ne "#default"), @possible_namespace_names) > 1 or not @possible_namespace_names
grep(($_ ne "#default"), @possible_namespace_names) > 1 not @possible_namespace_names
Truth table0%0/3
A or not(B)
A= grep(($_ ne "#default"), @possible_namespace_names) > 1B= not @possible_namespace_names
ABresult
1X1
011
000
112 0 die "No prefix found for namespace $ns, or too many possible names: ``@possible_namespace_names''; there should be just one and maybe a '#default' entry";
113 }
114 0 my $prefix = $possible_namespace_names[0];
115 0 $xml .= ' type="' . $prefix . ':' . $self->get_name() .'"';
116 }
117  
118 # nillabel ?
119 3 ▶ return $xml .'/>' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3 3
120  
121 3 $xml .= join q{}, '>' , $value , '</' , $name , '>';
122 3 ▶ $xml .= "\n" if ($opt->{ readable });
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"readable"} 0 3 3
123 3 return $xml;
124 }
125  
126 1 1;
« blib/lib/SOAP/WSDL/Base.pm ↑ Summary blib/lib/SOAP/WSDL/Generator/Iterator/WSDL11.pm »