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