3 |
|
|
4 |
with 'Frey::Session'; |
with 'Frey::Session'; |
5 |
|
|
|
use Frey::Types; |
|
|
|
|
6 |
#use Continuity::Widget::DomNode; |
#use Continuity::Widget::DomNode; |
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use Carp qw/confess cluck/; |
use Carp qw/confess cluck carp/; |
9 |
use File::Slurp; |
use File::Slurp; |
10 |
|
use Text::Tabs; # expand, unexpand |
11 |
|
|
12 |
|
use lib 'lib'; |
13 |
|
|
14 |
|
use Frey::Types; |
15 |
|
|
16 |
use Frey::Bookmarklet; |
use Frey::Bookmarklet; |
17 |
use Frey::ClassBrowser; |
use Frey::Class::Browser; |
18 |
use Frey::INC; |
use Frey::INC; |
19 |
|
|
20 |
use Frey::SVK; |
use Frey::SVK; |
21 |
|
|
|
use Text::Tabs; # expand, unexpand |
|
|
|
|
22 |
our @head; |
our @head; |
23 |
sub head { @head } |
sub head { @head } |
24 |
|
|
27 |
isa => 'Uri', coerce => 1, |
isa => 'Uri', coerce => 1, |
28 |
required => 1, |
required => 1, |
29 |
default => sub { |
default => sub { |
30 |
cluck "undefined request_url"; |
carp "undefined request_url"; |
31 |
'/'; |
'/'; |
32 |
}, |
}, |
33 |
); |
); |
71 |
default => 250, |
default => 250, |
72 |
); |
); |
73 |
|
|
74 |
|
has 'wrap_in_page' => ( |
75 |
|
documentation => 'wrap full html page with status bar around content', |
76 |
|
is => 'rw', |
77 |
|
isa => 'Bool', |
78 |
|
default => 1, |
79 |
|
); |
80 |
|
|
81 |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
82 |
my $escape_re = join '|' => keys %escape; |
my $escape_re = join '|' => keys %escape; |
83 |
|
|
84 |
sub html_escape { |
sub html_escape { |
85 |
my ( $self, $html ) = @_; |
my ( $self, $html ) = @_; |
86 |
|
return '' unless defined $html; |
87 |
$html =~ s/($escape_re)/$escape{$1}/g; |
$html =~ s/($escape_re)/$escape{$1}/g; |
88 |
return $html; |
return $html; |
89 |
} |
} |
90 |
|
|
91 |
|
# from Mojo::ByteStream |
92 |
|
sub url_escape { |
93 |
|
my ( $self, $url, $pattern ) = @_; |
94 |
|
$pattern ||= 'A-Za-z0-9\-\.\_\~'; |
95 |
|
$url =~ s/([^$pattern])/sprintf('%%%02X',ord($1))/ge; |
96 |
|
return $url; |
97 |
|
} |
98 |
|
|
99 |
sub html_dump { |
sub html_dump { |
100 |
my ( $self, $dump ) = @_; |
my ( $self, $dump ) = @_; |
101 |
$dump = dump( $dump ) if ref($dump); |
$dump = dump( $dump ) if ref($dump); |
103 |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
104 |
$dump = $self->html_escape( $dump ); |
$dump = $self->html_escape( $dump ); |
105 |
$dump =~ s{\Q...\E}{…}gs; |
$dump =~ s{\Q...\E}{…}gs; |
106 |
# $dump =~ $self->editor_links( $dump ); # FIXME include this |
# $dump =~ $self->html_links( $dump ); # FIXME include this |
107 |
return "<code>$dump</code>"; |
return "<code>$dump</code>"; |
108 |
} |
} |
109 |
|
|
110 |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
111 |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
112 |
|
|
113 |
our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1|[^>]+/)>}s; # relaxed html check for one semi-valid tag |
our $re_html = qr{<(?:!--|(\w+)|[^>]+)/?>}s; # relaxed html check for one semi-valid tag |
114 |
|
|
115 |
sub popup_dropdown { |
sub popup_dropdown { |
116 |
my ( $self, $type, $name, $content, $full ) = @_; |
my ( $self, $type, $name, $content, $full ) = @_; |
132 |
} |
} |
133 |
} |
} |
134 |
|
|
135 |
sub _inline_path { |
sub _inline { |
136 |
my ( $self, $path ) = @_; |
my ( $self, $path ) = @_; |
137 |
-s $path < $self->inline_smaller_than; |
return unless defined $path; |
138 |
|
warn "# _inline $path"; |
139 |
|
-e $path && -s $path < $self->inline_smaller_than && -s $path; |
140 |
} |
} |
141 |
|
|
142 |
sub _head_html { |
sub _head_html { |
145 |
foreach my $path ( @head ) { |
foreach my $path ( @head ) { |
146 |
$path =~ s!^/!!; |
$path =~ s!^/!!; |
147 |
if ( $path =~ m/\.js$/ ) { |
if ( $path =~ m/\.js$/ ) { |
148 |
$out .= $self->_inline_path( $path ) ? |
my $size; |
149 |
qq|<script type="text/javascript">\n/* inline $path */\n\n| . read_file($path) . qq|\n</script>| : |
$out .= $size = _inline( $path ) ? |
150 |
|
qq|<script type="text/javascript">\n/* inline $path $size bytes */\n\n| . read_file($path) . qq|\n</script>| : |
151 |
qq|<script type="text/javascript" src="/$path"></script>|; |
qq|<script type="text/javascript" src="/$path"></script>|; |
152 |
} elsif ( $path =~ m/\.css$/ ) { |
} elsif ( $path =~ m/\.css$/ ) { |
153 |
$out .= $self->_inline_path( $path ) ? |
my $size; |
154 |
qq|<style type="text/css">\n/* inline $path */\n\n| . read_file( $path ) . qq|\n</style>| : |
$out .= $size = _inline( $path ) ? |
155 |
|
qq|<style type="text/css">\n/* inline $path $size bytes */\n\n| . read_file( $path ) . qq|\n</style>| : |
156 |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|; |
157 |
} elsif ( $path =~ m{<.+>}s ) { |
} elsif ( $path =~ m{<.+>}s ) { |
158 |
$out .= $path; |
$out .= $path; |
194 |
|
|
195 |
} |
} |
196 |
|
|
197 |
|
sub _add_css_js { |
198 |
|
my ( $self, $what, $content ) = @_; |
199 |
|
|
200 |
|
my $tag = $what eq 'css' ? 'style' : 'script'; |
201 |
|
my $type = $what eq 'css' ? 'text/css' : 'text/javascript'; |
202 |
|
my $head; |
203 |
|
|
204 |
|
my ( $package, $path, $line ) = caller(1); |
205 |
|
|
206 |
|
$content = "/$content" if $content !~ m{[\n\r]} && -e $content; |
207 |
|
if ( $content =~ $re_html ) { |
208 |
|
$head = qq| |
209 |
|
$content |
210 |
|
<!-- $type via $package at $path line $line --> |
211 |
|
|; |
212 |
|
} elsif ( $content =~ m{^(/\w+|https?://)} && $content !~ m{[\n\r]} ) { |
213 |
|
if ( $what eq 'js' ) { |
214 |
|
$head = qq| |
215 |
|
<$tag type="$type" src="$content"> |
216 |
|
/* $what via $package at $path line $line */ |
217 |
|
</$tag> |
218 |
|
|; |
219 |
|
} else { |
220 |
|
$head = qq| |
221 |
|
<link rel="stylesheet" type="$type" href="$content"> |
222 |
|
<!-- $what via $package at $path line $line --> |
223 |
|
|; |
224 |
|
} |
225 |
|
} else { |
226 |
|
$head = qq| |
227 |
|
<$tag type="$type"> |
228 |
|
/* via $package at $path line $line */ |
229 |
|
$content |
230 |
|
</$tag> |
231 |
|
|; |
232 |
|
}; |
233 |
|
$self->add_head( $head ); |
234 |
|
} |
235 |
|
|
236 |
sub add_css { |
sub add_css { |
237 |
my ($self,$css) = @_; |
my ($self,$css) = @_; |
238 |
my ( $package, $path, $line ) = caller; |
$self->_add_css_js( 'css', $css ); |
239 |
$self->add_head( qq| |
} |
240 |
<style type="text/css"> |
|
241 |
/* via $package at $path line $line */ |
sub add_js { |
242 |
$css |
my ($self,$js) = @_; |
243 |
</style> |
$self->_add_css_js( 'js', $js ); |
|
| ); |
|
244 |
} |
} |
245 |
|
|
246 |
our $reload_counter = 0; |
our $reload_counter = 0; |
247 |
|
|
248 |
|
|
249 |
=head2 page |
=head2 html_page |
250 |
|
|
251 |
$self->page( |
$self->html_page( |
252 |
title => 'page title', |
title => 'page title', |
253 |
head => '<!-- optional head markup -->', |
head => '<!-- optional head markup -->', |
254 |
body => '<b>Page Body</b>', |
body => '<b>Page Body</b>', |
261 |
|
|
262 |
our $icon_html; |
our $icon_html; |
263 |
|
|
264 |
sub page { |
sub html_page { |
265 |
my $self = shift; |
my $self = shift; |
266 |
my $a = {@_}; |
my $a = {@_}; |
267 |
|
|
|
warn "## page ",dump($a); |
|
|
|
|
268 |
$reload_counter++; |
$reload_counter++; |
269 |
|
|
270 |
my $status_line = ''; |
my $status_line = ''; |
284 |
warn "# no body, invoke $self->$run on ", ref($self); |
warn "# no body, invoke $self->$run on ", ref($self); |
285 |
$body = $self->$run; |
$body = $self->$run; |
286 |
} |
} |
287 |
if ( $self->content_type !~ m{html} ) { |
if ( $self->content_type !~ m{html} || ! $self->wrap_in_page ) { |
288 |
warn "# return only $self body ", $self->content_type; |
warn "# return only $self body ", $self->content_type; |
289 |
return $body |
return $body |
290 |
} elsif ( ! defined $body ) { |
} elsif ( ! defined $body ) { |
302 |
qq| |
qq| |
303 |
<span class="right"> |
<span class="right"> |
304 |
<a title="reload $url" href="/reload$url">reload</a> |
<a title="reload $url" href="/reload$url">reload</a> |
305 |
<a title="$description" href="/exit$url">$exit</a> |
<a title="$description" href="/exit$url" target="exit">$exit</a> |
306 |
</span> |
</span> |
307 |
|; |
|; |
308 |
|
|
313 |
|
|
314 |
$self->add_icon unless $icon_html; |
$self->add_icon unless $icon_html; |
315 |
|
|
316 |
|
my $title = undef |
317 |
|
|| $a->{title} |
318 |
|
|| $self->title |
319 |
|
|| ref($self) |
320 |
|
; |
321 |
|
|
322 |
|
# $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes |
323 |
|
|
324 |
my $html = join("\n", |
my $html = join("\n", |
325 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
326 |
$self->_head_html, |
$self->_head_html, |
327 |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
qq|<title>$title</title>|, |
328 |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
329 |
( $icon_html || '<!-- no icon -->' ), |
( $icon_html || '<!-- no icon -->' ), |
330 |
( $a->{head} || '' ), |
( $a->{head} || '' ), |
366 |
qq|>$class</a>|; |
qq|>$class</a>|; |
367 |
} |
} |
368 |
|
|
369 |
=head2 editor_links |
=head2 html_links |
370 |
|
|
371 |
Create HTML links to editor for perl error message |
Create HTML links to editor for perl error message |
372 |
|
|
373 |
my $html = $self->editor_links( $error ) |
my $html = $self->html_links( $error ) |
374 |
|
|
375 |
=cut |
=cut |
376 |
|
|
377 |
sub editor_links { |
sub html_links { |
378 |
my ( $self, $error ) = @_; |
my ( $self, $error ) = @_; |
379 |
|
|
380 |
|
$error = $self->strip_full_path( $error ); |
381 |
|
|
382 |
# $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back |
# $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back |
383 |
|
|
384 |
|
# perl's backtrace |
385 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
386 |
{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
{at <a target="editor" href="/editor+$1+$2" title="vi $1 +$2">$1</a> line $2}gsm; |
387 |
|
|
388 |
|
$error =~ s{(via (?:package)\s+"?)([\w:]+)("?)} |
389 |
|
{$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm |
390 |
|
|| # or anything that looks like "Class::Name" |
391 |
|
$error =~ s{"(\w+(?:::\w+)+)"} |
392 |
|
{"<a target="$1" href="/$1" title="introspect $1">$1</a>"}gsm; |
393 |
|
|
394 |
|
# method error messages |
395 |
|
# FIXME replace with link to Frey::Introspect data |
396 |
|
$error =~ s{(method ")(\w+)(" via)} |
397 |
|
{$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm; |
398 |
|
|
399 |
|
# link paths to editor |
400 |
|
$error =~ s{((?:lib|t)/[\S]+)\s+(\d+\s+bytes)} |
401 |
|
{<a target="editor" href="/editor+$1+1" title="vi $1 [$2]">$1</a>}gsm; |
402 |
|
|
403 |
$error =~ s{(via (?:package) "?)([\w:]+)("?)} |
$error =~ s{(class ")([\w:]+)(")} |
404 |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
{$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm; |
405 |
|
|
406 |
return $error; |
return $error; |
407 |
} |
} |
408 |
|
|
409 |
|
sub html_self { |
410 |
|
my $self = shift; |
411 |
|
my $html = $self; |
412 |
|
$html =~ s{([\w:]+)=}{<a target="$1" href="/$1" title="introspect $1">$1</a>=}gsm; |
413 |
|
return $html; |
414 |
|
} |
415 |
|
|
416 |
|
=head2 error |
417 |
|
|
418 |
|
This method will return error to browser and backtrace unless |
419 |
|
error message ends with LF C<\n> just like L<warn> |
420 |
|
|
421 |
|
=cut |
422 |
|
|
423 |
sub error { |
sub error { |
424 |
my $self = shift; |
my $self = shift; |
425 |
my $error = join(" ", @_); |
my $error = join(" ", @_); |
426 |
|
|
427 |
my @backtrace = $self->backtrace; |
my $fatal = ''; |
428 |
$error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; |
my $backtrace = ''; |
429 |
|
|
430 |
|
if ( $error !~ m{\n$} ) { |
431 |
|
if ( my @backtrace = $self->backtrace ) { |
432 |
|
$backtrace = |
433 |
|
"\n" . $self->html_self . "->error backtrace\n\t" |
434 |
|
. $self->html_links( join( "\n\t", @backtrace ) ) |
435 |
|
; |
436 |
|
$fatal = qq| frey-fatal|; |
437 |
|
} |
438 |
|
} |
439 |
|
|
440 |
warn "ERROR: $error\n"; |
warn "ERROR: $error\n"; |
441 |
return |
$self->add_icon('error'); |
442 |
qq|<pre class="frey-error">| |
$error = $self->html_links( $error ); |
443 |
. $self->editor_links( $error ) . |
return qq|<pre class="frey-error$fatal">$error $backtrace</pre>| ; |
|
qq|</pre>| |
|
|
; |
|
444 |
} |
} |
445 |
|
|
446 |
=head1 Status line |
=head1 Status line |
455 |
|
|
456 |
sub add_status { |
sub add_status { |
457 |
my ( $self, $data ) = @_; |
my ( $self, $data ) = @_; |
458 |
push @status, { 'X' => [ $self->backtrace ] }; |
die "no data" unless $data; |
459 |
if ( ref($data) ) { |
if ( ref $data ) { |
460 |
push @status, $data; |
push @status, $data; |
461 |
} else { |
} else { |
462 |
if ( defined $status[ $#status ] ) { |
if ( defined $status[ $#status ] ) { |
478 |
sub clean_status { |
sub clean_status { |
479 |
my ($self) = shift; |
my ($self) = shift; |
480 |
@head = ( 'static/frey.css' ); |
@head = ( 'static/frey.css' ); |
|
my $params = { request_url => $self->request_url }; |
|
481 |
@status = ( |
@status = ( |
482 |
{ 'ClassBrowser' => Frey::ClassBrowser->new( %$params, usage_on_top => 0 )->as_markup }, |
{ 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup }, |
483 |
{ 'Bookmarklets' => Frey::Bookmarklet->new( %$params )->as_markup }, |
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
484 |
{ 'INC' => Frey::INC->new( %$params )->as_markup }, |
{ 'INC' => Frey::INC->new->as_markup }, |
485 |
); |
); |
486 |
$icon_html = ''; |
$icon_html = ''; |
487 |
} |
} |
516 |
|
|
517 |
sub icon_path { |
sub icon_path { |
518 |
my ($self,$class,$variant) = @_; |
my ($self,$class,$variant) = @_; |
519 |
my $icon = $class; |
|
520 |
$icon =~ s{::}{/}g; |
sub icon_exists { |
521 |
$icon .= "/$variant" if $variant; |
my $class = shift; |
522 |
my $path = 'static/icons/' . $icon . '.png'; |
$class =~ s{::}{/}g; |
523 |
if ( -e $path ) { |
$class .= "/$variant" if $variant; |
524 |
warn "# $class from $self icon_path $path" if $self->debug; |
my $icon_path = 'static/icons/' . $class . '.png'; |
525 |
return $path; |
return $icon_path if -e $icon_path; |
526 |
} else { |
return; |
527 |
$self->TODO( "add $path icon for $class" ); |
} |
528 |
|
|
529 |
|
my $path = icon_exists( $class ); |
530 |
|
if ( ! $path ) { |
531 |
|
my $super_class = $class; |
532 |
|
while ( $super_class =~ s{::[^:]+$}{} && ! $path ) { |
533 |
|
$path = icon_exists( $super_class ) unless $super_class eq 'Frey'; # don't default on Frey icon |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
|
if ( ! $path ) { |
538 |
|
$self->TODO( "add icon for $class" . ( $variant ? " variant $variant" : '' ) ); |
539 |
return undef; |
return undef; |
540 |
} |
} |
541 |
|
|
542 |
|
warn "# $class from $self icon_path $path" if $self->debug; |
543 |
|
return $path; |
544 |
} |
} |
545 |
|
|
546 |
sub add_icon { |
sub add_icon { |
547 |
my ($self,$variant) = @_; |
my ($self,$variant) = @_; |
548 |
|
|
549 |
my $class = ref($self); |
my $class = $self->class if $self->can('class'); |
550 |
$class = $self->class if $self->can('class'); |
#$class ||= $self->title; |
551 |
|
$class ||= ref($self); |
552 |
my $icon_path = $self->icon_path( $class, $variant ) || return; |
my $icon_path = $self->icon_path( $class, $variant ) || return; |
553 |
|
|
554 |
$icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|; |
$icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|; |
581 |
'"' => '"', |
'"' => '"', |
582 |
}; |
}; |
583 |
|
|
584 |
|
=for later |
585 |
|
|
586 |
my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']'; |
my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']'; |
587 |
warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re"; |
warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re"; |
588 |
|
|
589 |
|
=cut |
590 |
|
|
591 |
sub log_path { |
sub log_path { |
592 |
$Frey::Bootstrap::log_path || die "no log_path?"; |
$Frey::Bootstrap::log_path || die "no log_path?"; |
593 |
} |
} |
594 |
|
|
595 |
|
our $pwd = `pwd`; |
596 |
|
chomp $pwd; |
597 |
|
|
598 |
|
sub strip_full_path { |
599 |
|
my ($self, $msg) = @_; |
600 |
|
# Mojo seems to expand warn messages to full path which is annoying |
601 |
|
$msg =~ s{/[^/]+/\.\./}{/}gs; |
602 |
|
$msg =~ s{$pwd/*}{}gs; |
603 |
|
return $msg; |
604 |
|
} |
605 |
|
|
606 |
|
our $last_log_pos = 0; |
607 |
|
our $last_log_line = 0; |
608 |
|
|
609 |
sub warnings_html { |
sub warnings_html { |
610 |
my ($self,$level) = shift; |
my ($self,$level) = shift; |
611 |
$level ||= $self->debug, |
$level ||= $self->debug, |
614 |
my $max = 30; |
my $max = 30; |
615 |
my $pos = 0; |
my $pos = 0; |
616 |
my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines |
my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines |
617 |
my $line = 0; |
my $line = $last_log_line; |
618 |
my $multiline_end; |
my $multiline_end; |
619 |
|
|
620 |
# XXX do we really want to do this every time? |
# XXX do we really want to do this every time? |
628 |
} |
} |
629 |
$self->add_css( $css ); |
$self->add_css( $css ); |
630 |
|
|
631 |
open(my $log, '<', $path) || die "can't open $path: $!"; |
open(my $log, '<', $path) || die "can't open $path: $!"; |
632 |
|
seek($log, $last_log_pos, 0) || warn "can't seek: $!"; |
633 |
while(<$log>) { |
while(<$log>) { |
634 |
chomp; |
chomp; |
635 |
$line++; |
$line++; |
660 |
if ( m{^(#*)} ) { |
if ( m{^(#*)} ) { |
661 |
|
|
662 |
my $level = $1; |
my $level = $1; |
663 |
my $msg = $_; |
my $msg = $self->strip_full_path( $_ ); |
664 |
|
|
665 |
my $spacer = ' '; |
my $spacer = ' '; |
666 |
my $real_msg = expand( $msg ); |
my $real_msg = expand( $msg ); |
685 |
$warnings[ $pos++ % $max ] = $msg; |
$warnings[ $pos++ % $max ] = $msg; |
686 |
} |
} |
687 |
} |
} |
688 |
warn "log has $line lines tell position ",tell($log); |
$last_log_pos = tell($log); |
689 |
|
$last_log_line = $line; |
690 |
|
warn "log has $line lines tell position $last_log_pos"; |
691 |
close($log) || die "can't close $path: $!"; |
close($log) || die "can't close $path: $!"; |
692 |
|
|
693 |
my $size = -s $path; |
my $size = -s $path; |
701 |
return |
return |
702 |
# need to wrap editor link into span so we can have links in warnings |
# need to wrap editor link into span so we can have links in warnings |
703 |
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>| |
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>| |
704 |
. $self->editor_links( $warnings ) |
. $self->html_links( $warnings ) |
705 |
. qq|</code></span></a>| |
. qq|</code></span>| |
706 |
; |
; |
707 |
} |
} |
708 |
|
|
719 |
my ($self) = @_; |
my ($self) = @_; |
720 |
|
|
721 |
my @backtrace; |
my @backtrace; |
722 |
foreach ( 0 .. 5 ) { |
foreach ( 1 .. 5 ) { # 0 = backtrace |
723 |
my ( |
my ( |
724 |
$package,$path,$line |
$package,$path,$line |
725 |
# subroutine hasargs |
# subroutine hasargs |
728 |
) = caller($_) or last; |
) = caller($_) or last; |
729 |
|
|
730 |
push @backtrace, |
push @backtrace, |
731 |
qq|via $package at $path line $line|; |
qq|via "$package" at $path line $line|; |
732 |
} |
} |
733 |
#warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
#warn "# backtrace: ", dump( @backtrace ) if @backtrace; |
734 |
return @backtrace; |
return @backtrace; |
735 |
} |
} |
736 |
|
|
737 |
|
=head2 checkbox |
738 |
|
|
739 |
|
Generate checkbox html markup from some attribute |
740 |
|
|
741 |
|
my $html = $self->checkbox('attribute_name', $value); |
742 |
|
|
743 |
|
=cut |
744 |
|
|
745 |
|
sub checkbox { |
746 |
|
my ($self,$name,$value) = @_; |
747 |
|
my $checked = ''; |
748 |
|
my $all_checkboxes = eval { $self->$name }; |
749 |
|
warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@; |
750 |
|
$all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty |
751 |
|
$checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes; |
752 |
|
warn "# checkbox $name $value $checked\t", $self->dump( $self->$name ); |
753 |
|
qq|<input name="$name" value="$value" type="checkbox"$checked>|; |
754 |
|
} |
755 |
|
|
756 |
|
=head2 strip |
757 |
|
|
758 |
|
Strip whitespace around content |
759 |
|
|
760 |
|
my $stripped = strip(' no more whitespace around this '); |
761 |
|
|
762 |
|
=cut |
763 |
|
|
764 |
|
sub strip { |
765 |
|
my $t = shift; |
766 |
|
$t =~ s{^\s+}{}gs; |
767 |
|
$t =~ s{>\s+<}{><}gs; |
768 |
|
$t =~ s{\s+$}{}gs; |
769 |
|
return $t; |
770 |
|
} |
771 |
|
|
772 |
1; |
1; |