11 |
use File::Slurp; |
use File::Slurp; |
12 |
|
|
13 |
use Frey::Bookmarklet; |
use Frey::Bookmarklet; |
14 |
use Frey::ClassBrowser; |
use Frey::Class::Browser; |
15 |
use Frey::INC; |
use Frey::INC; |
16 |
|
|
17 |
use Frey::SVK; |
use Frey::SVK; |
86 |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
$dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs; |
87 |
$dump = $self->html_escape( $dump ); |
$dump = $self->html_escape( $dump ); |
88 |
$dump =~ s{\Q...\E}{…}gs; |
$dump =~ s{\Q...\E}{…}gs; |
89 |
# $dump =~ $self->editor_links( $dump ); # FIXME include this |
# $dump =~ $self->html_links( $dump ); # FIXME include this |
90 |
return "<code>$dump</code>"; |
return "<code>$dump</code>"; |
91 |
} |
} |
92 |
|
|
93 |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
sub popup { my $self = shift; $self->popup_dropdown('popup', @_); } |
94 |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); } |
95 |
|
|
96 |
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 |
97 |
|
|
98 |
sub popup_dropdown { |
sub popup_dropdown { |
99 |
my ( $self, $type, $name, $content, $full ) = @_; |
my ( $self, $type, $name, $content, $full ) = @_; |
184 |
| ); |
| ); |
185 |
} |
} |
186 |
|
|
187 |
|
sub add_js { |
188 |
|
my ($self,$js) = @_; |
189 |
|
my ( $package, $path, $line ) = caller; |
190 |
|
|
191 |
|
if ( $js =~ m{http.*\.js} ) { |
192 |
|
$self->add_head( qq| |
193 |
|
<script type="text/javascript" src="$js"> |
194 |
|
/* via $package at $path line $line */ |
195 |
|
</script> |
196 |
|
|); |
197 |
|
} else { |
198 |
|
$self->add_head( qq| |
199 |
|
<script type="text/javascript"> |
200 |
|
/* via $package at $path line $line */ |
201 |
|
$js |
202 |
|
</script> |
203 |
|
| ); |
204 |
|
}; |
205 |
|
} |
206 |
|
|
207 |
our $reload_counter = 0; |
our $reload_counter = 0; |
208 |
|
|
209 |
|
|
324 |
qq|>$class</a>|; |
qq|>$class</a>|; |
325 |
} |
} |
326 |
|
|
327 |
=head2 editor_links |
=head2 html_links |
328 |
|
|
329 |
Create HTML links to editor for perl error message |
Create HTML links to editor for perl error message |
330 |
|
|
331 |
my $html = $self->editor_links( $error ) |
my $html = $self->html_links( $error ) |
332 |
|
|
333 |
=cut |
=cut |
334 |
|
|
335 |
sub editor_links { |
sub html_links { |
336 |
my ( $self, $error ) = @_; |
my ( $self, $error ) = @_; |
337 |
|
|
338 |
|
$error = $self->strip_full_path( $error ); |
339 |
|
|
340 |
# $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 |
341 |
|
|
342 |
# perl's backtrace |
# perl's backtrace |
354 |
$error =~ s{(method ")(\w+)(" via)} |
$error =~ s{(method ")(\w+)(" via)} |
355 |
{$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm; |
{$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm; |
356 |
|
|
357 |
|
# link paths to editor |
358 |
|
$error =~ s{((?:lib|t)/[\S]+)\s+(\d+\s+bytes)} |
359 |
|
{<a target="editor" href="/editor+$1+1" title="vi $1 [$2]">$1</a>}gsm; |
360 |
|
|
361 |
|
$error =~ s{(class ")([\w:]+)(")} |
362 |
|
{$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm; |
363 |
|
|
364 |
return $error; |
return $error; |
365 |
} |
} |
380 |
if ( $error !~ m{\n$} ) { |
if ( $error !~ m{\n$} ) { |
381 |
if ( my @backtrace = $self->backtrace ) { |
if ( my @backtrace = $self->backtrace ) { |
382 |
$error .= "\n\t" . join( "\n\t", @backtrace ); |
$error .= "\n\t" . join( "\n\t", @backtrace ); |
383 |
$fatal = qq| class="fatal"|; |
$fatal = qq| frey-fatal|; |
384 |
} |
} |
385 |
} |
} |
386 |
|
|
387 |
warn "ERROR: $error\n"; |
warn "ERROR: $error\n"; |
388 |
return |
return |
389 |
qq|<pre class="frey-error$fatal">| |
qq|<pre class="frey-error$fatal">| |
390 |
. $self->editor_links( $error ) . |
. $self->html_links( $error ) . |
391 |
qq|</pre>| |
qq|</pre>| |
392 |
; |
; |
393 |
} |
} |
428 |
my ($self) = shift; |
my ($self) = shift; |
429 |
@head = ( 'static/frey.css' ); |
@head = ( 'static/frey.css' ); |
430 |
@status = ( |
@status = ( |
431 |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
{ 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup }, |
432 |
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
433 |
{ 'INC' => Frey::INC->new->as_markup }, |
{ 'INC' => Frey::INC->new->as_markup }, |
434 |
); |
); |
466 |
sub icon_path { |
sub icon_path { |
467 |
my ($self,$class,$variant) = @_; |
my ($self,$class,$variant) = @_; |
468 |
my $icon = $class; |
my $icon = $class; |
469 |
|
$icon ||= $self->title; |
470 |
$icon =~ s{::}{/}g; |
$icon =~ s{::}{/}g; |
471 |
$icon .= "/$variant" if $variant; |
$icon .= "/$variant" if $variant; |
472 |
my $path = 'static/icons/' . $icon . '.png'; |
my $path = 'static/icons/' . $icon . '.png'; |
527 |
$Frey::Bootstrap::log_path || die "no log_path?"; |
$Frey::Bootstrap::log_path || die "no log_path?"; |
528 |
} |
} |
529 |
|
|
|
our $last_log_pos = 0; |
|
|
our $last_log_line = 0; |
|
|
|
|
530 |
our $pwd = `pwd`; |
our $pwd = `pwd`; |
531 |
chomp $pwd; |
chomp $pwd; |
532 |
|
|
533 |
|
sub strip_full_path { |
534 |
|
my ($self, $msg) = @_; |
535 |
|
# Mojo seems to expand warn messages to full path which is annoying |
536 |
|
$msg =~ s{/[^/]+/\.\./}{/}gs; |
537 |
|
$msg =~ s{$pwd/*}{}gs; |
538 |
|
return $msg; |
539 |
|
} |
540 |
|
|
541 |
|
our $last_log_pos = 0; |
542 |
|
our $last_log_line = 0; |
543 |
|
|
544 |
sub warnings_html { |
sub warnings_html { |
545 |
my ($self,$level) = shift; |
my ($self,$level) = shift; |
546 |
$level ||= $self->debug, |
$level ||= $self->debug, |
595 |
if ( m{^(#*)} ) { |
if ( m{^(#*)} ) { |
596 |
|
|
597 |
my $level = $1; |
my $level = $1; |
598 |
my $msg = $_; |
my $msg = $self->strip_full_path( $_ ); |
|
|
|
|
# Mojo seems to expand warn messages to full path which is annoying |
|
|
$msg =~ s{/[^/]+/\.\./}{/}gs; |
|
|
$msg =~ s{$pwd/*}{}gs; |
|
599 |
|
|
600 |
my $spacer = ' '; |
my $spacer = ' '; |
601 |
my $real_msg = expand( $msg ); |
my $real_msg = expand( $msg ); |
636 |
return |
return |
637 |
# 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 |
638 |
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>| |
639 |
. $self->editor_links( $warnings ) |
. $self->html_links( $warnings ) |
640 |
. qq|</code></span>| |
. qq|</code></span>| |
641 |
; |
; |
642 |
} |
} |
669 |
return @backtrace; |
return @backtrace; |
670 |
} |
} |
671 |
|
|
672 |
|
=head2 checkbox |
673 |
|
|
674 |
|
Generate checkbox html markup from some attribute |
675 |
|
|
676 |
|
my $html = $self->checkbox('attribute_name', $value); |
677 |
|
|
678 |
|
=cut |
679 |
|
|
680 |
|
sub checkbox { |
681 |
|
my ($self,$name,$value) = @_; |
682 |
|
my $checked = ''; |
683 |
|
my $all_checkboxes = eval { $self->$name }; |
684 |
|
warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@; |
685 |
|
$all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty |
686 |
|
$checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes; |
687 |
|
warn "# checkbox $name $value $checked\t", $self->dump( $self->$name ); |
688 |
|
qq|<input name="$name" value="$value" type="checkbox"$checked>|; |
689 |
|
} |
690 |
|
|
691 |
|
=head2 strip |
692 |
|
|
693 |
|
Strip whitespace around content |
694 |
|
|
695 |
|
my $stripped = strip(' no more whitespace around this '); |
696 |
|
|
697 |
|
=cut |
698 |
|
|
699 |
|
sub strip { |
700 |
|
my $t = shift; |
701 |
|
$t =~ s{^\s+}{}gs; |
702 |
|
$t =~ s{>\s+<}{><}gs; |
703 |
|
$t =~ s{\s+$}{}gs; |
704 |
|
return $t; |
705 |
|
} |
706 |
|
|
707 |
1; |
1; |