blib/lib/Google/Ads/SOAP/Generator/Generator.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 76 CC 5 SCAR 17.5
CC
5
Cov
0%
visit_XSD_ComplexType
12.0
generate_typemap
12.0
BUILD
2.0
CRAP 5.8
1 # Copyright 2012, Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # Custom class generator based on SOAP::WSDL::Generator::Template::XSD, with
16 # some overriden methods via inheritance.
17  
18 package Google::Ads::SOAP::Generator::Generator;
19  
20 use base qw(SOAP::WSDL::Generator::Template::XSD);
21  
22 use Google::Ads::SOAP::Generator::TypemapVisitor;
23  
24 use Class::Std::Fast::Storable;
25 use Cwd 'abs_path';
26 use File::Basename;
27 use File::Spec;
28  
29 sub BUILD {
30 my ($self, $ident, $arg_ref) = @_;
31  
32 $self->set_INCLUDE_PATH($self->_get_local_include_path() .
33 q{:} .
34 $self->get_INCLUDE_PATH());
35 }
36  
37 sub _get_local_include_path {
38  
39 my $template_path = File::Spec->catdir(File::Spec->rel2abs(dirname(__FILE__)),
40 "Template");
41 return abs_path($template_path);
42 }
43  
44 sub generate_filename {
45 my ($self, $name) = @_;
46  
47 $name =~ s{ \. }{::}xmsg;
48 $name =~ s{ \- }{_}xmsg;
49 $name =~ s{ :: }{/}xmsg;
50 return "$name.pm";
51 }
52  
53 sub visit_XSD_ComplexType {
54 my ($self, $type) = @_;
55  
56 my $output = defined $output_of{ident $self}
57 ? $output_of{ident $self}
58 : $self->generate_filename(
59 $self->get_name_resolver()->create_xsd_name($type));
60 warn "Creating complexType class $output \n" if not $self->get_silent();
61 $self->_process('complexType.tt',
62 {complexType => $type, NO_POD => 1},
63 $output);
64 }
65  
66 sub generate_typemap{
67 my ($self, $arg_ref) = @_;
68 my $visitor =
69 Google::Ads::SOAP::Generator::TypemapVisitor->new({
70 type_prefix => $self->get_type_prefix(),
71 element_prefix => $self->get_element_prefix(),
72 definitions => $self->get_definitions(),
73 typemap => {
74 'Fault' => 'SOAP::WSDL::SOAP::Typelib::Fault11',
75 'Fault/faultcode' => 'SOAP::WSDL::XSD::Typelib::Builtin::anyURI',
76 'Fault/faultactor' => 'SOAP::WSDL::XSD::Typelib::Builtin::token',
77 'Fault/faultstring' => 'SOAP::WSDL::XSD::Typelib::Builtin::string',
78 # PATCH Map our own FaultDetail object.
79 'Fault/detail' => 'Google::Ads::AdWords::FaultDetail',
80 # END OF PATCH.
81 },
82 resolver => $self->get_name_resolver(),
83 });
84  
85 use SOAP::WSDL::Generator::Iterator::WSDL11;
86 my $iterator = SOAP::WSDL::Generator::Iterator::WSDL11->new({
87 definitions => $self->get_definitions
88 });
89  
90 for my $service (@{$self->get_definitions->get_service}) {
91 $iterator->init({node => $service});
92 while (my $node = $iterator->get_next()) {
93 $node->_accept($visitor);
94 }
95  
96 my $output = $arg_ref->{output} ? $arg_ref->{output} :
97 $self->generate_filename(
98 $self->get_name_resolver()->create_typemap_name($service));
99 print "Creating typemap class $output\n" if not $self->get_silent();
100 $self->_process('Typemap.tt', {
101 service => $service,
102 typemap => $visitor->get_typemap(),
103 NO_POD => 1,
104 }, $output);
105 }
106 }
107  
108 return 1;