Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday October 22, 2002
03:56 PM

Problem Solved

[ #8532 ]

I finally nailed the problem from today's earlier post. The comments I received suggested that the table was locking, but how would that happen if I was committing things properly? Well, just in case, I had better write some tests.

$result = $mod->update_admin_message( $update );
ok( $result, 'update_admin_message() should succeed when passed valid data' );

my $new_data = $db->get_admin_message;
is( $new_data->{message},'foobar', '... and should set the message correctly');

Sure enough, the test suite hung when I tried to get the administrative message after setting it. Here's the code that sets it:

sub update_admin_message {
  my ( $self, $data ) = @_;
  my ( $fields, $values ) = $self->_format_update_data( $data );
  my $sql = "UPDATE adminMessage SET $fields";
  $self->_update_database( $sql, $values );
  return $self->_success_or_failure;

And the _success_or_failure() method:

sub _success_or_failure {
  my ( $self, $commit ) = @_;
  unless ( $self->{ _error } ) {
    $self->{ _dbh }->commit if $commit;
    return 1;
  } else {
    $self->{ _dbh }->rollback;

Apparently, I forget to pass a true value for the 'commit' parameter. I need to go through now and have all calls to this function explicitly pass a true or false value, rather than defaulting to false via undef. That should prevent this happening again, I hope (though I still don't understand all of the mysterious side-effects that we were experiencing. I fear that I am a bear of little brain).

And for the curious, the beginning of my tests for the mods to the _success_or_failure method.

my $warn;
$SIG{__WARN__} = sub { $warn = join '', @_ };
can_ok( MODULE, '_success_or_failure' );
$data = $mod->_success_or_failure;
ok( ! $data, '... and calling it without and argument should fail' );
ok( $warn, '... and should warn the programmer' );
like( $warn, qr/\QArgument to _success_or_failure() must be defined\E/,
  '... with an appropriate error message' );

  no warnings 'once';
  is( $George::Bush, $Big::Idiot, '... but no political statements, please' );

If you can't have a little fun at work ... :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.