NAME
CGI::PrintWrapper - CGI methods output to a print handle
SYNOPSIS
use CGI::PrintHandle;
use IO::Scalar; # just an example
use HTML::Stream; # continuing the example
my $content = '';
my $handle = IO::Scalar->new (\$content);
my $cgi = CGI::PrintHandle ($handle);
my $html = HTML::Stream->new ($handle);
# Not a very exciting example:
$cgi->start_form;
$html->STRONG->t ('I am a form.')->_STRONG;
$cgi->submit;
$cgi->end_form;
print "$content\n";
<FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<STRONG>I am a form.</STRONG><INPUT TYPE="submit" NAME=".submit"></FORM>
DESCRIPTION
CGI::PrintWrapper arranges for CGI methods to output their results by printing onto an arbitrary handle. This gets around the problem that the CGI's subs return strings.
You could just call print
yourself on the appropriate file handle, but there are many contexts in which it is cleaner to provide the extra abstraction (such as mixing CGI with HTML::Stream, the problem which prompted my solution, illustrated above).
CGI::PrintWrapper creates the necessary callbacks for printing dynamically, updating the symbol table as it encounters a new CGI method.
CONSTRUCTOR
new($h)
-
Creates a new CGI::PrintWrapper, printing the results of CGI methods onto the print handle object,
$h
.
METHODS
io()
-
Returns the underlying print handle object.
AUTOLOAD
-
Initially,
CGI::PrintWrapper
has no methods (exceptio
). As the caller invokes CGI methods,AUTOLOAD
creates anonymous subroutines to perform the actual CGI method call and print the results with the print handle object. It also updates the symbol table so that future calls can bypassAUTOLOAD
.
SEE ALSO
CGI, IO::Scalar, HTML::Stream, "print" in perlfunc
CGI is the canonical package for working with fill-out forms on the web.
IO::Scalar is a handy package for treating a string as an object supporting IO handle semantics.
HTML::Stream is a nice package for writing HTML markup and content into an IO handle with stream semantics.
DIAGNOSTICS
The following are the diagnostics generated by Class::Class. Items marked "(W)" are non-fatal (invoke Carp::carp
); those marked "(F)" are fatal (invoke Carp::croak
).
- No print handle
-
(F) The caller tried to create a new
CGI::PrintWrapper
without supplying an object which supportsprint
. - '%s' is not a print handle
-
(F) The caller tried to create a new
CGI::PrintWrapper
using an object which does not supportprint
.
BUGS AND CAVEATS
So far, none, but you never know. Caveat emptor.
AUTHORS
B. K. Oxley (binkley) at Home <binkley@bigfoot.com>. I am grateful to my employer, DataCraft, Inc., for time spent preparing this package for public consumption.
COPYRIGHT
$Id: PrintWrapper.pm,v 1.4 1999/11/18 20:48:00 binkley Exp $
Copyright 1999, B. K. Oxley (binkley).
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.