Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

SOAP::Lite, objects and global variables

by Pickwick (Beadle)
on May 26, 2010 at 08:12 UTC ( [id://841687]=perlquestion: print w/replies, xml ) Need Help??

Pickwick has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I really need some help understanding the basics of SOAP::Lite and visibility of variables in perl in my environment. First, please let me explain my situation: We have a web application with a frontend and a backend programmed in perl. The frontend uses SOAP::Lite to communicate with the backend, which is provided as one package which directly get SOAP-calls dispatched to. The client in the frontend does not instanciate the package using new or stuff like that, it just calls methods which SOAP::Lite will route to the package. All application logic is implemented directly in that package.

The server looks something like the following:

SOAP::Transport::HTTP::CGI ->dispatch_to('xyz') ->options({...}) ->handle();

Because the target package does provide a new-method I always thought this one gets called before calling the method requested automatically by SOAP::Lite, but this doesn't seem to be the case. SOAP::Lite seems to recognize if a blessed object reference is provided by the calling client or not and just calls the method on class level.

My problem now is that in one of the methods provided as a web service I have to make a recursive call to itself, while saving the fact that it called itself recursively. I have to save that because the function must not call itself again or it will end in an infinite loop. As I see it I have different options to achieve this:

  1. I could provide a new parameter as just a boolean flag to the function which indicates the recursive call. Because this function is directly accessible over SOAP this would mean an interface change of this function which has to be documented and proposed to our partners using that function. I really don't like that idea.
  2. I could use some sort of global value which indicates the recursive call. But because I have no instance I don't know how a global variable in the scope of the class, declared by either use vars or my, will work with different requests at a time. Right now we don't use mod_perl for the backend, so I think using a class level variable is save because each request starts a new perl interpreter. Switching to mod_perl all class variables would break, right?
  3. My long term solution would be to create a new package as endpoint for the SOAP::Lite-dispatcher which instanciates the now used package and calls the methods on that blessed object reference. This will give us the chance to create database connections etc. in the constructor of the package while not needing the client to call new, as it seems to be necessary in the SOAP::Lite-examples I saw.

Do you think that going the ways 2 and 3 is an acceptable solution?

Thanks for any help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-03-19 06:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found