1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# this is the application class
# this example shows how to skip the build in xml/xslt serialization
package example4;
use vars qw( @ISA @HANLDER );
use CGI::XMLApplication;
use XML::LibXML;
@ISA = qw(CGI::XMLApplication);
sub registerEvents { qw( submit ); } # the handler list
sub selectStylesheet {
return './' . ex2_form.xsl;
}
sub event_init {
my ( $self , $ctxt ) = @_;
# initialize the internal context
my $dom = XML::LibXML::Document->new();
my $root= $dom->createElement( 'yourfavouritetagname' );
$dom->setDocumentElement( $root );
$ctxt->{-XML} = $dom;
$ctxt->{-ROOT}= $root;
$ctxt->{-stylesheet} = 0; # on default we'll display the form
if ( $self->param('email')=~/\@.*\@/ || $self->param('email')!~/\@..+/ ) {
$self->sendEvent('_internal_error_' );
}
}
sub event_default {
my ( $self , $ctxt ) = @_;
$ctxt->{-ROOT}->appendTextChild('message','Hey user from ' .
$self->remote_host() .
" pass your email!" );
return 0;
}
sub event_submit {
my ( $self , $ctxt ) = @_;
# assume we have an file uploaded by the user and simply want to return
# it back to the client
my $file = $self->param("thefile");
my $type = $self->uploadInfo($file)->{'Content-Type'};
print $self->header( -type=>$type );
while ( <$file> ) { print; }
# in such a case we already handled the request so CGI::XMLApplication
# should not try any serialization
$self->skipSerialization(1);
return 0;
}
1;
|