16 |
|
|
17 |
use Frey::SVK; |
use Frey::SVK; |
18 |
|
|
19 |
our @head = ( 'static/frey.css' ); |
use Text::Tabs; # expand, unexpand |
20 |
|
|
21 |
|
our @head; |
22 |
|
sub head { @head } |
23 |
|
|
24 |
has 'request_url' => ( |
has 'request_url' => ( |
25 |
is => 'rw', |
is => 'rw', |
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 = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
82 |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
83 |
$dump = $self->html_escape( $dump ); |
$dump = $self->html_escape( $dump ); |
84 |
$dump =~ s{\Q...\E}{…}gs; |
$dump =~ s{\Q...\E}{…}gs; |
85 |
|
# $dump =~ $self->editor_links( $dump ); # FIXME include this |
86 |
return "<code>$dump</code>"; |
return "<code>$dump</code>"; |
87 |
} |
} |
88 |
|
|
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 ) = @_; |
98 |
|
|
99 |
$content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*}; |
$content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*}; |
100 |
|
|
101 |
warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug; |
$content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span"); |
102 |
|
|
103 |
|
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 |
} |
} |
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; |
174 |
my ( $package, $path, $line ) = caller; |
my ( $package, $path, $line ) = caller; |
175 |
$self->add_head( qq| |
$self->add_head( qq| |
176 |
<style type="text/css"> |
<style type="text/css"> |
177 |
/* via package $package at $path line $line */ |
/* via $package at $path line $line */ |
178 |
$css |
$css |
179 |
</style> |
</style> |
180 |
| ); |
| ); |
208 |
|
|
209 |
my $status_line = ''; |
my $status_line = ''; |
210 |
|
|
|
unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }; |
|
|
# unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }; |
|
|
unshift @status, { 'INC' => Frey::INC->new->as_markup }; |
|
|
|
|
211 |
foreach my $part ( @status ) { |
foreach my $part ( @status ) { |
212 |
foreach my $name ( keys %$part ) { |
foreach my $name ( keys %$part ) { |
213 |
$status_line .= $self->popup( $name, $part->{$name} ); |
$status_line .= $self->popup( $name, $part->{$name} ); |
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 |
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 |
|
|
316 |
$error =~ s{(via package ")([\w:]+)(")} |
$error =~ s{(via (?:package) "?)([\w:]+)("?)} |
317 |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
318 |
|
|
319 |
return $error; |
return $error; |
338 |
|
|
339 |
=head2 add_status |
=head2 add_status |
340 |
|
|
341 |
$self->add_status( name => { some => 'data' } ); |
$self->add_status( { name => { some => 'data' } } ); |
342 |
|
|
343 |
$self->add_status( "append to last status popup" ); |
$self->add_status( "append to last status popup" ); |
344 |
|
|
346 |
|
|
347 |
sub add_status { |
sub add_status { |
348 |
my ( $self, $data ) = @_; |
my ( $self, $data ) = @_; |
349 |
|
push @status, { 'X' => [ $self->backtrace ] }; |
350 |
if ( ref($data) ) { |
if ( ref($data) ) { |
351 |
push @status, $data; |
push @status, $data; |
352 |
} else { |
} else { |
353 |
$status[ $#status ]->{added} = $data; |
if ( defined $status[ $#status ] ) { |
354 |
|
$status[ $#status ]->{ '+' } = $data; |
355 |
|
} else { |
356 |
|
push @status, { '+' => $data }; |
357 |
|
} |
358 |
} |
} |
359 |
} |
} |
360 |
|
|
368 |
|
|
369 |
sub clean_status { |
sub clean_status { |
370 |
my ($self) = shift; |
my ($self) = shift; |
371 |
@head = (); |
@head = ( 'static/frey.css' ); |
372 |
@status = (); |
@status = ( |
373 |
|
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
374 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
375 |
|
{ 'INC' => Frey::INC->new->as_markup }, |
376 |
|
); |
377 |
$icon_html = ''; |
$icon_html = ''; |
378 |
} |
} |
379 |
|
|
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; |
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"; |
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 = '…' |
$spacer = '…' |
527 |
} |
} |
528 |
$msg =~ s{^\s}{ }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 . qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>\n|; |
536 |
|
$msg = qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>$msg| |
537 |
|
. ( $spacer ? $spacer : '' ) |
538 |
|
. "\n"; # XXX <pre> needs this |
539 |
|
|
540 |
|
$warnings[ $pos++ % $max ] = $msg; |
541 |
} |
} |
542 |
} |
} |
543 |
|
warn "log has $line lines tell position ",tell($log); |
544 |
close($log) || die "can't close $path: $!"; |
close($log) || die "can't close $path: $!"; |
545 |
|
|
546 |
|
my $size = -s $path; |
547 |
|
|
548 |
|
my $warnings = join("", |
549 |
|
map { $warnings[ ( $pos + $_ ) % $max ] || '' } 0 .. ( $max - 1 ) |
550 |
|
); |
551 |
|
|
552 |
|
my $s = length($warnings); |
553 |
|
|
554 |
return |
return |
555 |
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 |
556 |
|
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>| |
557 |
. $self->editor_links( $warnings ) |
. $self->editor_links( $warnings ) |
558 |
. qq|</span></span>| |
. qq|</code></span></a>| |
559 |
; |
; |
560 |
} |
} |
561 |
|
|
581 |
) = caller($_) or last; |
) = caller($_) or last; |
582 |
|
|
583 |
push @backtrace, |
push @backtrace, |
584 |
qq|via package $package at $path line $line|; |
qq|via $package at $path line $line|; |
585 |
} |
} |
586 |
warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
#warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
587 |
return @backtrace; |
return @backtrace; |
588 |
} |
} |
589 |
|
|