Acme::PETEK::Testkit::modperl1 - mod_perl 1 handler for Tester's Toolkit


Acme-PETEK-Testkit documentation Contained in the Acme-PETEK-Testkit distribution.

Index


Code Index:

NAME

Top

Acme::PETEK::Testkit::modperl1 - mod_perl 1 handler for Tester's Toolkit

VERSION

Top

Version 1.00

SYNOPSIS

Top

This Perl module is intended to be a collection of sample code for the Tester's Toolkit presentation at YAPC::NA 2005 by the author.

HANDLER

Top

handler($r)

Called by Apache.

HANDLER HELPERS

Top

gen_page($value)

Generates the page HTML with a given value.

valid_int

Returns true if the supplied argument is a valid integer.

AUTHOR

Top

Pete Krawczyk, <petek@cpan.org>

BUGS

Top

Fix 'em yourself! :-)

ALSO SEE

Top

Slides from the presentation are available at http://www.bsod.net/~petek/slides/.

COPYRIGHT & LICENSE

Top


Acme-PETEK-Testkit documentation Contained in the Acme-PETEK-Testkit distribution.
package Acme::PETEK::Testkit::modperl1;

use strict;
use vars qw($VERSION);

use Acme::PETEK::Testkit;
use Apache::Constants qw(OK);
use Apache::Request;

$VERSION = '1.00';

sub handler {
	my $r = Apache::Request->new(shift);

	my $val = $r->param('value') || 0;
	my $dec = $r->param('decrval') || 1;
	my $inc = $r->param('incrval') || 1;

	my $t = Acme::PETEK::Testkit->new();
	if (valid_int($val)) {
		$t->reset($val);
	}

	if ($r->param('decrn') && valid_int($dec)) {
		$t->decr($dec);
	}
	elsif ($r->param('decr1')) {
		$t->decr;
	} 
	elsif ($r->param('reset')) {
		$t->reset;
	}
	elsif ($r->param('incr1')) {
		$t->incr;
	}
	elsif ($r->param('incrn') && valid_int($inc)) {
		$t->incr($inc);
	}

	$r->send_http_header('text/html');
	$r->print(gen_page($t->value));

	return OK;
}

sub gen_page {
	my $value = shift;

	return <<HTML;
<html><head><title>Counter: $value</title></head>
<body><form method="post"><input type="hidden" name="cur" value="$value">
<div align="center">
	<p><big>Current Value: <u>$value</u></big></p>
	<p><input type="text" name="decrval" value="1" size="3" maxlength="3"
		/><input type="submit" name="decrn" value="&lt;&lt;"
		/><input type="submit" name="decr1" value="&lt;"
		/><input type="submit" name="reset" value="-0-" 
		/><input type="submit" name="incr1" value="&gt;"
		/><input type="submit" name="incrn" value="&gt;&gt;"
		/><input type="text" name="incrval" value="1" size="3" maxlength="3"
		/></p>
</div>
</body></html>
HTML
}

sub valid_int {
	my $int = shift;
	return 1 if $int =~ /^-?\d+$/;
	return;
}

1; # End of Acme::PETEK::Testkit::modperl1