Created
February 3, 2014 01:50
-
-
Save lestrrat/8777818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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