Leveraging synergy in this championship year
Michael Davies
Local
News
Software
Utility
Powered by PyBlosxom
Copyright © 2003, 2004, 2005, 2006, 2007, 2008 Michael Davies, |
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. |
|
This web page is optimised
for standards. |