
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
396
|
Appendix D: SOAP Example Code
The Third HTTP::Daemon Server
The final version of the HTTP::Daemon–based server differs from the previous only in
that it uses the revised SOAP interface presented in the previous section.
#
# This replaces BooksBy{Author,Title} with a single
# interface that uses the name given to the input parameter
# to choose the type of search to execute.
#
sub FindBooks {
my ($class, $arg, $env) = @_;
#
# Using the SOAP envelope of the request, get the
# SOAP::Data object that wraps the value $arg was
# assigned.
#
my $argname = $env->match(SOAP::SOM::paramsin)->dataof;
my $hook = ($argname->name eq 'author') ?
\&SoapExBook::get_books_by_author :
\&SoapExBook::get_books_by_title;
#
# As with the originals, this can be a static method,
# so the test to use a new book-database handle versus
# the self-stored one is still present.
#
my $bookdb = ref($class) ? $class->{_catalog} :
SoapExBook::connect();
return 'Unable to connect to catalog' unless $bookdb;
my @books = $hook->($bookdb, $arg);
\@books;
}
sub CanPurchase {
my $self = shift->new;
die SOAP::Fault->faultcode('Server.RequestError')
->faultstring('Could not get object')
unless $self;
SOAP::Data->name('return', $self->SUPER::CanPurchase)
->type('xsd:boolean');
}
Example D-10. WishListCustomer::SOAP2.pm (continued)
Get Programming Web Services with Perl now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.