in reply to SOAP::Lite dispatch routine
Here an example that uses mod_soap, if you are not using mod_soap then i recommend you take a look at it. First, my Apache http.conf directive to make mod_soap autodispatch:
Next, the dispatch object code - Factory.pm:<Location /mod_soap> SetHandler perl-script PerlHandler Apache::SOAP PerlSetVar dispatch_to "/usr/local/apache/lib/soap" </Location>
And finally, the client:package Factory; use strict; use DBI; my $dbh = DBI->connect( qw(DBI:vendor:database:host user pass), { RaiseError => 1} ); sub instantiate { my ($self,$package,$id) = @_; my $sth = $dbh->selectall_arrayref(' select title,artist,year from songs where id = ? ',undef,$id)->[0]; my $obj = eval { $package->new($id,@$sth) }; return $@ ? undef : $obj; } package My::User; use strict; sub new { my ($class,$id,$title,$artist,$year) = @_; my $self = { id => $id, title => $title, artist => $artist, year => $year, }; return bless $self,$class; } # this will be discussed later ... sub foo { 'foo' } 1;
When run, the following is printing:use strict; use SOAP::Lite; use Data::Dumper; my $soap = SOAP::Lite ->uri("http://127.0.0.1/Factory") ->proxy("http://127.0.0.1/mod_soap"); my $object = $soap->instantiate('My::User','5')->result; print Dumper $object;
The idea is to just return data - not code. SOAP is insecure enough already. As a matter of fact, if you try to return a DBI handle, you get back a nice fat undefined value.$VAR1 = bless( { 'artist' => 'Van Halen', 'title' => 'You Really Got Me', 'id' => '5', 'year' => '1978' }, 'My::User' );
SOAP really helped me to understand more about Perl OO, especially the fact that an object DOES NOT carry its methods with it - instead, the interpreter knows which package the object is blessed and is able to find the method in question because you use'ed or require'ed the package.
To see what i mean, call the foo method from package My::User inside your SOAP client ...
Pass data - not code, that's what COM and DCOM do (pass code and/or data). Hope this helps, and feel free to ask more. ;)my $object = $soap->instantiate('My::User','5')->result; print $object->foo(); # yields: Can't locate object method "foo" via package "My::User" at ./instantia +te.pl line 23.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR F--F--F--F--F--F--F--F-- (the triplet paradiddle)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (jeffa) Re: SOAP::Lite dispatch routine
by gildir (Pilgrim) on Jan 04, 2002 at 13:51 UTC | |
by lachoy (Parson) on Jan 05, 2002 at 01:40 UTC | |
by jeffa (Bishop) on Jan 04, 2002 at 22:03 UTC |