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.


In reply to SOAP::Lite, objects and global variables by Pickwick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.