/[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 410 by dpavlin, Tue Nov 18 13:57:52 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/;
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->markup },
29            ] },
30    );
31    
32    has 'request_url' => (
33            is => 'rw',
34            isa => 'Uri', coerce => 1,
35            default => '/',
36    );
37    
38  =head2 inline_smaller_than  =head2 inline_smaller_than
39    
40  Inline JavaScript and CSS smaller than this size into page reducing  Inline JavaScript and CSS smaller than this size into page reducing
# Line 95  our $reload_counter = 0; Line 118  our $reload_counter = 0;
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 = {@_};
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          . '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'                  foreach my $name ( keys %$part ) {
131          . ( $a->{head} || '' )                          my $content = $part->{$name};
132          . '</head><body>'                          if ( ref($content) ) {
133          . ( $a->{body} || '<!-- no body -->' )                                  $content = '<code>' . dump($content) . '</code>';
134          . qq|<div class="frey-status-line">                                  my $l = length($content);
135                  <a href="/">Frey</a> $Frey::VERSION                                  $content = qq|<span>$l bytes</span>| if $l > 1024;
136                  <a href="?reload=$reload_counter"><code>| . dump( $ENV{'REQUEST_URI'} ) . qq|</code></a>                          } else {
137                  <span class="frey-popup">Bookmarklets<span>| . Frey::Bookmarklet->markup . qq|</span></span>                                  $content = qq|<span>$content</span>|;
138                  <span class="frey-popup">ClassBrowser<span>| . Frey::ClassBrowser->markup . qq|</span></span>                          }
139                  <span class="frey-popup">ENV<span><code>| . dump( %ENV ) . qq|</code></span></span>                          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    
# Line 127  sub page { Line 165  sub page {
165  }  }
166    
167  sub error {  sub error {
168          my ( $self, $error ) = @_;          my $self = shift;
169          warn $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          return qq|<pre class="frey-error">$error</pre>|;          return qq|<pre class="frey-error">$error</pre>|;
175  }  }
176    

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

  ViewVC Help
Powered by ViewVC 1.1.26