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 { [ |
27 |
{ 'Bookmarklets' => Frey::Bookmarklet->new->markup }, |
{ 'Bookmarklets' => Frey::Bookmarklet->new->as_markup }, |
28 |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->markup }, |
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup }, |
29 |
] }, |
] }, |
30 |
); |
); |
31 |
|
|
45 |
}, |
}, |
46 |
); |
); |
47 |
|
|
48 |
|
has 'content_type' => ( |
49 |
|
is => 'rw', |
50 |
|
isa => 'Str', |
51 |
|
default => 'text/html', |
52 |
|
); |
53 |
|
|
54 |
=head2 inline_smaller_than |
=head2 inline_smaller_than |
55 |
|
|
56 |
Inline JavaScript and CSS smaller than this size into page reducing |
Inline JavaScript and CSS smaller than this size into page reducing |
170 |
my $url = $self->request_url; |
my $url = $self->request_url; |
171 |
$url =~ s{\?reload=\d+}{}; |
$url =~ s{\?reload=\d+}{}; |
172 |
|
|
173 |
|
my $body = $a->{body}; |
174 |
|
$body ||= $self->as_markup if $self->can('as_markup'); |
175 |
|
if ( $self->content_type !~ m{html} ) { |
176 |
|
warn "# return only $self body ", $self->content_type; |
177 |
|
return $body |
178 |
|
} elsif ( ! defined $body ) { |
179 |
|
warn "# no body"; |
180 |
|
$body = '<!-- no body -->'; |
181 |
|
} |
182 |
|
|
183 |
my $html = join("\n", |
my $html = join("\n", |
184 |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
185 |
$self->_head_html, |
$self->_head_html, |
186 |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
187 |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
188 |
( $a->{head} || '' ), |
( $a->{head} || '' ), |
|
'</head><body>', |
|
|
( $a->{body} || $self->markup || '<!-- no body -->' ), |
|
189 |
qq| |
qq| |
190 |
|
</head><body> |
191 |
|
$body |
192 |
<div class="frey-status-line"> |
<div class="frey-status-line"> |
193 |
<a href="/">Frey</a> $Frey::VERSION |
<a href="/">Frey</a> $Frey::VERSION |
194 |
<a href="?reload=$reload_counter"><code>$url</code></a> |
<a href="?reload=$reload_counter"><code>$url</code></a> |
206 |
sub error { |
sub error { |
207 |
my $self = shift; |
my $self = shift; |
208 |
my $error = join(" ", @_); |
my $error = join(" ", @_); |
209 |
my ($package, $filename, $line) = caller; |
|
210 |
$error .= " at $filename line $line" if $error !~ m{ at }; |
my @backtrace = $self->backtrace; |
211 |
warn "WARN: $error\n"; |
$error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace; |
212 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)}{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
|
213 |
$error =~ s{(via package ")([\w:]+)(")}{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
warn "ERROR: $error\n"; |
214 |
|
$error =~ s{at\s+(\S+)\s+line\s+(\d+)} |
215 |
|
{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
216 |
|
$error =~ s{(via package ")([\w:]+)(")} |
217 |
|
{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
218 |
|
|
219 |
return qq|<pre class="frey-error">$error</pre>|; |
return qq|<pre class="frey-error">$error</pre>|; |
220 |
} |
} |
221 |
|
|