File Coverage

lib/Google/Ads/SOAP/Generator/Generator.pm
Criterion Covered Total %
statement 27 51 52.9
branch 0 8 0.0
condition n/a
subroutine 9 14 64.2
pod 2 4 50.0
total 38 77 49.3


line stmt bran cond sub pod time code
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 1     1   2181 use strict;
  1         2  
  1         30  
21 1     1   5 use warnings;
  1         2  
  1         28  
22 1     1   4 use base qw(SOAP::WSDL::Generator::Template::XSD);
  1         2  
  1         357  
23              
24 1     1   36964 use Google::Ads::SOAP::Generator::TypemapVisitor;
  1         4  
  1         70  
25              
26 1     1   9 use Class::Std::Fast::Storable;
  1         3  
  1         9  
27 1     1   145 use Cwd 'abs_path';
  1         3  
  1         61  
28 1     1   5 use File::Basename;
  1         3  
  1         53  
29 1     1   6 use File::Spec;
  1         2  
  1         295  
30              
31             sub BUILD {
32 0     0 0   my ($self, $ident, $arg_ref) = @_;
33              
34 0           $self->set_INCLUDE_PATH(
35             $self->_get_local_include_path() . q{:} . $self->get_INCLUDE_PATH());
36             }
37              
38             sub _get_local_include_path {
39              
40 0     0     my $template_path =
41             File::Spec->catdir(File::Spec->rel2abs(dirname(__FILE__)), "Template");
42 0           return abs_path($template_path);
43             }
44              
45             sub generate_filename {
46 0     0 0   my ($self, $name) = @_;
47              
48 0           $name =~ s{ \. }{::}xmsg;
49 0           $name =~ s{ \- }{_}xmsg;
50 0           $name =~ s{ :: }{/}xmsg;
51 0           return "$name.pm";
52             }
53              
54             sub visit_XSD_ComplexType {
55 0     0 1   my ($self, $type) = @_;
56              
57             my $output =
58             defined $SOAP::WSDL::Generator::Template::XSD::output_of{ident $self}
59 0 0         ? $SOAP::WSDL::Generator::Template::XSD::output_of{ident $self}
60             : $self->generate_filename(
61             $self->get_name_resolver()->create_xsd_name($type));
62 0 0         warn "Creating complexType class $output \n" if not $self->get_silent();
63 0           $self->_process('complexType.tt', {complexType => $type, NO_POD => 1},
64             $output);
65             }
66              
67             sub generate_typemap {
68 0     0 1   my ($self, $arg_ref) = @_;
69 0           my $visitor = 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 1     1   7 use SOAP::WSDL::Generator::Iterator::WSDL11;
  1         1  
  1         126  
86 0           my $iterator = SOAP::WSDL::Generator::Iterator::WSDL11->new(
87             {definitions => $self->get_definitions});
88              
89 0           for my $service (@{$self->get_definitions->get_service}) {
  0            
90 0           $iterator->init({node => $service});
91 0           while (my $node = $iterator->get_next()) {
92 0           $node->_accept($visitor);
93             }
94              
95             my $output =
96             $arg_ref->{output}
97             ? $arg_ref->{output}
98 0 0         : $self->generate_filename(
99             $self->get_name_resolver()->create_typemap_name($service));
100 0 0         print "Creating typemap class $output\n" if not $self->get_silent();
101 0           $self->_process(
102             'Typemap.tt',
103             {
104             service => $service,
105             typemap => $visitor->get_typemap(),
106             NO_POD => 1,
107             },
108             $output
109             );
110             }
111             }
112              
113             return 1;