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 |
|
|
87 |
return $html; |
return $html; |
88 |
} |
} |
89 |
|
|
90 |
|
# from Mojo::ByteStream |
91 |
|
sub url_escape { |
92 |
|
my ( $self, $url, $pattern ) = @_; |
93 |
|
$pattern ||= 'A-Za-z0-9\-\.\_\~'; |
94 |
|
$url =~ s/([^$pattern])/sprintf('%%%02X',ord($1))/ge; |
95 |
|
return $url; |
96 |
|
} |
97 |
|
|
98 |
sub html_dump { |
sub html_dump { |
99 |
my ( $self, $dump ) = @_; |
my ( $self, $dump ) = @_; |
100 |
$dump = dump( $dump ) if ref($dump); |
$dump = dump( $dump ) if ref($dump); |
208 |
$content |
$content |
209 |
<!-- $type via $package at $path line $line --> |
<!-- $type via $package at $path line $line --> |
210 |
|; |
|; |
211 |
} elsif ( $content =~ m{^(/|https?://)} ) { |
} elsif ( $content =~ m{^(/\w+|https?://)} && $content !~ m{[\n\r]} ) { |
212 |
if ( $what eq 'js' ) { |
if ( $what eq 'js' ) { |
213 |
$head = qq| |
$head = qq| |
214 |
<$tag type="$type" src="$content"> |
<$tag type="$type" src="$content"> |
245 |
our $reload_counter = 0; |
our $reload_counter = 0; |
246 |
|
|
247 |
|
|
248 |
=head2 page |
=head2 html_page |
249 |
|
|
250 |
$self->page( |
$self->html_page( |
251 |
title => 'page title', |
title => 'page title', |
252 |
head => '<!-- optional head markup -->', |
head => '<!-- optional head markup -->', |
253 |
body => '<b>Page Body</b>', |
body => '<b>Page Body</b>', |
260 |
|
|
261 |
our $icon_html; |
our $icon_html; |
262 |
|
|
263 |
sub page { |
sub html_page { |
264 |
my $self = shift; |
my $self = shift; |
265 |
my $a = {@_}; |
my $a = {@_}; |
266 |
|
|
283 |
warn "# no body, invoke $self->$run on ", ref($self); |
warn "# no body, invoke $self->$run on ", ref($self); |
284 |
$body = $self->$run; |
$body = $self->$run; |
285 |
} |
} |
286 |
if ( $self->content_type !~ m{html} ) { |
if ( $self->content_type !~ m{html} || ! $self->wrap_in_page ) { |
287 |
warn "# return only $self body ", $self->content_type; |
warn "# return only $self body ", $self->content_type; |
288 |
return $body |
return $body |
289 |
} elsif ( ! defined $body ) { |
} elsif ( ! defined $body ) { |
312 |
|
|
313 |
$self->add_icon unless $icon_html; |
$self->add_icon unless $icon_html; |
314 |
|
|
315 |
|
my $title = undef |
316 |
|
|| $a->{title} |
317 |
|
|| $self->title |
318 |
|
|| ref($self) |
319 |
|
; |
320 |
|
|
321 |
|
# $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes |
322 |
|
|
323 |
my $html = join("\n", |
my $html = join("\n", |
324 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
325 |
$self->_head_html, |
$self->_head_html, |
326 |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
qq|<title>$title</title>|, |
327 |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
328 |
( $icon_html || '<!-- no icon -->' ), |
( $icon_html || '<!-- no icon -->' ), |
329 |
( $a->{head} || '' ), |
( $a->{head} || '' ), |