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); |
134 |
|
|
135 |
sub _inline { |
sub _inline { |
136 |
my ( $self, $path ) = @_; |
my ( $self, $path ) = @_; |
137 |
|
return unless defined $path; |
138 |
warn "# _inline $path"; |
warn "# _inline $path"; |
139 |
-e $path && -s $path < $self->inline_smaller_than && -s $path; |
-e $path && -s $path < $self->inline_smaller_than && -s $path; |
140 |
} |
} |
203 |
|
|
204 |
my ( $package, $path, $line ) = caller(1); |
my ( $package, $path, $line ) = caller(1); |
205 |
|
|
206 |
if ( $content =~ m{\.(js|css)} ) { |
$content = "/$content" if $content !~ m{[\n\r]} && -e $content; |
207 |
$content = "/$content" if -e $content; |
if ( $content =~ $re_html ) { |
208 |
if ( $content =~ $re_html ) { |
$head = qq| |
209 |
$head = qq| |
$content |
210 |
$content |
<!-- $type via $package at $path line $line --> |
211 |
<!-- $type via $package at $path line $line --> |
|; |
212 |
|; |
} elsif ( $content =~ m{^(/\w+|https?://)} && $content !~ m{[\n\r]} ) { |
213 |
} elsif ( $what eq 'js' ) { |
if ( $what eq 'js' ) { |
214 |
$head = qq| |
$head = qq| |
215 |
<$tag type="$type" src="$content"> |
<$tag type="$type" src="$content"> |
216 |
/* $what via $package at $path line $line */ |
/* $what via $package at $path line $line */ |
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 ) { |
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} || '' ), |
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 ] ) { |