/[Frey]/branches/zimbardo/lib/Frey/Web.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /branches/zimbardo/lib/Frey/Web.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 581 by dpavlin, Fri Nov 28 13:16:47 2008 UTC revision 611 by dpavlin, Fri Nov 28 23:34:26 2008 UTC
# Line 16  use Frey::INC; Line 16  use Frey::INC;
16    
17  use Frey::SVK;  use Frey::SVK;
18    
19    use Text::Tabs; # expand, unexpand
20    
21  our @head;  our @head;
22    sub head { @head }
23    
24  has 'request_url' => (  has 'request_url' => (
25          is => 'rw',          is => 'rw',
# Line 60  has 'html_dump_width' => ( Line 63  has 'html_dump_width' => (
63          is => 'rw',          is => 'rw',
64          isa => 'Int',          isa => 'Int',
65  #       required => 1, # FIXME we can't have required fields with defaults because Frey::Action isn't smart enough and asks for them  #       required => 1, # FIXME we can't have required fields with defaults because Frey::Action isn't smart enough and asks for them
66          default => 128,          default => 120,
67  );  );
68    
69  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
# Line 86  sub html_dump { Line 89  sub html_dump {
89  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }
90  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }
91    
92  our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1)>}s; # relaxed html check for one semi-valid tag  our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1|[^>]+/)>}s; # relaxed html check for one semi-valid tag
93    
94  sub popup_dropdown {  sub popup_dropdown {
95          my ( $self, $type, $name, $content, $full ) = @_;          my ( $self, $type, $name, $content, $full ) = @_;
# Line 97  sub popup_dropdown { Line 100  sub popup_dropdown {
100    
101          $content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span");          $content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span");
102    
103          warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug;          warn "## $type [$name] = ", length( $content ), " bytes"; # if $self->debug; # FIXME
104    
105          if ( $name =~ m{::} && $name !~ $re_html ) {          if ( $name =~ m{::} && $name !~ $re_html ) {
106                  return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|;                  return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|;
107            } elsif ( $name =~ s{^\s*(<a)\s+}{$1 class="frey-$type"} ) {
108                    return qq|$name $content\n|;
109          } else {          } else {
110                  return qq|<span class="frey-$type">$name $content</span>\n|;                  return qq|<span class="frey-$type">$name $content</span>\n|;
111          }          }
# Line 118  sub _head_html { Line 123  sub _head_html {
123                  $path =~ s!^/!!;                  $path =~ s!^/!!;
124                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
125                          $out .= $self->_inline_path( $path ) ?                          $out .= $self->_inline_path( $path ) ?
126                                  qq|<!-- $path --><script type="text/javascript">\n| . read_file($path) . qq|\n</script>| :                                  qq|<script type="text/javascript">\n/* inline $path */\n\n| . read_file($path) . qq|\n</script>| :
127                                  qq|<script type="text/javascript" src="/$path"></script>|;                                  qq|<script type="text/javascript" src="/$path"></script>|;
128                  } elsif ( $path =~ m/\.css$/ ) {                  } elsif ( $path =~ m/\.css$/ ) {
129                          $out .= $self->_inline_path( $path ) ?                          $out .= $self->_inline_path( $path ) ?
130                                  qq|<!-- $path --><style type="text/css">\n| . read_file( $path ) . qq|\n</style>| :                                  qq|<style type="text/css">\n/* inline $path */\n\n| . read_file( $path ) . qq|\n</style>| :
131                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
132                  } elsif ( $path =~ m{<.+>}s ) {                  } elsif ( $path =~ m{<.+>}s ) {
133                          $out .= $path;                          $out .= $path;
# Line 213  sub page { Line 218  sub page {
218          $url =~ s{\?reload=\d+}{};          $url =~ s{\?reload=\d+}{};
219    
220          my $body = $a->{body};          my $body = $a->{body};
221          $body ||= $self->as_markup if $self->can('as_markup');          if ( ! $body ) {
222                    my $run = $a->{run} || 'as_markup';
223                    warn "# no body, invoke $self->$run on ", ref($self);
224                    $body = $self->$run;
225            }
226          if ( $self->content_type !~ m{html} ) {          if ( $self->content_type !~ m{html} ) {
227                  warn "# return only $self body ", $self->content_type;                  warn "# return only $self body ", $self->content_type;
228                  return $body                  return $body
# Line 299  Create HTML links to editor for perl err Line 308  Create HTML links to editor for perl err
308  sub editor_links {  sub editor_links {
309          my ( $self, $error ) = @_;          my ( $self, $error ) = @_;
310    
311    #       $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back
312    
313          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}
314                  {at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm;                  {at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm;
315    
# Line 458  sub warnings_html { Line 469  sub warnings_html {
469          $level ||= $self->debug,          $level ||= $self->debug,
470          my $path = $self->log_path;          my $path = $self->log_path;
471    
472          my $warnings;          my $max = 30;
473            my $pos = 0;
474            my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines
475          my $line = 0;          my $line = 0;
476          my $multiline_end;          my $multiline_end;
477    
478            # XXX do we really want to do this every time?
479            my $css = qq|/* short css classes for levels */\n|;
480            my $level_to_class;
481            foreach ( keys %$warn_colors ) {
482                    my $l = length($_);
483                    my $class = 'l' . $l;
484                    $css .= qq|.$class { color: $warn_colors->{$_} }\n|;
485                    $level_to_class->{ $_ } = $class;
486            }
487            $self->add_css( $css );
488    
489          open(my $log, '<', $path) || die "can't open $path: $!";          open(my $log, '<', $path) || die "can't open $path: $!";
490          while(<$log>) {          while(<$log>) {
491                  chomp;                  chomp;
# Line 469  sub warnings_html { Line 493  sub warnings_html {
493    
494                  my $style = '';                  my $style = '';
495    
496    =for filter
497    
498                  if ( $multiline_end ) {                  if ( $multiline_end ) {
499                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {
500  #                               warn "## $line end of $multiline_end in '$_'\n";  #                               warn "## $line end of $multiline_end in '$_'\n";
# Line 485  sub warnings_html { Line 511  sub warnings_html {
511                                  next;                                  next;
512                          }                          }
513    
514                          $style = $warn_colors->{$1}  =cut
515                                  ? ' style="color:' . $warn_colors->{$1} . '"'                  if ( m{^(#*)} ) {
516                                  : '';  
517                            my $level = $1;
518                            my $msg = $_;
519    
                         my $msg = $self->html_escape( $_ );  
520                          my $spacer = ' ';                          my $spacer = ' ';
521                          if ( length($msg) > $self->html_dump_width ) {                          my $real_msg = expand( $msg );
522                                  $msg = substr( $msg, 0, $self->html_dump_width );                          if ( length($real_msg) > $self->html_dump_width ) {
523                                    
524                                    $real_msg = substr( $msg, 0, $self->html_dump_width );
525                                    $msg = unexpand( $real_msg );
526                                  $spacer = '&hellip;'                                  $spacer = '&hellip;'
527                          }                          }
528                          $msg =~ s{^\s}{&nbsp;}g;  
529                          $warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|;                          $msg = $self->html_escape( $msg );
530                          # FIXME <tt> should be <code> but CSS hates me  
531                            if ( my $class = $level_to_class->{ $level } ) {
532                                    $msg = qq|<span class="$class">$msg</span>|;
533                            }
534    
535                            $msg .= $spacer .
536                                    qq|<a target="editor" href="/editor+$path+$line" style="float: right;">+$line</a>\n|;
537    
538                            $warnings[ $pos++ % $max ] = $msg;
539                  }                  }
540          }          }
541            warn "log has $line lines tell position ",tell($log);
542          close($log) || die "can't close $path: $!";          close($log) || die "can't close $path: $!";
543    
544            my $size = -s $path;
545    
546            my $warnings = join("",
547                    map { $warnings[ ( $pos + $_ ) % $max ] || '' } 1 .. $max
548            );
549    
550            my $s = length($warnings);
551    
552          return          return
553                    qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="open $path level $level">warn</a><span>|                  # need to wrap editor link into span so we can have links in warnings
554                      qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="$path \| $size -> $s bytes \| $line -> $pos lines \| level $level">warn</a><code>|
555                  . $self->editor_links( $warnings )                  . $self->editor_links( $warnings )
556                  . qq|</span></span>|                  . qq|</code></span></a>|
557                  ;                  ;
558  }  }
559    
# Line 533  sub backtrace { Line 581  sub backtrace {
581                  push @backtrace,                  push @backtrace,
582                          qq|via $package at $path line $line|;                          qq|via $package at $path line $line|;
583          }          }
584          warn "# backtrace: ", dump( @backtrace ) if @backtrace;          #warn "# backtrace: ", dump( @backtrace ) if @backtrace;
585          return @backtrace;          return @backtrace;
586  }  }
587    

Legend:
Removed from v.581  
changed lines
  Added in v.611

  ViewVC Help
Powered by ViewVC 1.1.26