Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

@INC problem with SOAP::Lite

by john_oshea (Priest)
on Jan 09, 2007 at 19:16 UTC ( #593770=perlquestion: print w/ replies, xml ) Need Help??
john_oshea has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm hoping one of you kind souls can point out where, exactly, I'm being a bit dim, as the problem I have, well it just has to be something really simple, but I just can't see it...

I have a SOAP server:

#!/usr/local/bin/perl use strict; use warnings; use SOAP::Transport::HTTP; $|++; my $daemon = SOAP::Transport::HTTP::Daemon -> new( LocalAddr => 'localhost', LocalPort => 8080, R +euse => 1 ) -> dispatch_to('/Users/johno/Code/DCI/Wordbank-DCI-Ser +ver/lib'); print STDERR "SOAP server startup at ", $daemon->url, "\nServer INC:", + join(' ', @INC), "\n"; $daemon->handle;

...which is called from the following client:

#!/usr/local/bin/perl use strict; use warnings; #use SOAP::Lite +trace => ['all', '-transport']; use SOAP::Lite; my $soap = SOAP::Lite->new( uri => 'http://DCI/Wordbank::DCI::Server', proxy => 'http://10.1.1.50:8080/Server', on_fault => sub { my($soap, $res) = @_; die ref $res ? $res->faultdetail : $soap->tran +sport->status, "\n"; }); print $soap->hello()->result, "\n";

...and the server calls the following module:

package Wordbank::DCI::Server; use vars qw(@ISA); @ISA = qw(SOAP::Server::Parameters); use strict; use warnings; use Carp; sub hello { my $self = shift; print STDERR 'Module INC: ', join(' ', @INC), "\n"; return "Hello, world\n"; } 1;

All of which works perfectly, calls the hello method, and prints out quite a reasonable @INC value. Until I add in use Data::Dumper immediately after the use Carp line in the module, at which point I get the following (excerpted) error when I turn tracing on:

<soap:Fault><faultcode>soap:Client</faultcode><faultstring>Failed to a +ccess class (Wordbank::DCI::Server): Can't locate Data/Dumper.pm in @ +INC (@INC contains: /Users/johno/Code/DCI/Wordbank-DCI-Server/lib) at + /Users/johno/Code/DCI/Wordbank-DCI-Server/lib/Wordbank/DCI/Server.pm + line 9. BEGIN failed--compilation aborted at /Users/johno/Code/DCI/Wordbank-DC +I-Server/lib/Wordbank/DCI/Server.pm line 9. Compilation failed in require at (eval 98) line 3. </faultstring><faultactor>http://localhost:8080/</faultactor></soap:Fa +ult>

...i.e. it appears that @INC is getting zapped to only contain the current module's directory. I can't even use lib... something to get around it as it can't use 'lib'.

Can anyone reproduce this? Am I being a complete klutz? Hay-ulp...

(OSX 10.4.8, Perl 5.8.8, SOAP::Lite 0.69)


Update:

Thanks to both almut and Ultra for both speedy and accurate replies.

Comment on @INC problem with SOAP::Lite
Select or Download Code
Re: @INC problem with SOAP::Lite
by almut (Canon) on Jan 09, 2007 at 22:28 UTC

    Not really sure, but my guess would be that it has to do with the following piece of code (SOAP/Lite.pm, line 2500):

    unless (defined(%{"${class}::"}) || exists($INC{join '/', split /::/ +, $class.'.pm'})) { # allow all for static and only specified path for dynamic binding +s local @INC = (($static ? @INC : ()), grep {!ref && m![/\\.]!} $sel +f->dispatch_to); eval 'local $^W; ' . "require $class"; die "Failed to access class ($class): $@" if $@; $self->dispatched($class) unless $static; }

    in particular the local @INC = ...

    A cursory glance at the surrounding lines makes me wonder what would happen if you "preload" Data::Dumper in the server (the idea being that it then already is loaded when the require is executed with the restricted @INC...).   Just an idea - could be entirely wrong, though.

Re: @INC problem with SOAP::Lite
by Ultra (Hermit) on Jan 09, 2007 at 22:37 UTC

    I'm getting the same with SOAP::Lite 0.69 on SuSE 10.1, and not just with Data::Dumper but with Anything::

    maybe it's a bug, and you should report it :)

    as a workaround (ugly one) that works for me, you can move Wordbank directory from lib/ to the daemon root, and replace

    -> dispatch_to('/Users/johno/Code/DCI/Wordbank-DCI-Server/lib');
    from the daemon code with:
    -> dispatch_to("Wordbank::DCI::Server");

    Dodge This!
Re: @INC problem with SOAP::Lite
by john_oshea (Priest) on Jan 10, 2007 at 10:28 UTC

    Update 2

    It appears that changing the dispatch_to parameters to the following allows for Data::Dumper use:

    -> dispatch_to('/Users/johno/Code/DCI/Wordbank-DCI-Server/lib', '/usr/local/lib/perl5/5.8.8/darwin-2level/');

    This makes me feel somewhat happier than hacking at the SOAP::Lite code, which, quite frankly, I don't understand. This seems not to introduce any gaping security holes(*), but I'd appreciate it if anyone who feels faint / nauseous at this would let me know what I'm letting myself in for ;-)

    (*) I can't, for instance, call getcwd from Cwd.pm, which lives in the second path parameter.

      This makes me feel queasy. I think the problem results from SOAP::Lite lazy-loading your module after it has modified @INC:

      unless (defined(%{"${class}::"}) || exists($INC{join '/', split /::/ +, $class.'.pm'})) { # allow all for static and only specified path for dynamic binding +s local @INC = (($static ? @INC : ()), grep {!ref && m![/\\.]!} $sel +f->dispatch_to); eval 'local $^W; ' . "require $class"; die "Failed to access class ($class): $@" if $@; $self->dispatched($class) unless $static; }
      I think you should be able to fix the problem by force-loading your class(es) instead of waiting until SOAP::Lite decides to load them:

      use Wordbank::DCI::Server; use Wordbank::DCI::Another::Package; # and so on

        Hmmm. Yes. Now that I've done some more reading in the meantime, I get it. I think.. ;-)

        For anyone else who may get stuck on this, Corion's suggestion is the 'static linking' option mentioned in the security section of the SOAP::Lite documentation.

        Thanks for the help - much appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://593770]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-07-05 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls