--- trunk/lib/Frey/Web.pm 2008/11/19 19:11:52 465 +++ trunk/lib/Frey/Web.pm 2008/11/20 14:39:43 480 @@ -24,8 +24,8 @@ isa => 'ArrayRef[HashRef[Str]]', lazy => 1, default => sub { [ - { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, + { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, ] }, ); @@ -49,6 +49,14 @@ is => 'rw', isa => 'Str', default => 'text/html', + documentation => 'Content-type header', +); + +has 'dump_max_bytes' => ( + is => 'rw', + isa => 'Int', + default => 4096, + documentation => 'Maximum dump size sent to browser before truncation', ); =head2 inline_smaller_than @@ -158,7 +166,7 @@ if ( ref($content) ) { $content = '' . dump($content) . ''; my $l = length($content); - $content = qq|$l bytes| if $l > 1024; + $content = qq|$l bytes| if $l > $self->dump_max_bytes; } else { $content = qq|$content|; } @@ -180,6 +188,24 @@ $body = ''; } + $status_line + .= qq|warn| + . $self->editor_links( join("", $self->warnings ) ) + . qq|| + if $self->warnings; + + my ($exit,$description) = ('exit','stop server'); + ($exit,$description) = ('restart','restart server') + if $ENV{FREY_RESTART}; # tune labels on exit link + + my $right = + qq| + + $url + $exit + + |; + my $html = join("\n", qq||, $self->_head_html, @@ -191,8 +217,8 @@ $body
Frey $Frey::VERSION - $url $status_line + $right
|, @@ -203,6 +229,43 @@ return $html; } +=head2 editor + +Create HTML editor link with optional line and title + + my $html = $self->editor( $class, $line, $title ); + +=cut + +sub editor { + my ( $self, $class, $line, $title ) = @_; + confess "need class" unless $class; + $line ||= 1; + qq|$class|; +} + +=head2 editor_links + +Create HTML links to editor for perl error message + + my $html = $self->editor_links( $error ) + +=cut + +sub editor_links { + my ( $self, $error ) = @_; + + $error =~ s{at\s+(\S+)\s+line\s+(\d+)} + {at $1 line $2}gsm; + + $error =~ s{(via package ")([\w:]+)(")} + {$1$2$3}gsm; + + return $error; +} + sub error { my $self = shift; my $error = join(" ", @_); @@ -211,12 +274,11 @@ $error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; warn "ERROR: $error\n"; - $error =~ s{at\s+(\S+)\s+line\s+(\d+)} - {at $1 line $2}gsm; - $error =~ s{(via package ")([\w:]+)(")} - {$1$2$3}gsm; - - return qq|
$error
|; + return + qq|
|
+		. $self->editor_links( $error ) .
+		qq|
| + ; } 1;