12 |
|
|
13 |
use Frey::Bookmarklet; |
use Frey::Bookmarklet; |
14 |
use Frey::ClassBrowser; |
use Frey::ClassBrowser; |
15 |
|
use Frey::SVK; |
16 |
|
|
17 |
has 'head' => ( |
has 'head' => ( |
18 |
is => 'rw', |
is => 'rw', |
25 |
isa => 'ArrayRef[HashRef[Str]]', |
isa => 'ArrayRef[HashRef[Str]]', |
26 |
lazy => 1, |
lazy => 1, |
27 |
default => sub { [ |
default => sub { [ |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
|
28 |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
29 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
30 |
] }, |
] }, |
31 |
); |
); |
32 |
|
|
50 |
is => 'rw', |
is => 'rw', |
51 |
isa => 'Str', |
isa => 'Str', |
52 |
default => 'text/html', |
default => 'text/html', |
53 |
|
documentation => 'Content-type header', |
54 |
|
); |
55 |
|
|
56 |
|
has 'dump_max_bytes' => ( |
57 |
|
is => 'rw', |
58 |
|
isa => 'Int', |
59 |
|
default => 4096, |
60 |
|
documentation => 'Maximum dump size sent to browser before truncation', |
61 |
); |
); |
62 |
|
|
63 |
=head2 inline_smaller_than |
=head2 inline_smaller_than |
167 |
if ( ref($content) ) { |
if ( ref($content) ) { |
168 |
$content = '<code>' . dump($content) . '</code>'; |
$content = '<code>' . dump($content) . '</code>'; |
169 |
my $l = length($content); |
my $l = length($content); |
170 |
$content = qq|<span>$l bytes</span>| if $l > 1024; |
$content = qq|<span>$l bytes</span>| if $l > $self->dump_max_bytes; |
171 |
} else { |
} else { |
172 |
$content = qq|<span>$content</span>|; |
$content = qq|<span>$content</span>|; |
173 |
} |
} |
189 |
$body = '<!-- no body -->'; |
$body = '<!-- no body -->'; |
190 |
} |
} |
191 |
|
|
192 |
|
my $warn_colors = { |
193 |
|
'#' => '#444', |
194 |
|
'##' => '#888', |
195 |
|
}; |
196 |
|
|
197 |
|
$status_line |
198 |
|
.= qq|<span class="frey-popup">warn<span>| |
199 |
|
. $self->editor_links( |
200 |
|
join("", map { |
201 |
|
warn "# $_"; |
202 |
|
my $style = ''; |
203 |
|
$style = $warn_colors->{$1} |
204 |
|
? ' style="color:' . $warn_colors->{$1} . '"' |
205 |
|
: '' |
206 |
|
if m{^(#+)}; |
207 |
|
qq|<tt$style>$_</tt><br/>|; # XXX <tt> should be <code> but CSS hates me |
208 |
|
} $self->warnings ) |
209 |
|
) |
210 |
|
. qq|</span></span>| |
211 |
|
if $self->warnings; |
212 |
|
|
213 |
|
my ($exit,$description) = ('exit','stop server'); |
214 |
|
($exit,$description) = ('restart','restart server') |
215 |
|
if $ENV{FREY_RESTART}; # tune labels on exit link |
216 |
|
|
217 |
|
my $right = |
218 |
|
qq| |
219 |
|
<span class="right"> |
220 |
|
<a title="reload" href="/reload$url"><code>$url</code></a> |
221 |
|
<a title="$description" href="/exit$url">$exit</a> |
222 |
|
</span> |
223 |
|
|; |
224 |
|
|
225 |
|
my $revision = Frey::SVK->info->{Revision} || ''; |
226 |
|
|
227 |
my $html = join("\n", |
my $html = join("\n", |
228 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
229 |
$self->_head_html, |
$self->_head_html, |
234 |
</head><body> |
</head><body> |
235 |
$body |
$body |
236 |
<div class="frey-status-line"> |
<div class="frey-status-line"> |
237 |
<a href="/">Frey</a> $Frey::VERSION |
<a href="/">Frey</a> $Frey::VERSION $revision |
|
<a href="?reload=$reload_counter"><code>$url</code></a> |
|
238 |
$status_line |
$status_line |
239 |
|
$right |
240 |
</div> |
</div> |
241 |
</body></html> |
</body></html> |
242 |
|, |
|, |
247 |
return $html; |
return $html; |
248 |
} |
} |
249 |
|
|
250 |
|
=head2 editor |
251 |
|
|
252 |
|
Create HTML editor link with optional line and title |
253 |
|
|
254 |
|
my $html = $self->editor( $class, $line, $title ); |
255 |
|
|
256 |
|
=cut |
257 |
|
|
258 |
|
sub editor { |
259 |
|
my ( $self, $class, $line, $title ) = @_; |
260 |
|
confess "need class" unless $class; |
261 |
|
$line ||= 1; |
262 |
|
qq|<a target="editor" href="/editor+$class+$line"| . |
263 |
|
( $title ? qq| title="$title"| : '' ) . |
264 |
|
qq|>$class</a>|; |
265 |
|
} |
266 |
|
|
267 |
|
=head2 editor_links |
268 |
|
|
269 |
|
Create HTML links to editor for perl error message |
270 |
|
|
271 |
|
my $html = $self->editor_links( $error ) |
272 |
|
|
273 |
|
=cut |
274 |
|
|
275 |
|
sub editor_links { |
276 |
|
my ( $self, $error ) = @_; |
277 |
|
|
278 |
|
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
279 |
|
{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
280 |
|
|
281 |
|
$error =~ s{(via package ")([\w:]+)(")} |
282 |
|
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
283 |
|
|
284 |
|
return $error; |
285 |
|
} |
286 |
|
|
287 |
sub error { |
sub error { |
288 |
my $self = shift; |
my $self = shift; |
289 |
my $error = join(" ", @_); |
my $error = join(" ", @_); |
292 |
$error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; |
$error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; |
293 |
|
|
294 |
warn "ERROR: $error\n"; |
warn "ERROR: $error\n"; |
295 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
return |
296 |
{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
qq|<pre class="frey-error">| |
297 |
$error =~ s{(via package ")([\w:]+)(")} |
. $self->editor_links( $error ) . |
298 |
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
qq|</pre>| |
299 |
|
; |
300 |
|
} |
301 |
|
|
302 |
return qq|<pre class="frey-error">$error</pre>|; |
sub add_status { |
303 |
|
my ( $self, $data ) = @_; |
304 |
|
push @{ $self->status }, $data; |
305 |
|
warn "## current status ", $#{ $self->status }, " elements"; |
306 |
} |
} |
307 |
|
|
308 |
1; |
1; |