AppConfig

 view release on metacpan or  search on metacpan

t/cgi.t  view on Meta::CPAN

}

END {
    ok(0) unless $loaded;
}

my $ok_count = 1;
sub ok {
    shift or print "not ";
    print "ok $ok_count\n";
    ++$ok_count;
}

use AppConfig qw(:argcount);
use AppConfig::CGI;
$loaded = 1;
ok(1);


#------------------------------------------------------------------------
# create new AppConfig::State and AppConfig::CGI objects
#

my $default = "<default>";
my $anon    = "<anon>";
my $user    = "Fred Smith";
my $age     = 42;
my $notarg  = "This is not an arg";

my $state = AppConfig::State->new({
        GLOBAL => { 
            DEFAULT  => $default,
            ARGCOUNT => ARGCOUNT_ONE,
        } 
    },
    'verbose' => {
        DEFAULT  => 0,
        ARGCOUNT => ARGCOUNT_NONE,
        ALIAS    => 'v',
    },
    'user' => {
        ALIAS    => 'u|name|uid',
        DEFAULT  => $anon,
    },
    'age' => {
        ALIAS    => 'a',
        VALIDATE => '\d+',
    });

my $cfgcgi = AppConfig::CGI->new($state);

#2 - #3: test the state and cfgargs got instantiated correctly
ok( defined $state   );
ok( defined $cfgcgi );

my $args = "v&u=$user&age=$age";

#4: process the args
ok( $cfgcgi->parse($args) );

#5 - #7: check variables got updated
ok( $state->verbose() == 1     );
ok( $state->user()    eq $user );
ok( $state->age()     == $age  );

$age = $age * 2;

#8 - #9: check args defaults to using $ENV{ QUERY_STRING }
$ENV{ QUERY_STRING } = "v&u=$user=$user&age=$age";
ok( $cfgcgi->parse() );
ok( $state->age() == $age );



( run in 1.984 second using v1.01-cache-2.11-cpan-39bf76dae61 )