Mark Knoop <> wrote:
> Hi
>
> It's Mark's class workshop today :)
>
> I want to wrap up a SOAP service handle (returned from a call to a
> wsdl
> file) in a class (ultimately so I can make it a singleton and only
> call it once but we'll leave that for the purposes of this example).
>
> So if I have something like this (calling a random public SOAP
> service)
>
> use strict;
> use warnings;
> use SOAP::Lite;
> use Data::Dumper;
> my $service =
> SOAP::Lite->service('http://ws.cisa.ca/WehireWS/JobsWs.asmx?WSDL');
> my $result = $service->GetAll;
> print Dumper($result);
>
> It works fine and I get
>
> $VAR1 = {
> 'JobDetail' => {
> 'PostingDate' => '1/30/2006',
> 'Location' => 'British Columbia',
> 'Url' =>
> 'http://www.wehire.ca/view.php?job_id=1408',
> 'Category' => 'Construction',
> 'Company' => 'XS West Construction Group',
> 'Title' => 'Equipment Operator'
> }
> };
>
> However if I try to abstract it into my own class eg
>
> #############
>
> package Soap;
> use strict;
> use warnings;
> use SOAP::Lite;
>
> sub new {
>
> my $class = shift;
>
> my $self =
> SOAP::Lite->service('http://ws.cisa.ca/WehireWS/JobsWs.asmx?WSDL');
>
> bless ($self, $class);
>
> return $self;
>
> }
>
> 1;
>
> ################
>
> use strict;
> use warnings;
> use Soap;
> use Data::Dumper;
> my $service = Soap->new;
> my $result = $service->GetAll;
> print Dumper($result);
>
> #################
>
> I get
>
> Can't locate object method "GetAll" via package "Soap" at soap2.pl
> line 6.
>
> I don't expect anyone to read the SOAP::Lite documentation for me but
> I am wondering whether there is anything fundamentally flawed in my
> approach?
Yes there is. Basically, you are re-blessing the object returned by
SOAP::Lite::service into your package namespace, and I don't see a
subroutine named GetAll defined there. You should store the returned
object in a container (hash or array), which you bless into your package
namespace. But that only fixes the first part of your problem, you still
don't have a subroutine named GetAll. You can delegate subroutine calls
to your class using the AUTOLOAD feature, see at least 'perldoc perlobj'
and 'perldoc perltoot' for help with that.
However, do you really want to go to all that trouble when all you seem
to be doing is hiding the service URL and only calling
SOAP::Lite::service once? The following would seem to be a simpler way
for Soap.pm to accomplish that:
----------------------------------
use strict;
use warnings;
package Soap;
use SOAP::Lite;
our $service;
our $url = 'http://ws.cisa.ca/WehireWS/JobsWs.asmx?WSDL';
sub service {
$service = SOAP::Lite->service($url)
unless defined $service;
return $service;
}
1;
----------------------------------
Then all you need in Soap.pl is:
----------------------------------
use strict;
use warnings;
use Soap;
use Data::Dumper;
my $result = Soap::service->GetAll;
print Dumper($result);
----------------------------------
HTH
--
Brian Raven
=========================================
Atos Euronext Market Solutions Disclaimer
=========================================
The information contained in this e-mail is confidential and solely for the
intended addressee(s). Unauthorised reproduction, disclosure, modification,
and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message do not
necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with
registration no. 3962327. Registered office address at 25 Bank Street London
E14 5NQ United Kingdom.
Atos Euronext Market Solutions SAS - Registered in France with registration no.
425 100 294. Registered office address at 6/8 Boulevard Haussmann 75009 Paris
France.
L'information contenue dans cet e-mail est confidentielle et uniquement
destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee.
Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail
vous parvient par erreur, nous vous prions de bien vouloir prevenir
l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre
systeme. Le contenu de ce message electronique ne represente pas necessairement
la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée au
Royaume Uni sous le numéro 3962327, dont le siège social se situe 25 Bank
Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, société par actions simplifiée, enregistré
au registre dui commerce et des sociétés sous le numéro 425 100 294 RCS Paris
et dont le siège social se situe 6/8 Boulevard Haussmann 75009 Paris France.
=========================================
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs