1 |
package Frey::Web; |
package Frey::Web; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
with 'Frey::Backtrace'; |
with 'Frey::Session'; |
5 |
|
|
6 |
use Frey::Types; |
use Frey::Types; |
7 |
|
|
8 |
use Continuity::Widget::DomNode; |
#use Continuity::Widget::DomNode; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use Carp qw/confess cluck/; |
use Carp qw/confess cluck/; |
11 |
use File::Slurp; |
use File::Slurp; |
12 |
|
|
13 |
use Frey::Bookmarklet; |
use Frey::Bookmarklet; |
14 |
use Frey::ClassBrowser; |
use Frey::ClassBrowser; |
15 |
|
use Frey::INC; |
16 |
|
|
17 |
use Frey::SVK; |
use Frey::SVK; |
18 |
|
|
19 |
has 'head' => ( |
use Text::Tabs; # expand, unexpand |
|
is => 'rw', |
|
|
isa => 'ArrayRef[Str]', |
|
|
default => sub { [ 'static/frey.css' ] }, |
|
|
); |
|
20 |
|
|
21 |
has 'status' => ( |
our @head; |
22 |
is => 'rw', |
sub head { @head } |
|
isa => 'ArrayRef[HashRef[Str]]', |
|
|
lazy => 1, |
|
|
default => sub { [ |
|
|
# { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
|
|
# { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
|
|
] }, |
|
|
); |
|
23 |
|
|
24 |
has 'request_url' => ( |
has 'request_url' => ( |
25 |
is => 'rw', |
is => 'rw', |
26 |
isa => 'Uri', coerce => 1, |
isa => 'Uri', coerce => 1, |
27 |
default => '/', |
required => 1, |
28 |
|
# default => '/', |
29 |
); |
); |
30 |
|
|
31 |
has 'title' => ( |
has 'title' => ( |
49 |
is => 'rw', |
is => 'rw', |
50 |
isa => 'Int', |
isa => 'Int', |
51 |
default => 4096, |
default => 4096, |
52 |
documentation => 'Maximum dump size sent to browser before truncation', |
documentation => 'maximum dump size sent to browser before truncation', |
53 |
); |
); |
54 |
|
|
|
=head2 inline_smaller_than |
|
|
|
|
|
Inline JavaScript and CSS smaller than this size into page reducing |
|
|
round-trips to server. |
|
|
|
|
|
=cut |
|
|
|
|
55 |
has 'inline_smaller_than' => ( |
has 'inline_smaller_than' => ( |
56 |
is => 'rw', |
is => 'rw', |
57 |
isa => 'Int', |
isa => 'Int', |
58 |
default => 10240, |
default => 10240, |
59 |
|
documentation => 'inline JavaScript and CSS to reduce round-trips', |
60 |
|
); |
61 |
|
|
62 |
|
has 'html_dump_width' => ( |
63 |
|
documentation => 'crop longer lines in dumps', |
64 |
|
is => 'rw', |
65 |
|
isa => 'Int', |
66 |
|
# required => 1, # FIXME we can't have required fields with defaults because Frey::Action isn't smart enough and asks for them |
67 |
|
default => 120, |
68 |
); |
); |
69 |
|
|
70 |
sub dom2html { |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
71 |
# warn "## dom2html ",dump( @_ ); |
my $escape_re = join '|' => keys %escape; |
72 |
return Continuity::Widget::DomNode->create( @_ )->to_string; |
|
73 |
|
sub html_escape { |
74 |
|
my ( $self, $html ) = @_; |
75 |
|
$html =~ s/($escape_re)/$escape{$1}/g; |
76 |
|
return $html; |
77 |
|
} |
78 |
|
|
79 |
|
sub html_dump { |
80 |
|
my ( $self, $dump ) = @_; |
81 |
|
$dump = dump( $dump ) if ref($dump); |
82 |
|
my $width = $self->html_dump_width; |
83 |
|
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
84 |
|
$dump = $self->html_escape( $dump ); |
85 |
|
$dump =~ s{\Q...\E}{…}gs; |
86 |
|
# $dump =~ $self->editor_links( $dump ); # FIXME include this |
87 |
|
return "<code>$dump</code>"; |
88 |
|
} |
89 |
|
|
90 |
|
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
91 |
|
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
92 |
|
|
93 |
|
our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1|[^>]+/)>}s; # relaxed html check for one semi-valid tag |
94 |
|
|
95 |
|
sub popup_dropdown { |
96 |
|
my ( $self, $type, $name, $content, $full ) = @_; |
97 |
|
|
98 |
|
$content = $self->html_dump($content) if ref $content; |
99 |
|
|
100 |
|
$content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*}; |
101 |
|
|
102 |
|
$content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span"); |
103 |
|
|
104 |
|
warn "## $type [$name] = ", length( $content ), " bytes"; # if $self->debug; # FIXME |
105 |
|
|
106 |
|
if ( $name =~ m{::} && $name !~ $re_html ) { |
107 |
|
return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|; |
108 |
|
} elsif ( $name =~ s{^\s*(<a)\s+}{$1 class="frey-$type"} ) { |
109 |
|
return qq|$name $content\n|; |
110 |
|
} else { |
111 |
|
return qq|<span class="frey-$type">$name $content</span>\n|; |
112 |
|
} |
113 |
} |
} |
114 |
|
|
115 |
sub _inline_path { |
sub _inline_path { |
120 |
sub _head_html { |
sub _head_html { |
121 |
my $self = shift; |
my $self = shift; |
122 |
my $out = ''; |
my $out = ''; |
123 |
foreach my $path ( @{ $self->head } ) { |
foreach my $path ( @head ) { |
124 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
125 |
if ( $path =~ m/\.js$/ ) { |
if ( $path =~ m/\.js$/ ) { |
126 |
$out .= $self->_inline_path( $path ) ? |
$out .= $self->_inline_path( $path ) ? |
127 |
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>| : |
128 |
qq|<script type="text/javascript" src="/$path"></script>|; |
qq|<script type="text/javascript" src="/$path"></script>|; |
129 |
} elsif ( $path =~ m/\.css$/ ) { |
} elsif ( $path =~ m/\.css$/ ) { |
130 |
$out .= $self->_inline_path( $path ) ? |
$out .= $self->_inline_path( $path ) ? |
131 |
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>| : |
132 |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
133 |
} elsif ( $path =~ m{<.+>}s ) { |
} elsif ( $path =~ m{<.+>}s ) { |
134 |
$out .= $path; |
$out .= $path; |
155 |
return if ! defined $path || $path eq ''; |
return if ! defined $path || $path eq ''; |
156 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
157 |
|
|
158 |
if ( $path =~ m{<.*>}s ) { |
if ( $path =~ $re_html ) { |
159 |
push @{ $self->head }, $path; |
push @head, $path; |
160 |
} elsif ( -e $path ) { |
} elsif ( -e $path ) { |
161 |
if ( $path =~ m/\.(?:js|css)$/ ) { |
if ( $path =~ m/\.(?:js|css)$/ ) { |
162 |
push @{ $self->head }, $path; |
push @head, $path; |
163 |
} else { |
} else { |
164 |
confess "can't add_head( $path ) it's not js or css"; |
confess "can't add_head( $path ) it's not js or css"; |
165 |
} |
} |
170 |
|
|
171 |
} |
} |
172 |
|
|
173 |
|
sub add_css { |
174 |
|
my ($self,$css) = @_; |
175 |
|
my ( $package, $path, $line ) = caller; |
176 |
|
$self->add_head( qq| |
177 |
|
<style type="text/css"> |
178 |
|
/* via $package at $path line $line */ |
179 |
|
$css |
180 |
|
</style> |
181 |
|
| ); |
182 |
|
} |
183 |
|
|
184 |
our $reload_counter = 0; |
our $reload_counter = 0; |
185 |
|
|
186 |
|
|
194 |
|
|
195 |
=cut |
=cut |
196 |
|
|
197 |
|
our @status; |
198 |
|
sub status { @status }; |
199 |
|
|
200 |
|
our $icon_html; |
201 |
|
|
202 |
sub page { |
sub page { |
203 |
my $self = shift; |
my $self = shift; |
204 |
my $a = {@_}; |
my $a = {@_}; |
205 |
|
|
206 |
|
warn "## page ",dump($a); |
207 |
|
|
208 |
$reload_counter++; |
$reload_counter++; |
209 |
|
|
210 |
my $status_line = ''; |
my $status_line = ''; |
211 |
foreach my $part ( @{ $self->status } ) { |
|
212 |
|
foreach my $part ( @status ) { |
213 |
foreach my $name ( keys %$part ) { |
foreach my $name ( keys %$part ) { |
214 |
my $content = $part->{$name}; |
$status_line .= $self->popup( $name, $part->{$name} ); |
|
if ( ref($content) ) { |
|
|
$content = '<code>' . dump($content) . '</code>'; |
|
|
my $l = length($content); |
|
|
$content = qq|<span>$l bytes</span>| if $l > $self->dump_max_bytes; |
|
|
} else { |
|
|
$content = qq|<span>$content</span>|; |
|
|
} |
|
|
warn "### part [$name] = ", length( $content ), " bytes" if $self->debug; |
|
|
$status_line .= qq|<span class="frey-popup">$name $content</span>\n|; |
|
215 |
} |
} |
216 |
} |
} |
217 |
|
|
219 |
$url =~ s{\?reload=\d+}{}; |
$url =~ s{\?reload=\d+}{}; |
220 |
|
|
221 |
my $body = $a->{body}; |
my $body = $a->{body}; |
222 |
$body ||= $self->as_markup if $self->can('as_markup'); |
if ( ! $body ) { |
223 |
|
my $run = $a->{run} || 'as_markup'; |
224 |
|
warn "# no body, invoke $self->$run on ", ref($self); |
225 |
|
$body = $self->$run; |
226 |
|
} |
227 |
if ( $self->content_type !~ m{html} ) { |
if ( $self->content_type !~ m{html} ) { |
228 |
warn "# return only $self body ", $self->content_type; |
warn "# return only $self body ", $self->content_type; |
229 |
return $body |
return $body |
232 |
$body = '<!-- no body -->'; |
$body = '<!-- no body -->'; |
233 |
} |
} |
234 |
|
|
235 |
my $warn_colors = { |
$status_line .= $self->warnings_html; |
|
'#' => '#444', |
|
|
'##' => '#888', |
|
|
}; |
|
|
|
|
|
$status_line |
|
|
.= qq|<span class="frey-popup">warn<span>| |
|
|
. $self->editor_links( |
|
|
join("", map { |
|
|
warn "# $_"; |
|
|
my $style = ''; |
|
|
$style = $warn_colors->{$1} |
|
|
? ' style="color:' . $warn_colors->{$1} . '"' |
|
|
: '' |
|
|
if m{^(#+)}; |
|
|
qq|<tt$style>$_</tt><br/>|; # XXX <tt> should be <code> but CSS hates me |
|
|
} $self->warnings ) |
|
|
) |
|
|
. qq|</span></span>| |
|
|
if $self->warnings; |
|
236 |
|
|
237 |
my ($exit,$description) = ('exit','stop server'); |
my ($exit,$description) = ('exit','stop server'); |
238 |
($exit,$description) = ('restart','restart server') |
($exit,$description) = ('restart','restart server') |
241 |
my $right = |
my $right = |
242 |
qq| |
qq| |
243 |
<span class="right"> |
<span class="right"> |
244 |
<a title="reload" href="/reload$url"><code>$url</code></a> |
<a title="reload $url" href="/reload$url">reload</a> |
245 |
<a title="$description" href="/exit$url">$exit</a> |
<a title="$description" href="/exit$url">$exit</a> |
246 |
</span> |
</span> |
247 |
|; |
|; |
248 |
|
|
249 |
my $info = Frey::SVK->info; |
my $svk = Frey::SVK->new; |
250 |
my $revision = Frey::SVK->info->{Revision} || ''; |
my $info = $svk->info; |
251 |
|
my $revision = $svk->info->{Revision} || ''; |
252 |
$revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)}; |
$revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)}; |
253 |
|
|
254 |
|
$self->add_icon unless $icon_html; |
255 |
|
|
256 |
my $html = join("\n", |
my $html = join("\n", |
257 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
258 |
$self->_head_html, |
$self->_head_html, |
259 |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
260 |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
261 |
|
( $icon_html || '<!-- no icon -->' ), |
262 |
( $a->{head} || '' ), |
( $a->{head} || '' ), |
263 |
qq| |
qq| |
264 |
</head><body> |
</head><body> |
288 |
sub editor { |
sub editor { |
289 |
my ( $self, $class, $line, $title ) = @_; |
my ( $self, $class, $line, $title ) = @_; |
290 |
confess "need class" unless $class; |
confess "need class" unless $class; |
291 |
$line ||= 1; |
if ( ! defined $title ) { |
292 |
|
$title = "edit $class"; |
293 |
|
$title .= " line $line" if $line; |
294 |
|
} |
295 |
|
$line ||= 1; |
296 |
qq|<a target="editor" href="/editor+$class+$line"| . |
qq|<a target="editor" href="/editor+$class+$line"| . |
297 |
( $title ? qq| title="$title"| : '' ) . |
( $title ? qq| title="$title"| : '' ) . |
298 |
qq|>$class</a>|; |
qq|>$class</a>|; |
309 |
sub editor_links { |
sub editor_links { |
310 |
my ( $self, $error ) = @_; |
my ( $self, $error ) = @_; |
311 |
|
|
312 |
|
# $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back |
313 |
|
|
314 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
315 |
{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; |
316 |
|
|
317 |
$error =~ s{(via package ")([\w:]+)(")} |
$error =~ s{(via (?:package) "?)([\w:]+)("?)} |
318 |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
319 |
|
|
320 |
return $error; |
return $error; |
335 |
; |
; |
336 |
} |
} |
337 |
|
|
338 |
|
=head1 Status line |
339 |
|
|
340 |
|
=head2 add_status |
341 |
|
|
342 |
|
$self->add_status( { name => { some => 'data' } } ); |
343 |
|
|
344 |
|
$self->add_status( "append to last status popup" ); |
345 |
|
|
346 |
|
=cut |
347 |
|
|
348 |
sub add_status { |
sub add_status { |
349 |
my ( $self, $data ) = @_; |
my ( $self, $data ) = @_; |
350 |
push @{ $self->status }, $data; |
push @status, { 'X' => [ $self->backtrace ] }; |
351 |
|
if ( ref($data) ) { |
352 |
|
push @status, $data; |
353 |
|
} else { |
354 |
|
if ( defined $status[ $#status ] ) { |
355 |
|
$status[ $#status ]->{ '+' } = $data; |
356 |
|
} else { |
357 |
|
push @status, { '+' => $data }; |
358 |
|
} |
359 |
|
} |
360 |
|
} |
361 |
|
|
362 |
|
=head2 clean_status |
363 |
|
|
364 |
|
Called at beginning of each request |
365 |
|
|
366 |
|
$self->clean_status; |
367 |
|
|
368 |
|
=cut |
369 |
|
|
370 |
|
sub clean_status { |
371 |
|
my ($self) = shift; |
372 |
|
@head = ( 'static/frey.css' ); |
373 |
|
my $params = { request_url => $self->request_url }; |
374 |
|
@status = ( |
375 |
|
{ 'ClassBrowser' => Frey::ClassBrowser->new( %$params, usage_on_top => 0 )->as_markup }, |
376 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new( %$params )->as_markup }, |
377 |
|
{ 'INC' => Frey::INC->new( %$params )->as_markup }, |
378 |
|
); |
379 |
|
$icon_html = ''; |
380 |
|
} |
381 |
|
|
382 |
|
=head2 status_parts |
383 |
|
|
384 |
|
Dump all status line parts |
385 |
|
|
386 |
|
$self->status_parts |
387 |
|
|
388 |
|
=cut |
389 |
|
|
390 |
|
sub status_parts { |
391 |
|
warn "## status parts ", dump( map { keys %$_ } @status ); |
392 |
} |
} |
393 |
|
|
394 |
|
=for debug |
395 |
|
|
396 |
sub DEMOLISH { |
sub DEMOLISH { |
397 |
my ( $self ) = @_; |
my ( $self ) = @_; |
398 |
cluck "## DEMOLISH status ", $#{ $self->status } + 1, " elements ", dump( map { keys %$_ } @{ $self->status } ); |
warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status; |
399 |
|
} |
400 |
|
|
401 |
|
=cut |
402 |
|
|
403 |
|
=head2 add_icon |
404 |
|
|
405 |
|
Frey::Foo->add_icon; # /static/icons/Frey/Foo.png |
406 |
|
Frey::Foo->add_icon('warning'); # /static/icons/Frey/Foo/warning.png |
407 |
|
|
408 |
|
=cut |
409 |
|
|
410 |
|
sub icon_path { |
411 |
|
my ($self,$class,$variant) = @_; |
412 |
|
my $icon = $class; |
413 |
|
$icon =~ s{::}{/}g; |
414 |
|
$icon .= "/$variant" if $variant; |
415 |
|
my $path = 'static/icons/' . $icon . '.png'; |
416 |
|
if ( -e $path ) { |
417 |
|
warn "# $class from $self icon_path $path" if $self->debug; |
418 |
|
return $path; |
419 |
|
} else { |
420 |
|
$self->TODO( "add $path icon for $class" ); |
421 |
|
return undef; |
422 |
|
} |
423 |
|
} |
424 |
|
|
425 |
|
sub add_icon { |
426 |
|
my ($self,$variant) = @_; |
427 |
|
|
428 |
|
my $class = ref($self); |
429 |
|
$class = $self->class if $self->can('class'); |
430 |
|
my $icon_path = $self->icon_path( $class, $variant ) || return; |
431 |
|
|
432 |
|
$icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|; |
433 |
|
warn "# using icon $icon_path"; |
434 |
|
|
435 |
|
=for later |
436 |
|
|
437 |
|
# FIXME http://en.wikipedia.org/wiki/Favicon suggest just rel="icon" but that doesn't seem to work! |
438 |
|
my $ico_path = $icon_path; |
439 |
|
$ico_path =~ s{png$}{ico}; |
440 |
|
if ( ! -e $ico_path ) { |
441 |
|
system "convert $icon_path $ico_path"; |
442 |
|
warn "# convert $icon_path $ico_path : $@"; |
443 |
|
} |
444 |
|
$icon_html .= qq|<link rel="shortcut icon" type="image/x-icon" href="/$ico_path">| if -e $ico_path; |
445 |
|
|
446 |
|
=cut |
447 |
|
|
448 |
|
} |
449 |
|
|
450 |
|
my $warn_colors = { |
451 |
|
'#' => '#444', |
452 |
|
'##' => '#888', |
453 |
|
}; |
454 |
|
|
455 |
|
my $multiline_markers = { |
456 |
|
'(' => ')', |
457 |
|
'{' => '}', |
458 |
|
'[' => ']', |
459 |
|
'"' => '"', |
460 |
|
}; |
461 |
|
|
462 |
|
my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']'; |
463 |
|
warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re"; |
464 |
|
|
465 |
|
sub log_path { |
466 |
|
$Frey::Bootstrap::log_path || warn "no log_path?"; |
467 |
|
} |
468 |
|
|
469 |
|
sub warnings_html { |
470 |
|
my ($self,$level) = shift; |
471 |
|
$level ||= $self->debug, |
472 |
|
my $path = $self->log_path; |
473 |
|
|
474 |
|
my $max = 30; |
475 |
|
my $pos = 0; |
476 |
|
my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines |
477 |
|
my $line = 0; |
478 |
|
my $multiline_end; |
479 |
|
|
480 |
|
# XXX do we really want to do this every time? |
481 |
|
my $css = qq|/* short css classes for levels */\n|; |
482 |
|
my $level_to_class; |
483 |
|
foreach ( keys %$warn_colors ) { |
484 |
|
my $l = length($_); |
485 |
|
my $class = 'l' . $l; |
486 |
|
$css .= qq|.$class { color: $warn_colors->{$_} }\n|; |
487 |
|
$level_to_class->{ $_ } = $class; |
488 |
|
} |
489 |
|
$self->add_css( $css ); |
490 |
|
|
491 |
|
open(my $log, '<', $path) || die "can't open $path: $!"; |
492 |
|
while(<$log>) { |
493 |
|
chomp; |
494 |
|
$line++; |
495 |
|
|
496 |
|
my $style = ''; |
497 |
|
|
498 |
|
=for filter |
499 |
|
|
500 |
|
if ( $multiline_end ) { |
501 |
|
if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) { |
502 |
|
# warn "## $line end of $multiline_end in '$_'\n"; |
503 |
|
undef $multiline_end; |
504 |
|
} else { |
505 |
|
# warn "## $line skipped\n"; |
506 |
|
} |
507 |
|
} elsif ( m{^(#*)\s+} ) { |
508 |
|
my $l = $1 ? length($1) : 0; |
509 |
|
if ( $l > $level ) { |
510 |
|
undef $multiline_end; |
511 |
|
$multiline_end = $multiline_markers->{$1} if m{($multiline_re)$}; |
512 |
|
# warn "## $line start $1 .. $multiline_end level $l > $level for '$_'\n" if $multiline_end; |
513 |
|
next; |
514 |
|
} |
515 |
|
|
516 |
|
=cut |
517 |
|
if ( m{^(#*)} ) { |
518 |
|
|
519 |
|
my $level = $1; |
520 |
|
my $msg = $_; |
521 |
|
|
522 |
|
my $spacer = ' '; |
523 |
|
my $real_msg = expand( $msg ); |
524 |
|
if ( length($real_msg) > $self->html_dump_width ) { |
525 |
|
|
526 |
|
$real_msg = substr( $msg, 0, $self->html_dump_width ); |
527 |
|
$msg = unexpand( $real_msg ); |
528 |
|
$spacer = '…' |
529 |
|
} |
530 |
|
|
531 |
|
$msg = $self->html_escape( $msg ); |
532 |
|
|
533 |
|
if ( my $class = $level_to_class->{ $level } ) { |
534 |
|
$msg = qq|<span class="$class">$msg</span>|; |
535 |
|
} |
536 |
|
|
537 |
|
#$msg .= $spacer . qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>\n|; |
538 |
|
$msg = qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>$msg| |
539 |
|
. ( $spacer ? $spacer : '' ) |
540 |
|
. "\n"; # XXX <pre> needs this |
541 |
|
|
542 |
|
$warnings[ $pos++ % $max ] = $msg; |
543 |
|
} |
544 |
|
} |
545 |
|
warn "log has $line lines tell position ",tell($log); |
546 |
|
close($log) || die "can't close $path: $!"; |
547 |
|
|
548 |
|
my $size = -s $path; |
549 |
|
|
550 |
|
my $warnings = join("", |
551 |
|
map { $warnings[ ( $pos + $_ ) % $max ] || '' } 0 .. ( $max - 1 ) |
552 |
|
); |
553 |
|
|
554 |
|
my $s = length($warnings); |
555 |
|
|
556 |
|
return |
557 |
|
# need to wrap editor link into span so we can have links in warnings |
558 |
|
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>| |
559 |
|
. $self->editor_links( $warnings ) |
560 |
|
. qq|</code></span></a>| |
561 |
|
; |
562 |
|
} |
563 |
|
|
564 |
|
|
565 |
|
=head2 backtrace |
566 |
|
|
567 |
|
Show backtrace with links to editor |
568 |
|
|
569 |
|
my @backtrace = $self->backtrace; |
570 |
|
|
571 |
|
=cut |
572 |
|
|
573 |
|
sub backtrace { |
574 |
|
my ($self) = @_; |
575 |
|
|
576 |
|
my @backtrace; |
577 |
|
foreach ( 0 .. 5 ) { |
578 |
|
my ( |
579 |
|
$package,$path,$line |
580 |
|
# subroutine hasargs |
581 |
|
# wantarray evaltext is_require |
582 |
|
# hints bitmask hinthash |
583 |
|
) = caller($_) or last; |
584 |
|
|
585 |
|
push @backtrace, |
586 |
|
qq|via $package at $path line $line|; |
587 |
|
} |
588 |
|
#warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
589 |
|
return @backtrace; |
590 |
} |
} |
591 |
|
|
592 |
1; |
1; |