Re: Mason-checkins digest, Vol 1 #742 - 5 msgs
Jonathan Swartz <[email protected]> Mon, 15 Aug 2005 03:30:18 -0700
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
Dave - The $m->print code used grep originally, but someone at work did some profiling and determined that the for loop was faster. Probably because the grep creates a whole new list. Unless you've profiled this and found otherwise, please change it back to use a for loop. If you want to get rid of the $text alias and just use $_, that's fine. Otherwise the changes look good to me, I agree this is much cleaner than turning off all undef warnings! Bad Jon. Jon > Message: 2 > To: [email protected] > From: Dave Rolsky <[email protected]> > Date: Sun, 14 Aug 2005 07:11:32 -0700 > Subject: [Mason-checkins] CVS: mason/dist/lib/HTML/Mason Request.pm, > 1.352,1.353 > Reply-To: [email protected] > > Update of /cvsroot/mason/mason/dist/lib/HTML/Mason > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16117 > > Modified Files: > Request.pm > Log Message: > style cleanup > avoid making temp copy (or is it an alias?) of elements in @_ - > either way code is simpler to read > > > Index: Request.pm > =================================================================== > RCS file: /cvsroot/mason/mason/dist/lib/HTML/Mason/Request.pm,v > retrieving revision 1.352 > retrieving revision 1.353 > diff -u -r1.352 -r1.353 > --- Request.pm 13 Aug 2005 03:57:35 -0000 1.352 > +++ Request.pm 14 Aug 2005 14:11:30 -0000 1.353 > @@ -1146,12 +1146,14 @@ > { > my $self = shift; > > - my $bufref = defined($self->{top_stack}) ? > - $self->{top_stack}->[STACK_BUFFER] : > - \($self->{request_buffer}); > - foreach my $text (@_) { > - $$bufref .= $text if defined($text); > - } > + my $bufref = > + ( defined $self->{top_stack} > + ? $self->{top_stack}->[STACK_BUFFER] > + : \$self->{request_buffer} > + ); > + > + $$bufref .= $_ for grep { defined } @_; > + > $self->flush_buffer if $self->{autoflush}; > } > > > > > --__--__-- > > Message: 3 > To: [email protected] > From: Dave Rolsky <[email protected]> > Date: Sun, 14 Aug 2005 07:12:05 -0700 > Subject: [Mason-checkins] CVS: mason/dist/lib/HTML/Mason > Compiler.pm,1.122,1.123 > Reply-To: [email protected] > > Update of /cvsroot/mason/mason/dist/lib/HTML/Mason > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16215 > > Modified Files: > Compiler.pm > Log Message: > only output defined bits of text for output-generating code with > enable_autoflush off > > > Index: Compiler.pm > =================================================================== > RCS file: /cvsroot/mason/mason/dist/lib/HTML/Mason/Compiler.pm,v > retrieving revision 1.122 > retrieving revision 1.123 > diff -u -r1.122 -r1.123 > --- Compiler.pm 13 Aug 2005 15:49:11 -0000 1.122 > +++ Compiler.pm 14 Aug 2005 14:12:02 -0000 1.123 > @@ -498,7 +498,9 @@ > if ($self->enable_autoflush) { > $code = "\$m->print( $text );\n"; > } else { > - $code = "for ($text) { \$\$_outbuf .= \$_ }\n"; > + # only output defined bits, which is what $m->print does > + # internally as well > + $code = "for ( grep { defined } $text ) { \$\$_outbuf .= \ > $_ }\n"; > } > > eval { $self->postprocess_perl->(\$code) } if $self- > >postprocess_perl; > > > > --__--__-- > > Message: 4 > To: [email protected] > From: Dave Rolsky <[email protected]> > Date: Sun, 14 Aug 2005 07:18:32 -0700 > Subject: [Mason-checkins] CVS: mason/dist/lib/HTML/Mason Tests.pm, > 1.65,1.66 > Reply-To: [email protected] > > Update of /cvsroot/mason/mason/dist/lib/HTML/Mason > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17205 > > Modified Files: > Tests.pm > Log Message: > added expect_warnings, which works just like expect_error (more or > less) > > > Index: Tests.pm > =================================================================== > RCS file: /cvsroot/mason/mason/dist/lib/HTML/Mason/Tests.pm,v > retrieving revision 1.65 > retrieving revision 1.66 > diff -u -r1.65 -r1.66 > --- Tests.pm 14 Aug 2005 14:07:36 -0000 1.65 > +++ Tests.pm 14 Aug 2005 14:18:30 -0000 1.66 > @@ -542,7 +542,7 @@ > { > if ( $test->{expect_error} ) > { > - if ( $@ =~ /$test->{expect_error}/ ) > + if ( $error =~ /$test->{expect_error}/ ) > { > return $self->_success > } > @@ -580,6 +580,15 @@ > $self->check_output( actual => $self->{buffer}, expect > => $test->{expect} ) > ); > > + if ( $test->{expect_warnings} ) > + { > + unless ( $warnings =~ /$test->{expect_warnings}/ ) > + { > + $Test->diag( "Got warnings:\n$warnings\n...but > expected something matching:\n$test->{expect_warnings}\n" ); > + $success = 0; > + } > + } > + > $Test->diag( "Got warnings: $warnings" ) if $warnings; > $success = 0 if $test->{no_warnings} && $warnings; > > @@ -828,14 +837,19 @@ > > =item * expect_error > > -A regex containing that will be matched against the error returned > -from the component execution. > +A regex that will be matched against the error returned from the > +component execution. > > =item * no_warnings > > If true, this means that the test expects to run without generating > any warnings. If warnings are generated, the test fails. > > +=item * expect_warnings > + > +A regex that will be matched against any warnings output when running > +the component. > + > =item * skip_expect > > This causes the component to be run but its output is ignored. > > > > --__--__-- > > Message: 5 > To: [email protected] > From: Dave Rolsky <[email protected]> > Date: Sun, 14 Aug 2005 07:19:00 -0700 > Subject: [Mason-checkins] CVS: mason/dist/t 06-compiler.t,1.72,1.73 > Reply-To: [email protected] > > Update of /cvsroot/mason/mason/dist/t > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17302 > > Modified Files: > 06-compiler.t > Log Message: > test that a substitution can output an undef value without warnings > test that other warnings in a component body are output > > > Index: 06-compiler.t > =================================================================== > RCS file: /cvsroot/mason/mason/dist/t/06-compiler.t,v > retrieving revision 1.72 > retrieving revision 1.73 > diff -u -r1.72 -r1.73 > --- 06-compiler.t 13 Aug 2005 15:49:12 -0000 1.72 > +++ 06-compiler.t 14 Aug 2005 14:18:58 -0000 1.73 > @@ -1060,6 +1060,63 @@ > > #------------------------------------------------------------ > > + $group->add_test( name => 'no_warnings', > + description => 'Make sure no warnings > are generated for trying to output undef', > + component => <<'EOF', > +% my $x; > +x is <% $x %> > +EOF > + expect => <<'EOF', > +x is > +EOF > + ); > + > +#------------------------------------------------------------ > + > + $group->add_test( name => 'no_warnings_without_autoflush', > + description => 'Make sure no warnings > are generated for trying to output undef when enable_autoflush is > off', > + interp_params => { enable_autoflush => 0 }, > + component => <<'EOF', > +% my $x; > +x is <% $x %> > +EOF > + expect => <<'EOF', > +x is > +EOF > + no_warnings => 1, > + ); > + > +#------------------------------------------------------------ > + > + $group->add_test( name => 'warnings', > + description => 'Make sure that warnings > _are_ generated for other bad use of uninit', > + component => <<'EOF', > +% my $x; > +x is <% $x + 2 %> > +EOF > + expect => <<'EOF', > +x is 2 > +EOF > + expect_warnings => qr/Use of > uninitialized value in addition/, > + ); > + > +#------------------------------------------------------------ > + > + $group->add_test( name => 'warnings_without_autoflush', > + description => 'Make sure that warnings > _are_ generated for other bad use of uninit when enable_autoflush > is off', > + interp_params => { enable_autoflush => 0 }, > + component => <<'EOF', > +% my $x; > +x is <% $x + 2 %> > +EOF > + expect => <<'EOF', > +x is 2 > +EOF > + expect_warnings => qr/Use of > uninitialized value in addition/, > + ); > + > +#------------------------------------------------------------ > + > return $group; > } > > > > > > --__--__-- > > _______________________________________________ > Mason-checkins mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/mason-checkins > > > End of Mason-checkins Digest > > > ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf