/[Frey]/branches/zimbardo/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 /branches/zimbardo/lib/Frey/Web.pm

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

revision 564 by dpavlin, Thu Nov 27 21:31:02 2008 UTC revision 584 by dpavlin, Fri Nov 28 13:25:17 2008 UTC
# Line 16  use Frey::INC; Line 16  use Frey::INC;
16    
17  use Frey::SVK;  use Frey::SVK;
18    
19  has 'head' => (  our @head;
20          is => 'rw',  sub head { @head }
         isa => 'ArrayRef[Str]',  
         default => sub { [ 'static/frey.css' ] },  
 );  
21    
22  has 'request_url' => (  has 'request_url' => (
23          is => 'rw',          is => 'rw',
# Line 83  sub html_dump { Line 80  sub html_dump {
80          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;
81          $dump = $self->html_escape( $dump );          $dump = $self->html_escape( $dump );
82          $dump =~ s{\Q...\E}{…}gs;          $dump =~ s{\Q...\E}{…}gs;
83    #       $dump =~ $self->editor_links( $dump ); # FIXME include this
84          return "<code>$dump</code>";          return "<code>$dump</code>";
85  }  }
86    
# Line 98  sub popup_dropdown { Line 96  sub popup_dropdown {
96    
97          $content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*};          $content = qq|<span>$content</span>| unless $content =~ m{^\s*<(span|a|code).+?/\1>\s*};
98    
99            $content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span");
100    
101          warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug;          warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug;
102    
103          if ( $name =~ m{::} && $name !~ $re_html ) {          if ( $name =~ m{::} && $name !~ $re_html ) {
# Line 115  sub _inline_path { Line 115  sub _inline_path {
115  sub _head_html {  sub _head_html {
116          my $self = shift;          my $self = shift;
117          my $out = '';          my $out = '';
118          foreach my $path ( @{ $self->head } ) {          foreach my $path ( @head ) {
119                  $path =~ s!^/!!;                  $path =~ s!^/!!;
120                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
121                          $out .= $self->_inline_path( $path ) ?                          $out .= $self->_inline_path( $path ) ?
# Line 151  sub add_head { Line 151  sub add_head {
151          $path =~ s!^/!!;          $path =~ s!^/!!;
152    
153          if ( $path =~ $re_html ) {          if ( $path =~ $re_html ) {
154                  push @{ $self->head }, $path;                  push @head, $path;
155          } elsif ( -e $path ) {          } elsif ( -e $path ) {
156                  if ( $path =~ m/\.(?:js|css)$/ ) {                  if ( $path =~ m/\.(?:js|css)$/ ) {
157                          push @{ $self->head }, $path;                          push @head, $path;
158                  } else {                  } else {
159                          confess "can't add_head( $path ) it's not js or css";                          confess "can't add_head( $path ) it's not js or css";
160                  }                  }
# Line 165  sub add_head { Line 165  sub add_head {
165    
166  }  }
167    
168    sub add_css {
169            my ($self,$css) = @_;
170            my ( $package, $path, $line ) = caller;
171            $self->add_head( qq|
172            <style type="text/css">
173            /* via $package at $path line $line */
174            $css
175            </style>
176            | );
177    }
178    
179  our $reload_counter = 0;  our $reload_counter = 0;
180    
181    
# Line 193  sub page { Line 204  sub page {
204    
205          my $status_line = '';          my $status_line = '';
206    
         unshift @status, { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup };  
 #       unshift @status, { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup };  
         unshift @status, { 'INC' => Frey::INC->new->as_markup };  
   
207          foreach my $part ( @status ) {          foreach my $part ( @status ) {
208                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
209                          $status_line .= $self->popup( $name, $part->{$name} );                          $status_line .= $self->popup( $name, $part->{$name} );
# Line 230  sub page { Line 237  sub page {
237                          </span>                          </span>
238                  |;                  |;
239    
240          my $info = Frey::SVK->info;          my $svk = Frey::SVK->new;
241          my $revision = Frey::SVK->info->{Revision} || '';          my $info = $svk->info;
242            my $revision = $svk->info->{Revision} || '';
243          $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};          $revision = $1 if $info->{'Mirrored From'} =~ m{Rev\.\s+(\d+)};
244    
245          $self->add_icon unless $icon_html;          $self->add_icon unless $icon_html;
# Line 295  sub editor_links { Line 303  sub editor_links {
303          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}
304                  {at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm;                  {at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm;
305    
306          $error =~ s{(via package ")([\w:]+)(")}          $error =~ s{(via (?:package) "?)([\w:]+)("?)}
307                  {$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm;                  {$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm;
308    
309          return $error;          return $error;
# Line 316  sub error { Line 324  sub error {
324                  ;                  ;
325  }  }
326    
327    =head1 Status line
328    
329    =head2 add_status
330    
331      $self->add_status( { name => { some => 'data' } } );
332    
333      $self->add_status( "append to last status popup" );
334    
335    =cut
336    
337  sub add_status {  sub add_status {
338          my ( $self, $data ) = @_;          my ( $self, $data ) = @_;
339          push @status, $data;          push @status, { 'X' => [ $self->backtrace ] };
340            if ( ref($data) ) {
341                    push @status, $data;
342            } else {
343                    if ( defined $status[ $#status ] ) {
344                            $status[ $#status ]->{ '+' } = $data;
345                    } else {
346                            push @status, { '+' => $data };
347                    }
348            }
349  }  }
350    
351    =head2 clean_status
352    
353    Called at beginning of each request
354    
355      $self->clean_status;
356    
357    =cut
358    
359  sub clean_status {  sub clean_status {
360          @status = ();          my ($self) = shift;
361            @head = ( 'static/frey.css' );
362            @status = (
363                    { 'ClassBrowser' => Frey::ClassBrowser->new( usage_on_top => 0 )->as_markup },
364                    { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
365                    { 'INC' => Frey::INC->new->as_markup },
366            );
367          $icon_html = '';          $icon_html = '';
368  }  }
369    
370    =head2 status_parts
371    
372    Dump all status line parts
373    
374      $self->status_parts
375    
376    =cut
377    
378  sub status_parts {  sub status_parts {
379          warn "## status parts ", dump( map { keys %$_ } @status );          warn "## status parts ", dump( map { keys %$_ } @status );
380  }  }
381    
382    =for debug
383    
384  sub DEMOLISH {  sub DEMOLISH {
385          my ( $self ) = @_;          my ( $self ) = @_;
386          warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status;          warn "## $self DEMOLISH status ", $#status + 1, " elements ", dump( map { keys %$_ } @status ) if @status;
387  }  }
388    
389    =cut
390    
391  =head2 add_icon  =head2 add_icon
392    
393    Frey::Foo->add_icon;            # /static/icons/Frey/Foo.png    Frey::Foo->add_icon;            # /static/icons/Frey/Foo.png
# Line 349  sub icon_path { Line 402  sub icon_path {
402          $icon .= "/$variant" if $variant;          $icon .= "/$variant" if $variant;
403          my $path = 'static/icons/' . $icon . '.png';          my $path = 'static/icons/' . $icon . '.png';
404          if ( -e $path ) {          if ( -e $path ) {
405                  warn "# $class from $self icon_path $path";                  warn "# $class from $self icon_path $path" if $self->debug;
406                  return $path;                  return $path;
407          } else {          } else {
408                  $self->TODO( "add $path icon for $class" );                  $self->TODO( "add $path icon for $class" );
# Line 479  sub backtrace { Line 532  sub backtrace {
532                  ) = caller($_) or last;                  ) = caller($_) or last;
533    
534                  push @backtrace,                  push @backtrace,
535                          qq|via $package from $path <a target="editor" href="/editor+$path+$line">$path</a>|;                          qq|via $package at $path line $line|;
536          }          }
537          warn "# backtrace: ", dump( @backtrace ) if @backtrace;          warn "# backtrace: ", dump( @backtrace ) if @backtrace;
538          return @backtrace;          return @backtrace;

Legend:
Removed from v.564  
changed lines
  Added in v.584

  ViewVC Help
Powered by ViewVC 1.1.26