mrd

Leveraging synergy in this championship year
Michael Davies' Blog

Michael Davies
michael [at] the-davies.net
GPG Id: 0x0AA9D6FC
RSS feed.

No Software Patents


< June 2008 >
SuMoTuWeThFrSa
1 2 3 4 5 6 7
8 91011121314
15161718192021
22232425262728
2930     


Local
  chicago
  docs
  photo blog
  planet
  site-index
  software

News
  lwn
  /.
  linuxtoday
  kernel traffic
  theregister
  abc
  bom
  

Software
  sourceforge
  savanna
  tigris
  ibiblio
  freshmeat
  tridge's junkcode
  here
  

Utility
  absolute truth
  google
  wikipedia
  convert currency
  convert time
  convert tongues
  convert temperature
  convert temperature (2)
  linux man pages
  thesaurus
  dictionary
  acronyms
  street maps downunder
  street maps usa
  toilets downunder
  




My Amazon Wishlist


www.flickr.com

Powered by PyBlosxom

Copyright © 2003, 2004, 2005, 2006, 2007, 2008 Michael Davies,
All Rights Reserved.
All opinions are mine only.

Perl's CGI is broken

  use strict;
  use warnings;
  use CGI;
  use Test::More qw( no_plan );

  my $cgi = new CGI;

  $cgi->param('foobar', 6);
  ok( $cgi->param("foobar") eq '6', "6 is a magical number" );

  $cgi->param('foobar', 4);
  ok( $cgi->param("foobar") eq '4', "And 4 is a favourite" );

  my %hash = ( "random_key" => '13' );

  $cgi->param('foobar', $hash{'randomKey'} );
  ok( $cgi->param("foobar") eq '13',
      "but a simple typo in a hash key shouldn't be so hard to find" ); # Fail
  ok( $cgi->param("foobar") eq '4',
      "so it hasn't changed but there's no complaint" );

  $cgi->param('foobar', $hash{'random_key'} );
  ok( $cgi->param("foobar") eq '13', "The key is to get the key right :-)" );

What sort of deranged API silently ignores calling a setter with an undef? Surely a warning or exception could have been thrown? Or perhaps setting the value to undef, or to the empty string, or even "You messed up, Idiot!". But quietly swallowing the error and leaving the value unchanged is really bad form.

This sort of thing doesn't rate well on Rusty's API design advice: How Do I Make This Hard to Misuse?. Grrr.

| 20 Jun 2008 | #