Changeset 6

Show
Ignore:
Timestamp:
06/27/07 03:05:37 (7 years ago)
Author:
jesus
Message:

closes, #2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Mungo.pm

    r2 r6  
    1414use Mungo::Request; 
    1515use Mungo::Response; 
     16use HTML::Entities; 
    1617 
    1718use vars qw/$VERSION 
     
    118119  my %copy = %$self; 
    119120  my $page = bless \%copy, $pkg; 
    120   $page->content(@_); 
     121  eval { $page->content(@_); }; 
     122  if($@) { 
     123    my $error = $@; 
     124    my $preamble = eval "\$${pkg}::Mungo_preamble;"; 
     125    my $postamble = eval "\$${pkg}::Mungo_postamble;"; 
     126    my $contents = eval "\$${pkg}::Mungo_contents;"; 
     127    my ($line) = ($error =~ /line (\d+)/m); 
     128    die "$error\n\n".pretty_print_code($preamble, $contents, $postamble, $line); 
     129  } 
     130
     131sub pretty_print_code { 
     132  my ($preamble, $contents, $postamble, $line) = @_; 
     133  my $outer_line = 1; 
     134  my $inner_line = 1; 
     135  my $rv = ''; 
     136  (my $numbered_preamble = $preamble) =~ 
     137    s/^/sprintf("[ %4d]       ", $outer_line++)/emg; 
     138  $rv .= qq^<pre style="color: #999">$numbered_preamble</pre>\n^; 
     139  (my $numbered_contents = $$contents) =~ 
     140    s/^/sprintf("[%s%4d] %4d: ", ($outer_line == $line)?'*':' ', 
     141                $outer_line++, $inner_line++)/emg; 
     142  $numbered_contents = HTML::Entities::encode($numbered_contents); 
     143  $rv .= "<pre>$numbered_contents</pre>\n"; 
     144  (my $numbered_postamble = $postamble) =~ 
     145    s/^/sprintf("[ %4d]       ", $outer_line++)/emg; 
     146  $rv .= qq^<pre style="color: #999">$numbered_postamble</pre>\n\n^; 
     147  return $rv; 
    121148} 
    122149sub packagize { 
     
    150177     print "ERROR:<br><pre>$@</pre>\n\n"; 
    151178     print "PRE PARSE:<br>\n"; 
    152      my $outer_line = 1; 
    153      my $inner_line = 1; 
    154      (my $numbered_preamble = $preamble) =~ 
    155        s/^/sprintf("[%4d]       ", $outer_line++)/emg; 
    156      print qq^<pre style="color: #999">$numbered_preamble</pre>\n^; 
    157      (my $numbered_contents = $$contents) =~ 
    158        s/^/sprintf("[%4d] %4d: ", $outer_line++, $inner_line++)/emg; 
    159      print "<pre>$numbered_contents</pre>\n"; 
    160      (my $numbered_postamble = $postamble) =~ 
    161        s/^/sprintf("[%4d]       ", $outer_line++)/emg; 
    162      print qq^<pre style="color: #999">$numbered_postamble</pre>\n\n^; 
     179     print pretty_print_code($preamble, $contents, $postamble); 
    163180     return 0; 
    164181  } 
     182  eval "\$${pkg}::Mungo_preamble = \$preamble;"; 
     183  eval "\$${pkg}::Mungo_postamble = \$postamble;"; 
     184  eval "\$${pkg}::Mungo_contents = \$contents;"; 
    165185  return 1; 
    166186} 
  • trunk/lib/Mungo/Response.pm

    r5 r6  
    2323  my %core_data = ( 
    2424    'Apache::Request' => $r, 
    25     'ContentType' => $r->dir_config('MungoContentType') || 
    26                      $r->content_type || 'text/html', 
     25    'ContentType' => $r->dir_config('MungoContentType') || $r->content_type || 'text/html', 
    2726    # We don't set buffer here, we set it after it has been tied. 
    2827    # 'Buffer' => $r->dir_config('MungoBuffer') || 0, 
     
    130129  }; 
    131130  if($@) { 
    132     print "<pre>Error: $@\n\n".Carp::shortmess()."\n</pre>\n";; 
     131    (my $error = HTML::Entities::encode(Carp::longmess())) =~ s/\n/<br \/>/gsm; 
     132    print "Error in Include($subject):<br />$@\n\n".$error."\n\n";; 
    133133    return undef; 
    134134  }