1 |
package Frey::Web; |
package Frey::Web; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
|
#with 'Frey::Escape'; |
5 |
|
|
6 |
|
use Frey::Types; |
7 |
|
|
8 |
use Continuity::Widget::DomNode; |
use Continuity::Widget::DomNode; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use Carp qw/confess/; |
use Carp qw/confess/; |
16 |
default => sub { [ 'static/frey.css' ] }, |
default => sub { [ 'static/frey.css' ] }, |
17 |
); |
); |
18 |
|
|
19 |
|
has 'status' => ( |
20 |
|
is => 'rw', |
21 |
|
isa => 'ArrayRef[HashRef[Str]]', |
22 |
|
lazy => 1, |
23 |
|
default => sub { [ |
24 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->markup }, |
25 |
|
{ 'ClassBrowser' => Frey::ClassBrowser->markup }, |
26 |
|
] }, |
27 |
|
); |
28 |
|
|
29 |
|
has 'request_url' => ( |
30 |
|
is => 'rw', |
31 |
|
isa => 'Uri', coerce => 1, |
32 |
|
default => '/', |
33 |
|
); |
34 |
|
|
35 |
=head2 inline_smaller_than |
=head2 inline_smaller_than |
36 |
|
|
37 |
Inline JavaScript and CSS smaller than this size into page reducing |
Inline JavaScript and CSS smaller than this size into page reducing |
124 |
|
|
125 |
$reload_counter++; |
$reload_counter++; |
126 |
|
|
127 |
my $html = qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>| |
my $status_line = ''; |
128 |
. $self->_head_html |
foreach my $part ( @{ $self->status } ) { |
129 |
. '<title>' . ( $a->{title} || ref($self) ) . '</title>' |
confess "part not hash ",dump( $part ) unless ref($part) eq 'HASH'; |
130 |
. ( $a->{head} || '' ) |
foreach my $name ( keys %$part ) { |
131 |
. '</head><body>' |
my $content = $part->{$name}; |
132 |
. ( $a->{body} || '<!-- no body -->' ) |
if ( ref($content) ) { |
133 |
. qq|<div class="frey-status-line"> |
$content = '<code>' . dump($content) . '</code>'; |
134 |
<a href="/">Frey</a> $Frey::VERSION |
my $l = length($content); |
135 |
<a href="?reload=$reload_counter"><code>| . dump( $ENV{'REQUEST_URI'} ) . qq|</code></a> |
$content = qq|<span>$l bytes</span>| if $l > 1024; |
136 |
<span class="frey-popup">Bookmarklets<span>| . Frey::Bookmarklet->markup . qq|</span></span> |
} else { |
137 |
<span class="frey-popup">ClassBrowser<span>| . Frey::ClassBrowser->markup . qq|</span></span> |
$content = qq|<span>$content</span>|; |
138 |
<span class="frey-popup">ENV<span><code>| . dump( %ENV ) . qq|</code></span></span> |
} |
139 |
|
warn "### part [$name] = ", length( $content ), " bytes" if $self->debug; |
140 |
|
$status_line .= qq|<span class="frey-popup">$name $content</span>\n|; |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
|
my $html = join("\n", |
145 |
|
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
146 |
|
$self->_head_html, |
147 |
|
'<title>' . ( $a->{title} || ref($self) ) . '</title>', |
148 |
|
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
149 |
|
( $a->{head} || '' ), |
150 |
|
'</head><body>', |
151 |
|
( $a->{body} || '<!-- no body -->' ), |
152 |
|
qq| |
153 |
|
<div class="frey-status-line"> |
154 |
|
<a href="/">Frey</a> $Frey::VERSION |
155 |
|
<a href="?reload=$reload_counter"><code>| . $self->request_url . qq|</code></a> |
156 |
|
$status_line |
157 |
</div> |
</div> |
158 |
</body></html> |
</body></html> |
159 |
|; |
|, |
160 |
|
); |
161 |
|
|
162 |
warn "## >>> page ",length($html), " bytes\n" if $self->debug; |
warn "## >>> page ",length($html), " bytes\n" if $self->debug; |
163 |
|
|
164 |
return $html; |
return $html; |
165 |
} |
} |
166 |
|
|
167 |
|
sub error { |
168 |
|
my $self = shift; |
169 |
|
my $error = join(" ", @_); |
170 |
|
my ($package, $filename, $line) = caller; |
171 |
|
$error .= " at $filename line $line" if $error !~ m{ at }; |
172 |
|
warn "WARN: $error\n"; |
173 |
|
$error =~ s{at\s+(\S+)\s+line\s+(\d+)}{at <a href="/editor$1+$2" target="editor">$1</a> line $2}gsm; |
174 |
|
return qq|<pre class="frey-error">$error</pre>|; |
175 |
|
} |
176 |
|
|
177 |
1; |
1; |