Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I've been using Class::DBI to create a web site and it is going nicely. I now want to create a comprehensive test suite that tests the site via the web using Test::WWW::Mechanize. The problem is getting CDBI to grab new data from the database after a change has been made on the site.

The problem rests with CDBI's cache of objects in memory. This code demonstrates the problem:

# In test suite. # Check CDBI object is as expected. is $cdbi_object->name, 'Foo', "name is correct (Foo)" # Change the name through web site. $mech->get_ok('http://localhost:3000/object/change?name=Bar'); # Check that the name has changed. is $cdbi_object->name, 'Bar', "name has changed to 'Bar'"; # Test fails.

Arguably the tests should fail as there is no way for one instance of perl (test) to know that the object has changed in another (webserver). The tests can be made to work as they should by inserting something like this before the test that checks for changed values:

# Reload the object from the database. $cdbi_object->remove_from_object_index; $cdbi_object = My::Object->retrieve( $cdbi_object->id );

To get to the point is there a simpler and better way to do this. Can the cache be turned off completely? Is there a way to get a method like $cdbi_object->freshen that will do the above? Am I missing the point


In reply to Reloading CDBI objects from database elegantly by EvdB

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2018-07-16 03:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (330 votes). Check out past polls.

      Notices?