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=back 84 85=cut 86 87=head1 STUB FILES 88 89=head2 STUB SUBROUTINES 90 91The "class" or "package" created by stubmaker.pl is actually a sub-class of 92the core SOAP::Lite object. As a result, all methods one can call upon 93L<SOAP::Lite> one can also call upon generated stubs. 94 95For example, suppose you wanted to obtain readable output from the generated 96stub, then simply call C<readable(1)> on the stub's instance. See the example 97below. 98 99The following subroutines are unique to generated stub classes, and help the 100user control and configure the stub class. 101 102=over 103 104=item want_som(boolean) 105 106When set to 1, SOAP::Lite will return SOAP::SOM objects to the user upon 107invoking a method on a remote service. This is very helpful when you need 108to check to see if the return value is a SOAP::Fault or not. When set to 0, 109SOAP::Lite will return the return value of the method. 110 111=back 112 113=cut 114 115=head1 EXAMPLES 116 117=head2 Invoking stubmaker.pl from the command line 118 119> perl stubmaker.pl http://www.xmethods.net/sd/StockQuoteService.wsdl 120Or: 121> perl "-MStockQuoteService qw(:all)" -le "print getQuote('MSFT')" 122 123=head2 Working with stub classes 124 125Command line: 126> perl stubmaker.pl http://ws1.api.re2.yahoo.com/ws/soap-demo/full.wsdl 127 128File: echo.pl 129> use full; 130> use SOAP::Lite +trace => qw( debug ); 131> my $f = new full; 132> $f->use_prefix(0); 133> $f->readable(1); 134> $f->want_som(1); 135> $som = $f->echoViaBase64("foo"); 136 137=head1 COPYRIGHT 138 139Copyright (C) 2000-2005 Paul Kulchenko. All rights reserved. 140 141This library is free software; you can redistribute it and/or modify 142it under the same terms as Perl itself. 143