« blib/lib/Google/Ads/AdWords/v201809/ConstantDataService/ConstantDataServiceInterfacePort.pm
↑ Summary
blib/lib/Google/Ads/AdWords/FaultDetail.pm »
| 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 strict; | ||
| 21 | use warnings; | ||
| 22 | use base qw(SOAP::WSDL::Generator::Template::XSD); | ||
| 23 | |||
| 24 | use Google::Ads::SOAP::Generator::TypemapVisitor; | ||
| 25 | |||
| 26 | use Class::Std::Fast::Storable; | ||
| 27 | use Cwd 'abs_path'; | ||
| 28 | use File::Basename; | ||
| 29 | use File::Spec; | ||
| 30 | |||
| 31 | sub BUILD { | ||
| 32 | my ($self, $ident, $arg_ref) = @_; | ||
| 33 | |||
| 34 | $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 | my $template_path = | ||
| 41 | File::Spec->catdir(File::Spec->rel2abs(dirname(__FILE__)), "Template"); | ||
| 42 | return abs_path($template_path); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub generate_filename { | ||
| 46 | my ($self, $name) = @_; | ||
| 47 | |||
| 48 | $name =~ s{ \. }{::}xmsg; | ||
| 49 | $name =~ s{ \- }{_}xmsg; | ||
| 50 | $name =~ s{ :: }{/}xmsg; | ||
| 51 | return "$name.pm"; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub visit_XSD_ComplexType { | ||
| 55 | my ($self, $type) = @_; | ||
| 56 | |||
| 57 | my $output = | ||
| 58 | defined $SOAP::WSDL::Generator::Template::XSD::output_of{ident $self} | ||
| 59 | ? $SOAP::WSDL::Generator::Template::XSD::output_of{ident $self} | ||
| 60 | : $self->generate_filename( | ||
| 61 | $self->get_name_resolver()->create_xsd_name($type)); | ||
| 62 | warn "Creating complexType class $output \n" if not $self->get_silent(); | ||
| 63 | $self->_process('complexType.tt', {complexType => $type, NO_POD => 1}, | ||
| 64 | $output); | ||
| 65 | } | ||
| 66 | |||
| 67 | sub generate_typemap { | ||
| 68 | my ($self, $arg_ref) = @_; | ||
| 69 | 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 | use SOAP::WSDL::Generator::Iterator::WSDL11; | ||
| 86 | my $iterator = SOAP::WSDL::Generator::Iterator::WSDL11->new( | ||
| 87 | {definitions => $self->get_definitions}); | ||
| 88 | |||
| 89 | for my $service (@{$self->get_definitions->get_service}) { | ||
| 90 | $iterator->init({node => $service}); | ||
| 91 | while (my $node = $iterator->get_next()) { | ||
| 92 | $node->_accept($visitor); | ||
| 93 | } | ||
| 94 | |||
| 95 | my $output = | ||
| 96 | $arg_ref->{output} | ||
| 97 | ? $arg_ref->{output} | ||
| 98 | : $self->generate_filename( | ||
| 99 | $self->get_name_resolver()->create_typemap_name($service)); | ||
| 100 | print "Creating typemap class $output\n" if not $self->get_silent(); | ||
| 101 | $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; |