1 |
package Frey::Web; |
package Frey::Web; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
|
with 'Frey::Backtrace'; |
5 |
|
|
6 |
use Frey::Types; |
use Frey::Types; |
7 |
|
|
8 |
use Continuity::Widget::DomNode; |
use Continuity::Widget::DomNode; |
24 |
isa => 'ArrayRef[HashRef[Str]]', |
isa => 'ArrayRef[HashRef[Str]]', |
25 |
lazy => 1, |
lazy => 1, |
26 |
default => sub { [ |
default => sub { [ |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
|
27 |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
28 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
29 |
] }, |
] }, |
30 |
); |
); |
31 |
|
|
49 |
is => 'rw', |
is => 'rw', |
50 |
isa => 'Str', |
isa => 'Str', |
51 |
default => 'text/html', |
default => 'text/html', |
52 |
|
documentation => 'Content-type header', |
53 |
|
); |
54 |
|
|
55 |
|
has 'dump_max_bytes' => ( |
56 |
|
is => 'rw', |
57 |
|
isa => 'Int', |
58 |
|
default => 4096, |
59 |
|
documentation => 'Maximum dump size sent to browser before truncation', |
60 |
); |
); |
61 |
|
|
62 |
=head2 inline_smaller_than |
=head2 inline_smaller_than |
166 |
if ( ref($content) ) { |
if ( ref($content) ) { |
167 |
$content = '<code>' . dump($content) . '</code>'; |
$content = '<code>' . dump($content) . '</code>'; |
168 |
my $l = length($content); |
my $l = length($content); |
169 |
$content = qq|<span>$l bytes</span>| if $l > 1024; |
$content = qq|<span>$l bytes</span>| if $l > $self->dump_max_bytes; |
170 |
} else { |
} else { |
171 |
$content = qq|<span>$content</span>|; |
$content = qq|<span>$content</span>|; |
172 |
} |
} |
188 |
$body = '<!-- no body -->'; |
$body = '<!-- no body -->'; |
189 |
} |
} |
190 |
|
|
191 |
|
$status_line |
192 |
|
.= qq|<span class="frey-popup">warn<code>| |
193 |
|
. $self->editor_links( join("", $self->warnings ) ) |
194 |
|
. qq|</code></span>| |
195 |
|
if $self->warnings; |
196 |
|
|
197 |
|
my ($exit,$description) = ('exit','stop server'); |
198 |
|
($exit,$description) = ('restart','restart server') |
199 |
|
if $ENV{FREY_RESTART}; # tune labels on exit link |
200 |
|
|
201 |
|
my $right = |
202 |
|
qq| |
203 |
|
<span class="right"> |
204 |
|
<a title="reload" href="/reload$url"><code>$url</code></a> |
205 |
|
<a title="$description" href="/exit$url">$exit</a> |
206 |
|
</span> |
207 |
|
|; |
208 |
|
|
209 |
my $html = join("\n", |
my $html = join("\n", |
210 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
211 |
$self->_head_html, |
$self->_head_html, |
217 |
$body |
$body |
218 |
<div class="frey-status-line"> |
<div class="frey-status-line"> |
219 |
<a href="/">Frey</a> $Frey::VERSION |
<a href="/">Frey</a> $Frey::VERSION |
|
<a href="?reload=$reload_counter"><code>$url</code></a> |
|
220 |
$status_line |
$status_line |
221 |
|
$right |
222 |
</div> |
</div> |
223 |
</body></html> |
</body></html> |
224 |
|, |
|, |
229 |
return $html; |
return $html; |
230 |
} |
} |
231 |
|
|
232 |
|
sub editor_links { |
233 |
|
my ( $self, $error ) = @_; |
234 |
|
|
235 |
|
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
236 |
|
{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
237 |
|
|
238 |
|
$error =~ s{(via package ")([\w:]+)(")} |
239 |
|
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
240 |
|
|
241 |
|
return $error; |
242 |
|
} |
243 |
|
|
244 |
sub error { |
sub error { |
245 |
my $self = shift; |
my $self = shift; |
246 |
my $error = join(" ", @_); |
my $error = join(" ", @_); |
247 |
|
|
248 |
my @backtrace; |
my @backtrace = $self->backtrace; |
249 |
foreach ( 0 .. 5 ) { |
$error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; |
|
my @caller = caller($_) or last; |
|
|
my @description = ( qw/ |
|
|
package filename line |
|
|
subroutine hasargs |
|
|
wantarray evaltext is_require |
|
|
hints bitmask hinthash |
|
|
/); |
|
|
push @backtrace, join(' ', |
|
|
map { |
|
|
$description[$_] . ': ' . dump $caller[$_] |
|
|
} ( 0 .. $#caller ) |
|
|
); |
|
|
} |
|
|
if ( @backtrace ) { |
|
|
warn "# append backtrace: ", dump( @backtrace ); |
|
|
$error .= "\n\t" . join( "\n\t", @backtrace ); |
|
|
} |
|
250 |
|
|
251 |
warn "ERROR: $error\n"; |
warn "ERROR: $error\n"; |
252 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)}{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
return |
253 |
$error =~ s{(via package ")([\w:]+)(")}{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
qq|<pre class="frey-error">| |
254 |
return qq|<pre class="frey-error">$error</pre>|; |
. $self->editor_links( $error ) . |
255 |
|
qq|</pre>| |
256 |
|
; |
257 |
} |
} |
258 |
|
|
259 |
1; |
1; |