/[Frey]/trunk/lib/Frey/Web.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Web.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 385 by dpavlin, Mon Nov 17 20:14:12 2008 UTC revision 397 by dpavlin, Tue Nov 18 01:45:44 2008 UTC
# Line 1  Line 1 
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/;
# Line 12  has 'head' => ( Line 16  has 'head' => (
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
# Line 104  sub page { Line 124  sub page {
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>'                  foreach my $name ( keys %$part ) {
130          . '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'                          my $content = $part->{$name};
131          . ( $a->{head} || '' )                          if ( ref($content) ) {
132          . '</head><body>'                                  $content = '<code>' . dump($content) . '</code>';
133          . ( $a->{body} || '<!-- no body -->' )                                  my $l = length($content);
134          . qq|<div class="frey-status-line">                                  $content = qq|<span>$l bytes</span>| if $l > 1024;
135                  <a href="/">Frey</a> $Frey::VERSION                          } else {
136                  <a href="?reload=$reload_counter"><code>| . dump( $ENV{'REQUEST_URI'} ) . qq|</code></a>                                  $content = qq|<span>$content</span>|;
137                  <span class="frey-popup">Bookmarklets<span>| . Frey::Bookmarklet->markup . qq|</span></span>                          }
138                  <span class="frey-popup">ClassBrowser<span>| . Frey::ClassBrowser->markup . qq|</span></span>                          warn "### part [$name] = ", length( $content ), " bytes" if $self->debug;
139                  <span class="frey-popup">ENV<span><code>| . dump( %ENV ) . qq|</code></span></span>                          $status_line .= qq|<span class="frey-popup">$name $content</span>\n|;
140                    }
141            }
142    
143            my $html = join("\n",
144                    qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,
145                    $self->_head_html,
146                    '<title>' . ( $a->{title} || ref($self) ) . '</title>',
147                    '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
148                    ( $a->{head} || '' ),
149                    '</head><body>',
150                    ( $a->{body} || '<!-- no body -->' ),
151                    qq|
152                    <div class="frey-status-line">
153                            <a href="/">Frey</a> $Frey::VERSION
154                            <a href="?reload=$reload_counter"><code>| . $self->request_url . qq|</code></a>
155                            $status_line
156                  </div>                  </div>
157              </body></html>              </body></html>
158          |;                  |,
159            );
160    
161          warn "## >>> page ",length($html), " bytes\n" if $self->debug;          warn "## >>> page ",length($html), " bytes\n" if $self->debug;
162    
# Line 127  sub page { Line 164  sub page {
164  }  }
165    
166  sub error {  sub error {
167          my ( $self, $error ) = @_;          my $self = shift;
168          warn $error;          my $error = join(" ", @_);
169          $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;
170            $error .= " at $filename line $line";
171            warn "WARN: $error\n";
172            $error =~ s{at\s+(\S+)\s+line\s+(\d+)}{at <a href="/editor$1+$2" target="editor">$1</a> line $2}gsm;
173          return qq|<pre class="frey-error">$error</pre>|;          return qq|<pre class="frey-error">$error</pre>|;
174  }  }
175    

Legend:
Removed from v.385  
changed lines
  Added in v.397

  ViewVC Help
Powered by ViewVC 1.1.26