From: Kip H. <ki...@us...> - 2009-01-24 13:17:45
|
Update of /cvsroot/sawa/sawa/t/src/htmltemplate/lib/htmltemplate In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11548/t/src/htmltemplate/lib/htmltemplate Added Files: Base.pm Output.pm handler.pm Log Message: Massive update to the test suite. Now decoupled from Apache::Test --- NEW FILE: Base.pm --- package htmltemplate::Base; use SAWA::Constants; use SAWA::Event::Simple; use strict; our @ISA = qw( SAWA::Event::Simple ); BEGIN { srand(time() ^ ($$ + ($$ << 15))) } sub registerEvents { return qw/ complete /; } sub event_default { my $self = shift; my $ctxt = shift; $ctxt->{template} = 'prompt.tmpl'; $ctxt->{message} = 'Please complete the following form to generate your fabulous new movie star name'; return OK; } sub event_complete { my $self = shift; my $ctxt = shift; my @param_names = $self->query->param; my @first_names = map { $self->query->param("$_") } grep { $_ =~ /^first_/ } @param_names; my @last_names = map { $self->query->param("$_") } grep { $_ =~ /^last_/ } @param_names; if ( ((scalar @first_names) + (scalar @last_names) != 6) || ( grep { length == 0 } @first_names, @last_names ) ) { $ctxt->{message} = 'All fields must be filled in. Please try again.'; $ctxt->{template} = 'prompt.tmpl'; return OK; } $ctxt->{first_name} = $first_names[ int( rand( @first_names )) ]; $ctxt->{last_name} = $last_names[ int( rand( @last_names )) ]; $ctxt->{message} = 'Congratulations! Your Movie Star name has been magically determined!'; $ctxt->{template} = 'complete.tmpl'; return OK; } 1; --- NEW FILE: handler.pm --- package htmltemplate::handler; use SAWA::Machine; use mod_perl; use constant MP2 => $mod_perl::VERSION >= 1.99; BEGIN { if (MP2) { require Apache::Response; require Apache::Const; } else { require Apache::Constants; } } sub handler { my $r = shift; my $app = SAWA::Machine->new(); $app->pipeline( qw( htmltemplate::Base htmltemplate::Output ) ); $app->run({}); return MP2 ? Apache::OK : Apache::Constants::OK; } 1; --- NEW FILE: Output.pm --- package htmltemplate::Output; use strict; use warnings; use SAWA::Constants; use base qw(SAWA::Output::HTMLTemplate); sub get_template { my $self = shift; my $ctxt = shift; # this is more complest than it usually would be # due to the fact that the test dir may be installed # in any dir my $style_path; if ($ENV{MOD_PERL}) { $style_path = $self->query->r->document_root; $style_path .= '/templates/moviename/'; } else { require Cwd; $style_path = Cwd::abs_path('../htdocs/templates/moviename'); $style_path .= '/'; } $self->template_path( $style_path ); $self->template( $ctxt->{template} ); return OK; } sub get_template_vars { my $self = shift; my $ctxt = shift; for ( $self->query->param ) { $ctxt->{$_} = $self->query->param($_); } $self->template_vars($ctxt); return OK; } sub get_template_conf { my $self = shift; $self->template_conf({ die_on_bad_params => 0 }); return OK; } 1; |