1 |
package Frey::Web; |
package Frey::Web; |
2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
|
#with 'Frey::Escape'; |
5 |
|
|
6 |
use Frey::Types; |
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 cluck/; |
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]', |
24 |
isa => 'ArrayRef[HashRef[Str]]', |
isa => 'ArrayRef[HashRef[Str]]', |
25 |
lazy => 1, |
lazy => 1, |
26 |
default => sub { [ |
default => sub { [ |
27 |
{ 'Bookmarklets' => Frey::Bookmarklet->markup }, |
{ 'Bookmarklets' => Frey::Bookmarklet->new->markup }, |
28 |
{ 'ClassBrowser' => Frey::ClassBrowser->markup }, |
{ 'ClassBrowser' => Frey::ClassBrowser->new->markup }, |
29 |
] }, |
] }, |
30 |
); |
); |
31 |
|
|
32 |
has 'urequest_url' => ( |
has 'request_url' => ( |
33 |
is => 'rw', |
is => 'rw', |
34 |
isa => 'Uri', coerce => 1, |
isa => 'Uri', coerce => 1, |
35 |
default => '/', |
default => '/', |
118 |
|
|
119 |
=cut |
=cut |
120 |
|
|
|
use Frey::Bookmarklet; |
|
|
use Frey::ClassBrowser; |
|
|
|
|
121 |
sub page { |
sub page { |
122 |
my $self = shift; |
my $self = shift; |
123 |
my $a = {@_}; |
my $a = {@_}; |
126 |
|
|
127 |
my $status_line = ''; |
my $status_line = ''; |
128 |
foreach my $part ( @{ $self->status } ) { |
foreach my $part ( @{ $self->status } ) { |
129 |
|
confess "part not hash ",dump( $part ) unless ref($part) eq 'HASH'; |
130 |
foreach my $name ( keys %$part ) { |
foreach my $name ( keys %$part ) { |
131 |
warn "### part [$name] = ", length( $part->{name} ), " bytes" if $self->debug; |
my $content = $part->{$name}; |
132 |
$status_line .= qq|<span class="frey-popup">$name<span>| . $part->{$name} . qq|</span></span>|; |
if ( ref($content) ) { |
133 |
|
$content = '<code>' . dump($content) . '</code>'; |
134 |
|
my $l = length($content); |
135 |
|
$content = qq|<span>$l bytes</span>| if $l > 1024; |
136 |
|
} else { |
137 |
|
$content = qq|<span>$content</span>|; |
138 |
|
} |
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 |
|
|
152 |
qq| |
qq| |
153 |
<div class="frey-status-line"> |
<div class="frey-status-line"> |
154 |
<a href="/">Frey</a> $Frey::VERSION |
<a href="/">Frey</a> $Frey::VERSION |
155 |
<a href="?reload=$reload_counter"><code>| . $self->urequest_url . qq|</code></a> |
<a href="?reload=$reload_counter"><code>| . $self->request_url . qq|</code></a> |
156 |
$status_line |
$status_line |
157 |
</div> |
</div> |
158 |
</body></html> |
</body></html> |
165 |
} |
} |
166 |
|
|
167 |
sub error { |
sub error { |
168 |
my ( $self, $error ) = @_; |
my $self = shift; |
169 |
cluck $error; |
my $error = join(" ", @_); |
170 |
$error =~ s{at\s+(\S+)\s+line\s+(\d+)}{ <a href="/editor$1+$2" target="editor">$1</a> line $2}gsm; |
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 target="editor" href="/editor+$1+$2">$1</a> line $2}gsm; |
174 |
|
$error =~ s{(via package ")([\w:]+)(")}{$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm; |
175 |
return qq|<pre class="frey-error">$error</pre>|; |
return qq|<pre class="frey-error">$error</pre>|; |
176 |
} |
} |
177 |
|
|