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/; |
11 |
use File::Slurp; |
use File::Slurp; |
12 |
|
|
13 |
|
use Frey::Bookmarklet; |
14 |
|
use Frey::ClassBrowser; |
15 |
|
|
16 |
has 'head' => ( |
has 'head' => ( |
17 |
is => 'rw', |
is => 'rw', |
18 |
isa => 'ArrayRef[Str]', |
isa => 'ArrayRef[Str]', |
19 |
default => sub { [ 'static/frey.css' ] }, |
default => sub { [ 'static/frey.css' ] }, |
20 |
); |
); |
21 |
|
|
22 |
|
has 'status' => ( |
23 |
|
is => 'rw', |
24 |
|
isa => 'ArrayRef[HashRef[Str]]', |
25 |
|
lazy => 1, |
26 |
|
default => sub { [ |
27 |
|
{ 'Bookmarklets' => Frey::Bookmarklet->new->markup }, |
28 |
|
{ 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->markup }, |
29 |
|
] }, |
30 |
|
); |
31 |
|
|
32 |
|
has 'request_url' => ( |
33 |
|
is => 'rw', |
34 |
|
isa => 'Uri', coerce => 1, |
35 |
|
default => '/', |
36 |
|
); |
37 |
|
|
38 |
|
has 'title' => ( |
39 |
|
is => 'rw', |
40 |
|
isa => 'Str', |
41 |
|
lazy => 1, |
42 |
|
default => sub { |
43 |
|
my ($self) = @_; |
44 |
|
ref($self); |
45 |
|
}, |
46 |
|
); |
47 |
|
|
48 |
=head2 inline_smaller_than |
=head2 inline_smaller_than |
49 |
|
|
50 |
Inline JavaScript and CSS smaller than this size into page reducing |
Inline JavaScript and CSS smaller than this size into page reducing |
128 |
|
|
129 |
=cut |
=cut |
130 |
|
|
|
use Frey::Bookmarklet; |
|
|
use Frey::ClassBrowser; |
|
|
|
|
131 |
sub page { |
sub page { |
132 |
my $self = shift; |
my $self = shift; |
133 |
my $a = {@_}; |
my $a = {@_}; |
134 |
|
|
135 |
$reload_counter++; |
$reload_counter++; |
136 |
|
|
137 |
my $html = qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>| |
my $status_line = ''; |
138 |
. $self->_head_html |
foreach my $part ( @{ $self->status } ) { |
139 |
. '<title>' . ( $a->{title} || ref($self) ) . '</title>' |
if ( ref($part) ne 'HASH' ) { |
140 |
. ( $a->{head} || '' ) |
warn "part not hash ",dump( $part ) ; |
141 |
. '</head><body>' |
#$self->status( $part ); |
142 |
. ( $a->{body} || '<!-- no body -->' ) |
next; |
143 |
. qq|<div class="frey-status-line"> |
} |
144 |
<a href="/">Frey</a> $Frey::VERSION |
foreach my $name ( keys %$part ) { |
145 |
<a href="?reload=$reload_counter"><code>| . dump( $ENV{'REQUEST_URI'} ) . qq|</code></a> |
my $content = $part->{$name}; |
146 |
<span class="frey-popup">Bookmarklets<span>| . Frey::Bookmarklet->markup . qq|</span></span> |
if ( ref($content) ) { |
147 |
<span class="frey-popup">ClassBrowser<span>| . Frey::ClassBrowser->markup . qq|</span></span> |
$content = '<code>' . dump($content) . '</code>'; |
148 |
<span class="frey-popup">ENV<span><code>| . dump( %ENV ) . qq|</code></span></span> |
my $l = length($content); |
149 |
|
$content = qq|<span>$l bytes</span>| if $l > 1024; |
150 |
|
} else { |
151 |
|
$content = qq|<span>$content</span>|; |
152 |
|
} |
153 |
|
warn "### part [$name] = ", length( $content ), " bytes" if $self->debug; |
154 |
|
$status_line .= qq|<span class="frey-popup">$name $content</span>\n|; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
my $html = join("\n", |
159 |
|
qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|, |
160 |
|
$self->_head_html, |
161 |
|
'<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>', |
162 |
|
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', |
163 |
|
( $a->{head} || '' ), |
164 |
|
'</head><body>', |
165 |
|
( $a->{body} || $self->markup || '<!-- no body -->' ), |
166 |
|
qq| |
167 |
|
<div class="frey-status-line"> |
168 |
|
<a href="/">Frey</a> $Frey::VERSION |
169 |
|
<a href="?reload=$reload_counter"><code>| . $self->request_url . qq|</code></a> |
170 |
|
$status_line |
171 |
</div> |
</div> |
172 |
</body></html> |
</body></html> |
173 |
|; |
|, |
174 |
|
); |
175 |
|
|
176 |
warn "## >>> page ",length($html), " bytes\n" if $self->debug; |
warn "## >>> page ",length($html), " bytes\n" if $self->debug; |
177 |
|
|
178 |
return $html; |
return $html; |
179 |
} |
} |
180 |
|
|
181 |
|
sub error { |
182 |
|
my $self = shift; |
183 |
|
my $error = join(" ", @_); |
184 |
|
my ($package, $filename, $line) = caller; |
185 |
|
$error .= " at $filename line $line" if $error !~ m{ at }; |
186 |
|
warn "WARN: $error\n"; |
187 |
|
$error =~ s{at\s+(\S+)\s+line\s+(\d+)}{at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
188 |
|
$error =~ s{(via package ")([\w:]+)(")}{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
189 |
|
return qq|<pre class="frey-error">$error</pre>|; |
190 |
|
} |
191 |
|
|
192 |
1; |
1; |