/[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 577 by dpavlin, Fri Nov 28 00:30:03 2008 UTC revision 945 by dpavlin, Tue Jan 6 15:26:19 2009 UTC
# Line 3  use Moose::Role; Line 3  use Moose::Role;
3    
4  with 'Frey::Session';  with 'Frey::Session';
5    
 use Frey::Types;  
   
6  #use Continuity::Widget::DomNode;  #use Continuity::Widget::DomNode;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use Carp qw/confess cluck/;  use Carp qw/confess cluck carp/;
9  use File::Slurp;  use File::Slurp;
10    use Text::Tabs; # expand, unexpand
11    
12    use lib 'lib';
13    
14    use Frey::Types;
15    
16  use Frey::Bookmarklet;  use Frey::Bookmarklet;
17  use Frey::ClassBrowser;  use Frey::Class::Browser;
18  use Frey::INC;  use Frey::INC;
19    
20  use Frey::SVK;  use Frey::SVK;
21    
22  our @head = ( 'static/frey.css' );  our @head;
23    sub head { @head }
24    
25  has 'request_url' => (  has 'request_url' => (
26          is => 'rw',          is => 'rw',
27          isa => 'Uri', coerce => 1,          isa => 'Uri', coerce => 1,
28          default => '/',          required => 1,
29            default => sub {
30                    carp "undefined request_url";
31                    '/';
32            },
33  );  );
34    
35  has 'title' => (  has 'title' => (
# Line 60  has 'html_dump_width' => ( Line 68  has 'html_dump_width' => (
68          is => 'rw',          is => 'rw',
69          isa => 'Int',          isa => 'Int',
70  #       required => 1, # FIXME we can't have required fields with defaults because Frey::Action isn't smart enough and asks for them  #       required => 1, # FIXME we can't have required fields with defaults because Frey::Action isn't smart enough and asks for them
71          default => 128,          default => 250,
72  );  );
73    
74  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
# Line 72  sub html_escape { Line 80  sub html_escape {
80          return $html;          return $html;
81  }  }
82    
83    # from Mojo::ByteStream
84    sub url_escape {
85            my ( $self, $url, $pattern ) = @_;
86            $pattern ||= 'A-Za-z0-9\-\.\_\~';
87            $url =~ s/([^$pattern])/sprintf('%%%02X',ord($1))/ge;
88            return $url;
89    }
90    
91  sub html_dump {  sub html_dump {
92          my ( $self, $dump ) = @_;          my ( $self, $dump ) = @_;
93          $dump = dump( $dump ) if ref($dump);          $dump = dump( $dump ) if ref($dump);
# Line 79  sub html_dump { Line 95  sub html_dump {
95          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;
96          $dump = $self->html_escape( $dump );          $dump = $self->html_escape( $dump );
97          $dump =~ s{\Q...\E}{&hellip;}gs;          $dump =~ s{\Q...\E}{&hellip;}gs;
98    #       $dump =~ $self->html_links( $dump ); # FIXME include this
99          return "<code>$dump</code>";          return "<code>$dump</code>";
100  }  }
101    
102  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }
103  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }
104    
105  our $re_html = qr{<(?:!--.+?--|(\w+).+?/\1)>}s; # relaxed html check for one semi-valid tag  our $re_html = qr{<(?:!--|(\w+)|[^>]+)/?>}s; # relaxed html check for one semi-valid tag
106    
107  sub popup_dropdown {  sub popup_dropdown {
108          my ( $self, $type, $name, $content, $full ) = @_;          my ( $self, $type, $name, $content, $full ) = @_;
# Line 94  sub popup_dropdown { Line 111  sub popup_dropdown {
111    
112          $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*};
113    
114          warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug;          $content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span");
115    
116            warn "## $type [$name] = ", length( $content ), " bytes"; # if $self->debug; # FIXME
117    
118          if ( $name =~ m{::} && $name !~ $re_html ) {          if ( $name =~ m{::} && $name !~ $re_html ) {
119                  return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|;                  return qq|<a class="frey-$type" target="$name" href="/$name">$name $content</a>\n|;
120            } elsif ( $name =~ s{^\s*(<a)\s+}{$1 class="frey-$type"} ) {
121                    return qq|$name $content\n|;
122          } else {          } else {
123                  return qq|<span class="frey-$type">$name $content</span>\n|;                  return qq|<span class="frey-$type">$name $content</span>\n|;
124          }          }
125  }  }
126    
127  sub _inline_path {  sub _inline {
128          my ( $self, $path ) = @_;          my ( $self, $path ) = @_;
129          -s $path < $self->inline_smaller_than;          return unless defined $path;
130            warn "# _inline $path";
131            -e $path && -s $path < $self->inline_smaller_than && -s $path;
132  }  }
133    
134  sub _head_html {  sub _head_html {
# Line 114  sub _head_html { Line 137  sub _head_html {
137          foreach my $path ( @head ) {          foreach my $path ( @head ) {
138                  $path =~ s!^/!!;                  $path =~ s!^/!!;
139                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
140                          $out .= $self->_inline_path( $path ) ?                          my $size;
141                                  qq|<!-- $path --><script type="text/javascript">\n| . read_file($path) . qq|\n</script>| :                          $out .= $size = _inline( $path ) ?
142                                    qq|<script type="text/javascript">\n/* inline $path $size bytes */\n\n| . read_file($path) . qq|\n</script>| :
143                                  qq|<script type="text/javascript" src="/$path"></script>|;                                  qq|<script type="text/javascript" src="/$path"></script>|;
144                  } elsif ( $path =~ m/\.css$/ ) {                  } elsif ( $path =~ m/\.css$/ ) {
145                          $out .= $self->_inline_path( $path ) ?                          my $size;
146                                  qq|<!-- $path --><style type="text/css">\n| . read_file( $path ) . qq|\n</style>| :                          $out .= $size = _inline( $path ) ?
147                                    qq|<style type="text/css">\n/* inline $path $size bytes */\n\n| . read_file( $path ) . qq|\n</style>| :
148                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
149                  } elsif ( $path =~ m{<.+>}s ) {                  } elsif ( $path =~ m{<.+>}s ) {
150                          $out .= $path;                          $out .= $path;
# Line 161  sub add_head { Line 186  sub add_head {
186    
187  }  }
188    
189    sub _add_css_js {
190            my ( $self, $what, $content ) = @_;
191    
192            my $tag  = $what eq 'css' ? 'style'    : 'script';
193            my $type = $what eq 'css' ? 'text/css' : 'text/javascript';
194            my $head;
195    
196            my ( $package, $path, $line ) = caller(1);
197    
198            $content = "/$content" if $content !~ m{[\n\r]} && -e $content;
199            if ( $content =~ $re_html ) {
200                    $head = qq|
201                            $content
202                            <!-- $type via $package at $path line $line -->
203                    |;
204            } elsif ( $content =~ m{^(/|https?://)} ) {
205                    if ( $what eq 'js' ) {
206                            $head = qq|
207                                    <$tag type="$type" src="$content">
208                                    /* $what via $package at $path line $line */
209                                    </$tag>
210                            |;
211                    } else {
212                            $head = qq|
213                                    <link rel="stylesheet" type="$type" href="$content">
214                                    <!-- $what via $package at $path line $line -->
215                            |;
216                    }
217            } else {
218                    $head = qq|
219                            <$tag type="$type">
220                            /* via $package at $path line $line */
221                            $content
222                            </$tag>
223                    |;
224            };
225            $self->add_head( $head );
226    }
227    
228  sub add_css {  sub add_css {
229          my ($self,$css) = @_;          my ($self,$css) = @_;
230          my ( $package, $path, $line ) = caller;          $self->_add_css_js( 'css', $css );
231          $self->add_head( qq|  }
232          <style type="text/css">  
233          /* via package $package at $path line $line */  sub add_js {
234          $css          my ($self,$js) = @_;
235          </style>          $self->_add_css_js( 'js', $js );
         | );  
236  }  }
237    
238  our $reload_counter = 0;  our $reload_counter = 0;
# Line 194  sub page { Line 257  sub page {
257          my $self = shift;          my $self = shift;
258          my $a = {@_};          my $a = {@_};
259    
         warn "## page ",dump($a);  
   
260          $reload_counter++;          $reload_counter++;
261    
262          my $status_line = '';          my $status_line = '';
263    
         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 };  
   
264          foreach my $part ( @status ) {          foreach my $part ( @status ) {
265                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
266                          $status_line .= $self->popup( $name, $part->{$name} );                          $status_line .= $self->popup( $name, $part->{$name} );
# Line 214  sub page { Line 271  sub page {
271          $url =~ s{\?reload=\d+}{};          $url =~ s{\?reload=\d+}{};
272    
273          my $body = $a->{body};          my $body = $a->{body};
274          $body ||= $self->as_markup if $self->can('as_markup');          if ( ! $body ) {
275                    my $run = $a->{run} || 'as_markup';
276                    warn "# no body, invoke $self->$run on ", ref($self);
277                    $body = $self->$run;
278            }
279          if ( $self->content_type !~ m{html} ) {          if ( $self->content_type !~ m{html} ) {
280                  warn "# return only $self body ", $self->content_type;                  warn "# return only $self body ", $self->content_type;
281                  return $body                  return $body
# Line 233  sub page { Line 294  sub page {
294                  qq|                  qq|
295                          <span class="right">                          <span class="right">
296                          <a title="reload $url"  href="/reload$url">reload</a>                          <a title="reload $url"  href="/reload$url">reload</a>
297                          <a title="$description" href="/exit$url">$exit</a>                          <a title="$description" href="/exit$url" target="exit">$exit</a>
298                          </span>                          </span>
299                  |;                  |;
300    
# Line 244  sub page { Line 305  sub page {
305    
306          $self->add_icon unless $icon_html;          $self->add_icon unless $icon_html;
307    
308            my $title = undef
309                    || $a->{title}
310                    || $self->title
311                    || ref($self)
312                    ;
313    
314    #       $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes
315    
316          my $html = join("\n",          my $html = join("\n",
317                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,
318                  $self->_head_html,                  $self->_head_html,
319                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',                  qq|<title>$title</title>|,
320                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
321                  ( $icon_html || '<!-- no icon -->' ),                  ( $icon_html || '<!-- no icon -->' ),
322                  ( $a->{head} || '' ),                  ( $a->{head} || '' ),
# Line 289  sub editor { Line 358  sub editor {
358          qq|>$class</a>|;          qq|>$class</a>|;
359  }  }
360    
361  =head2 editor_links  =head2 html_links
362    
363  Create HTML links to editor for perl error message  Create HTML links to editor for perl error message
364    
365    my $html = $self->editor_links( $error )    my $html = $self->html_links( $error )
366    
367  =cut  =cut
368    
369  sub editor_links {  sub html_links {
370          my ( $self, $error ) = @_;          my ( $self, $error ) = @_;
371    
372            $error = $self->strip_full_path( $error );
373    
374    #       $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back
375    
376            # perl's backtrace
377          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}
378                  {at <a target="editor" href="/editor+$1+$2">$1</a> line $2}gsm;                  {at <a target="editor" href="/editor+$1+$2" title="vi $1 +$2">$1</a> line $2}gsm;
379    
380            $error =~ s{(via (?:package)\s+"?)([\w:]+)("?)}
381                    {$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm
382            || # or anything that looks like "Class::Name"
383            $error =~ s{"(\w+(?:::\w+)+)"}
384                    {"<a target="$1" href="/$1" title="introspect $1">$1</a>"}gsm;
385    
386            # method error messages
387            # FIXME replace with link to Frey::Introspect data
388            $error =~ s{(method ")(\w+)(" via)}
389                    {$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm;
390    
391            # link paths to editor
392            $error =~ s{((?:lib|t)/[\S]+)\s+(\d+\s+bytes)}
393                    {<a target="editor" href="/editor+$1+1" title="vi $1 [$2]">$1</a>}gsm;
394    
395          $error =~ s{(via package ")([\w:]+)(")}          $error =~ s{(class ")([\w:]+)(")}
396                  {$1<a target="editor" href="/editor+$2+1">$2</a>$3}gsm;                  {$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm;
397    
398          return $error;          return $error;
399  }  }
400    
401    sub html_self {
402            my $self = shift;
403            my $html = $self;
404            $html =~ s{([\w:]+)=}{<a target="$1" href="/$1" title="introspect $1">$1</a>=}gsm;
405            return $html;
406    }
407    
408    =head2 error
409    
410    This method will return error to browser and backtrace unless
411    error message ends with LF C<\n> just like L<warn>
412    
413    =cut
414    
415  sub error {  sub error {
416          my $self = shift;          my $self = shift;
417          my $error = join(" ", @_);          my $error = join(" ", @_);
418    
419          my @backtrace = $self->backtrace;          my $fatal = '';
420          $error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace;          my $backtrace = '';
421    
422            if ( $error !~ m{\n$} ) {
423                    if ( my @backtrace = $self->backtrace ) {
424                            $backtrace =
425                                      "\n" . $self->html_self . "->error backtrace\n\t"
426                                    . $self->html_links( join( "\n\t", @backtrace ) )
427                                    ;
428                            $fatal = qq| frey-fatal|;
429                    }
430            }
431    
432          warn "ERROR: $error\n";          warn "ERROR: $error\n";
433          return          $self->add_icon('error');
434                  qq|<pre class="frey-error">|          $error = $self->html_links( $error );
435                  . $self->editor_links( $error ) .          return qq|<pre class="frey-error$fatal">$error $backtrace</pre>| ;
                 qq|</pre>|  
                 ;  
436  }  }
437    
438  =head1 Status line  =head1 Status line
439    
440  =head2 add_status  =head2 add_status
441    
442    $self->add_status( name => { some => 'data' } );    $self->add_status( { name => { some => 'data' } } );
443    
444    $self->add_status( "append to last status popup" );    $self->add_status( "append to last status popup" );
445    
# Line 336  sub error { Line 447  sub error {
447    
448  sub add_status {  sub add_status {
449          my ( $self, $data ) = @_;          my ( $self, $data ) = @_;
450          if ( ref($data) ) {          die "no data" unless $data;
451            if ( ref $data  ) {
452                  push @status, $data;                  push @status, $data;
453          } else {          } else {
454                  $status[ $#status ]->{added} = $data;                  if ( defined $status[ $#status ] ) {
455                            $status[ $#status ]->{ '+' } = $data;
456                    } else {
457                            push @status, { '+' => $data };
458                    }
459          }          }
460  }  }
461    
# Line 353  Called at beginning of each request Line 469  Called at beginning of each request
469    
470  sub clean_status {  sub clean_status {
471          my ($self) = shift;          my ($self) = shift;
472          @head = ();          @head = ( 'static/frey.css' );
473          @status = ();          @status = (
474                    { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup },
475                    { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
476                    { 'INC' => Frey::INC->new->as_markup },
477            );
478          $icon_html = '';          $icon_html = '';
479  }  }
480    
# Line 388  sub DEMOLISH { Line 508  sub DEMOLISH {
508    
509  sub icon_path {  sub icon_path {
510          my ($self,$class,$variant) = @_;          my ($self,$class,$variant) = @_;
511          my $icon = $class;  
512          $icon =~ s{::}{/}g;          sub icon_exists {
513          $icon .= "/$variant" if $variant;                  my $class = shift;
514          my $path = 'static/icons/' . $icon . '.png';                  $class =~ s{::}{/}g;
515          if ( -e $path ) {                  $class .= "/$variant" if $variant;
516                  warn "# $class from $self icon_path $path" if $self->debug;                  my $icon_path = 'static/icons/' . $class . '.png';
517                  return $path;                  return $icon_path if -e $icon_path;
518          } else {                  return;
519                  $self->TODO( "add $path icon for $class" );          }
520    
521            my $path = icon_exists( $class );
522            if ( ! $path ) {
523                    my $super_class = $class;
524                    while ( $super_class =~ s{::[^:]+$}{} && ! $path ) {
525                            $path = icon_exists( $super_class ) unless $super_class eq 'Frey'; # don't default on Frey icon
526                    }
527            }
528    
529            if ( ! $path ) {
530                    $self->TODO( "add icon for $class" . ( $variant ? " variant $variant" : '' ) );
531                  return undef;                  return undef;
532          }          }
533    
534            warn "# $class from $self icon_path $path" if $self->debug;
535            return $path;
536  }  }
537    
538  sub add_icon {  sub add_icon {
539          my ($self,$variant) = @_;          my ($self,$variant) = @_;
540    
541          my $class = ref($self);          my $class = $self->class if $self->can('class');
542          $class = $self->class if $self->can('class');          #$class ||= $self->title;
543            $class ||= ref($self);
544          my $icon_path = $self->icon_path( $class, $variant ) || return;          my $icon_path = $self->icon_path( $class, $variant ) || return;
545    
546          $icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|;          $icon_html .= qq|<link rel="icon" type="image/png" href="/$icon_path">|;
# Line 438  my $multiline_markers = { Line 573  my $multiline_markers = {
573          '"' => '"',          '"' => '"',
574  };  };
575    
576    =for later
577    
578  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';
579  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";
580    
581    =cut
582    
583  sub log_path {  sub log_path {
584          $Frey::Bootstrap::log_path || warn "no log_path?";          $Frey::Bootstrap::log_path || die "no log_path?";
585  }  }
586    
587    our $pwd = `pwd`;
588    chomp $pwd;
589    
590    sub strip_full_path {
591            my ($self, $msg) = @_;
592            # Mojo seems to expand warn messages to full path which is annoying
593            $msg =~ s{/[^/]+/\.\./}{/}gs;
594            $msg =~ s{$pwd/*}{}gs;
595            return $msg;
596    }
597    
598    our $last_log_pos  = 0;
599    our $last_log_line = 0;
600    
601  sub warnings_html {  sub warnings_html {
602          my ($self,$level) = shift;          my ($self,$level) = shift;
603          $level ||= $self->debug,          $level ||= $self->debug,
604          my $path = $self->log_path;          my $path = $self->log_path;
605    
606          my $warnings;          my $max = 30;
607          my $line = 0;          my $pos = 0;
608            my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines
609            my $line = $last_log_line;
610          my $multiline_end;          my $multiline_end;
611    
612          open(my $log, '<', $path) || die "can't open $path: $!";          # XXX do we really want to do this every time?
613            my $css = qq|/* short css classes for levels */\n|;
614            my $level_to_class;
615            foreach ( keys %$warn_colors ) {
616                    my $l = length($_);
617                    my $class = 'l' . $l;
618                    $css .= qq|.$class { color: $warn_colors->{$_} }\n|;
619                    $level_to_class->{ $_ } = $class;
620            }
621            $self->add_css( $css );
622    
623            open(my $log, '<', $path)    || die "can't open $path: $!";
624            seek($log, $last_log_pos, 0) || warn "can't seek: $!";
625          while(<$log>) {          while(<$log>) {
626                  chomp;                  chomp;
627                  $line++;                  $line++;
628    
629                    next if m{^\s+(Mojo|Class::MOP|Moose)::};
630    
631                  my $style = '';                  my $style = '';
632    
633    =for filter
634    
635                  if ( $multiline_end ) {                  if ( $multiline_end ) {
636                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {
637  #                               warn "## $line end of $multiline_end in '$_'\n";  #                               warn "## $line end of $multiline_end in '$_'\n";
# Line 477  sub warnings_html { Line 648  sub warnings_html {
648                                  next;                                  next;
649                          }                          }
650    
651                          $style = $warn_colors->{$1}  =cut
652                                  ? ' style="color:' . $warn_colors->{$1} . '"'                  if ( m{^(#*)} ) {
653                                  : '';  
654                            my $level = $1;
655                            my $msg = $self->strip_full_path( $_ );
656    
                         my $msg = $self->html_escape( $_ );  
657                          my $spacer = ' ';                          my $spacer = ' ';
658                          if ( length($msg) > $self->html_dump_width ) {                          my $real_msg = expand( $msg );
659                                  $msg = substr( $msg, 0, $self->html_dump_width );                          if ( length($real_msg) > $self->html_dump_width ) {
660                                    
661                                    $real_msg = substr( $msg, 0, $self->html_dump_width );
662                                    $msg = unexpand( $real_msg );
663                                  $spacer = '&hellip;'                                  $spacer = '&hellip;'
664                          }                          }
665                          $msg =~ s{^\s}{&nbsp;}g;  
666                          $warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|;                          $msg = $self->html_escape( $msg );
667                          # FIXME <tt> should be <code> but CSS hates me  
668                            if ( my $class = $level_to_class->{ $level } ) {
669                                    $msg = qq|<span class="$class">$msg</span>|;
670                            }
671    
672                            #$msg .= $spacer . qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>\n|;
673                            $msg = qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>$msg|
674                                    . ( $spacer ? $spacer : '' )
675                                    . "\n"; # XXX <pre> needs this
676    
677                            $warnings[ $pos++ % $max ] = $msg;
678                  }                  }
679          }          }
680            $last_log_pos = tell($log);
681            $last_log_line = $line;
682            warn "log has $line lines tell position $last_log_pos";
683          close($log) || die "can't close $path: $!";          close($log) || die "can't close $path: $!";
684    
685            my $size = -s $path;
686    
687            my $warnings = join("",
688                    map { $warnings[ ( $pos + $_ ) % $max ] || '' } 0 .. ( $max - 1 )
689            );
690    
691            my $s = length($warnings);
692    
693          return          return
694                    qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="open $path level $level">warn</a><span>|                  # need to wrap editor link into span so we can have links in warnings
695                  . $self->editor_links( $warnings )                    qq|<span class="frey-popup"><a target="editor" href="/editor+$path+$line" title="$path \| $size -> $s bytes \| $line -> $pos lines \| level $level">warn</a><code>|
696                  . qq|</span></span>|                  . $self->html_links( $warnings )
697                    . qq|</code></span>|
698                  ;                  ;
699  }  }
700    
# Line 514  sub backtrace { Line 711  sub backtrace {
711          my ($self) = @_;          my ($self) = @_;
712    
713          my @backtrace;          my @backtrace;
714          foreach ( 0 .. 5 ) {          foreach ( 1 .. 5 ) { # 0 = backtrace
715                  my (                  my (
716                          $package,$path,$line                          $package,$path,$line
717                          # subroutine hasargs                          # subroutine hasargs
# Line 523  sub backtrace { Line 720  sub backtrace {
720                  ) = caller($_) or last;                  ) = caller($_) or last;
721    
722                  push @backtrace,                  push @backtrace,
723                          qq|via package $package at $path line $line|;                          qq|via "$package" at $path line $line|;
724          }          }
725          warn "# backtrace: ", dump( @backtrace ) if @backtrace;          #warn "# backtrace: ", dump( @backtrace ) if @backtrace;
726          return @backtrace;          return @backtrace;
727  }  }
728    
729    =head2 checkbox
730    
731    Generate checkbox html markup from some attribute
732    
733      my $html = $self->checkbox('attribute_name', $value);
734    
735    =cut
736    
737    sub checkbox {
738            my ($self,$name,$value) = @_;
739            my $checked = '';
740            my $all_checkboxes = eval { $self->$name };
741            warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@;
742            $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty
743            $checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes;
744            warn "# checkbox $name $value $checked\t", $self->dump( $self->$name );
745            qq|<input name="$name" value="$value" type="checkbox"$checked>|;
746    }
747    
748    =head2 strip
749    
750    Strip whitespace around content
751    
752      my $stripped = strip('  no more whitespace around this   ');
753    
754    =cut
755    
756    sub strip {
757            my $t = shift;
758            $t =~ s{^\s+}{}gs;
759            $t =~ s{>\s+<}{><}gs;
760            $t =~ s{\s+$}{}gs;
761            return $t;
762    }
763    
764  1;  1;

Legend:
Removed from v.577  
changed lines
  Added in v.945

  ViewVC Help
Powered by ViewVC 1.1.26