Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created February 3, 2014 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/8777818 to your computer and use it in GitHub Desktop.
Save lestrrat/8777818 to your computer and use it in GitHub Desktop.
use strict;
use feature 'say';
use CGI;
main() unless caller();
sub main {
local $ENV{REQUEST_METHOD} = "GET";
qstring_is_not_empty();
qstring_is_empty();
qstring_is_empty_string();
}
sub qstring_is_empty {
say "qstring is EMPTY";
local $ENV{QUERY_STRING};
run()
}
sub qstring_is_empty_string {
say "qstring is foo=''";
local $ENV{QUERY_STRING} = "foo=";
run()
}
sub qstring_is_not_empty {
say "qstring is foo='bar'";
local $ENV{QUERY_STRING} = "foo=bar";
run()
}
sub run {
CGI::initialize_globals(); # enable re-parsing
my $q = CGI->new;
if ($q->param('foo')) {
say "foo evaluates to TRUE (@{[ $q->param('foo') ]})";
} else {
say "foo evaluates to FALSE";
}
}
__END__
qstring is foo='bar'
foo evaluates to TRUE (bar)
qstring is EMPTY
foo evaluates to FALSE
qstring is foo=''
foo evaluates to FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment