I have a question concerning SOAP::Lite initialization.

I have a self-written module where the constructor accepts two parameters for the username & password and then sets a couple of variables at module scope:

my ($_username, $_password); sub new { my ($username, $password) = @_; $_username = $username; $_password = $password; my $self = {}; # ... bless $self; }

These two module variables are then used in the overloading of SOAP::Transport::HTTP::Client which is used in authentication:

sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $_username => $_password; }

The reason for pushing this into the module is because it being used in a Test::More script & the SOAP's complexities are to be hidden in the module.

Typically, a new module instance is used for running a battery of tests. Execution is made of a number of tests which all authenticate fine using one module instance in one subroutine is followed by creating a new module instance using bad credentials before executing another series of tests which should all intentionally fail in yet a different subroutine.

At least, this is what I intended. I assumed that placing different module instances each in their own subroutines would take care of any lingering scoping issues. I thought I could reset authentication upon the creation of each new module instance.

What I am seeing in practice is if an instance of the module is created using a correct username/password pair, all tests associated with that instance succeed as expected. What is unexpected is if I then create a new instance of the module with a bad username/password pair, all associated tests still pass because authentication was successful.

If I then go back to the initial set of tests (originally intended to pass...), & set the username/password incorrectly, those tests all fail as expected. Creation of another module instance with bad credentials causes all subsequent tests to fail as is expected.

Am I correct to assume that the username/password is getting cached? If so, is there a way I can reinitialize SOAP::Lite such that I can use my module as intended toggling authentication as intended? Any suggestions would be greatly appreciated.

Thanks!


In reply to SOAP initialization? by Anonymous Monk

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.