1#!/usr/bin/env perl 2#!d:\perl\bin\perl.exe 3# 4# Filename: stubmaker.pl 5# Authors: Byrne Reese <byrne at majordojo dot com> 6# Paul Kulchenko 7# 8# Copyright (C) 2005 Byrne Reese 9# 10# Usage: 11# stubmaker.pl -[vd] <WSDL URL> 12################################################### 13 14use SOAP::Lite; 15use Getopt::Long; 16 17my $VERBOSE = 0; 18my $DIRECTORY = "."; 19GetOptions( 20 'd=s' => \$DIRECTORY, 21 'v' => \$VERBOSE, 22 help => sub { HELP_MESSAGE(); }, 23 version => sub { VERSION_MESSAGE(); exit(0); }, 24 ) or HELP_MESSAGE(); 25 26HELP_MESSAGE() unless $ARGV[0]; 27 28my $WSDL_URL = shift; 29 30print "Writing stub files...\n" if $VERBOSE; 31my %services = %{SOAP::Schema->schema_url($WSDL_URL) 32 ->cache_ttl(1) 33 ->cache_dir($DIRECTORY) 34 ->parse() 35 ->load 36 ->services}; 37Carp::croak "More than one service in service description. Service and port names have to be specified\n" 38 if keys %services > 1; 39 40sub VERSION_MESSAGE { 41 print "$0 $SOAP::Lite::VERSION (C) 2005 Byrne Reese.\n"; 42} 43 44sub HELP_MESSAGE { 45 VERSION_MESSAGE(); 46 print <<EOT; 47usage: $0 -[options] <WSDL URL> 48options: 49 -v Verbose Outputbe quiet 50 -d <dirname> Output directory 51EOT 52exit 0; 53} 54 55__END__ 56 57=pod 58 59=head1 NAME 60 61stubmaker.pl - Generates client stubs from a WSDL file. 62 63=head1 OPTIONS 64 65=over 66 67=item -d <dirname> 68 69Specifies the directory you wish to output the files to. The directory must already exist. 70 71=item -v 72 73Turns on "verbose" output during the code stub generation process. To be honest, there is not much the program outputs, but if you must see something output to the console, then this fits the bill. 74 75=item --help 76 77Outputs a short help message. 78 79=item --version 80 81Outputs the current version of stubmaker.pl. 82 83=cut 84 85=head1 STUB FILES 86 87=head2 STUB SUBROUTINES 88 89The "class" or "package" created by stubmaker.pl is actually a sub-class of 90the core SOAP::Lite object. As a result, all methods one can call upon 91L<SOAP::Lite> one can also call upon generated stubs. 92 93For example, suppose you wanted to obtain readable output from the generated 94stub, then simply call C<readable(1)> on the stub's instance. See the example 95below. 96 97The following subroutines are unique to generated stub classes, and help the 98user control and configure the stub class. 99 100=over 101 102=item want_som(boolean) 103 104When set to 1, SOAP::Lite will return SOAP::SOM objects to the user upon 105invoking a method on a remote service. This is very helpful when you need 106to check to see if the return value is a SOAP::Fault or not. When set to 0, 107SOAP::Lite will return the return value of the method. 108 109=cut 110 111=head1 EXAMPLES 112 113=head2 Invoking stubmaker.pl from the command line 114 115> perl stubmaker.pl http://www.xmethods.net/sd/StockQuoteService.wsdl 116Or: 117> perl "-MStockQuoteService qw(:all)" -le "print getQuote('MSFT')" 118 119=head2 Working with stub classes 120 121Command line: 122> perl stubmaker.pl http://ws1.api.re2.yahoo.com/ws/soap-demo/full.wsdl 123 124File: echo.pl 125> use full; 126> use SOAP::Lite +trace => qw( debug ); 127> my $f = new full; 128> $f->use_prefix(0); 129> $f->readable(1); 130> $f->want_som(1); 131> $som = $f->echoViaBase64("foo"); 132 133=head1 COPYRIGHT 134 135Copyright (C) 2000-2005 Paul Kulchenko. All rights reserved. 136 137This library is free software; you can redistribute it and/or modify 138it under the same terms as Perl itself. 139