/[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 859 by dpavlin, Tue Dec 16 14:26:23 2008 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 79  sub html_dump { Line 87  sub html_dump {
87          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;
88          $dump = $self->html_escape( $dump );          $dump = $self->html_escape( $dump );
89          $dump =~ s{\Q...\E}{&hellip;}gs;          $dump =~ s{\Q...\E}{&hellip;}gs;
90    #       $dump =~ $self->html_links( $dump ); # FIXME include this
91          return "<code>$dump</code>";          return "<code>$dump</code>";
92  }  }
93    
94  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }
95  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }
96    
97  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
98    
99  sub popup_dropdown {  sub popup_dropdown {
100          my ( $self, $type, $name, $content, $full ) = @_;          my ( $self, $type, $name, $content, $full ) = @_;
# Line 94  sub popup_dropdown { Line 103  sub popup_dropdown {
103    
104          $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*};
105    
106          warn "## $type [$name] = ", length( $content ), " bytes" if $self->debug;          $content =~ s{<span>(<code>[^<]+</code>)</span>}{$1} && $self->TODO("code wrapped in span");
107    
108            warn "## $type [$name] = ", length( $content ), " bytes"; # if $self->debug; # FIXME
109    
110          if ( $name =~ m{::} && $name !~ $re_html ) {          if ( $name =~ m{::} && $name !~ $re_html ) {
111                  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|;
112            } elsif ( $name =~ s{^\s*(<a)\s+}{$1 class="frey-$type"} ) {
113                    return qq|$name $content\n|;
114          } else {          } else {
115                  return qq|<span class="frey-$type">$name $content</span>\n|;                  return qq|<span class="frey-$type">$name $content</span>\n|;
116          }          }
117  }  }
118    
119  sub _inline_path {  sub _inline_path_size {
120          my ( $self, $path ) = @_;          my ( $self, $path ) = @_;
121          -s $path < $self->inline_smaller_than;          -s $path < $self->inline_smaller_than && -s $path;
122  }  }
123    
124  sub _head_html {  sub _head_html {
# Line 113  sub _head_html { Line 126  sub _head_html {
126          my $out = '';          my $out = '';
127          foreach my $path ( @head ) {          foreach my $path ( @head ) {
128                  $path =~ s!^/!!;                  $path =~ s!^/!!;
129                    my $size = $self->_inline_path_size( $path );
130                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
131                          $out .= $self->_inline_path( $path ) ?                          $out .= $size ?
132                                  qq|<!-- $path --><script type="text/javascript">\n| . read_file($path) . qq|\n</script>| :                                  qq|<script type="text/javascript">\n/* inline $path $size bytes */\n\n| . read_file($path) . qq|\n</script>| :
133                                  qq|<script type="text/javascript" src="/$path"></script>|;                                  qq|<script type="text/javascript" src="/$path"></script>|;
134                  } elsif ( $path =~ m/\.css$/ ) {                  } elsif ( $path =~ m/\.css$/ ) {
135                          $out .= $self->_inline_path( $path ) ?                          $out .= $size ?
136                                  qq|<!-- $path --><style type="text/css">\n| . read_file( $path ) . qq|\n</style>| :                                  qq|<style type="text/css">\n/* inline $path $size bytes */\n\n| . read_file( $path ) . qq|\n</style>| :
137                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
138                  } elsif ( $path =~ m{<.+>}s ) {                  } elsif ( $path =~ m{<.+>}s ) {
139                          $out .= $path;                          $out .= $path;
# Line 161  sub add_head { Line 175  sub add_head {
175    
176  }  }
177    
178    sub _add_css_js {
179            my ( $self, $what, $content ) = @_;
180    
181            my $tag  = $what eq 'css' ? 'style'    : 'script';
182            my $type = $what eq 'css' ? 'text/css' : 'text/javascript';
183            my $head;
184    
185            my ( $package, $path, $line ) = caller(1);
186    
187            if ( $content =~ m{\.(js|css)} ) {
188                    $content = "/$content" if -e $content;
189                    if ( $content =~ $re_html ) {
190                            $head = qq|
191                                    $content
192                                    <!-- $type via $package at $path line $line -->
193                            |;
194                    } elsif ( $what eq 'js' ) {
195                            $head = qq|
196                                    <$tag type="$type" src="$content">
197                                    /* $what via $package at $path line $line */
198                                    </$tag>
199                            |;
200                    } else {
201                            $head = qq|
202                                    <link rel="stylesheet" type="$type" href="$content">
203                                    <!-- $what via $package at $path line $line -->
204                            |;
205                    }
206            } else {
207                    $head = qq|
208                            <$tag type="$type">
209                            /* via $package at $path line $line */
210                            $content
211                            </$tag>
212                    |;
213            };
214            $self->add_head( $head );
215    }
216    
217  sub add_css {  sub add_css {
218          my ($self,$css) = @_;          my ($self,$css) = @_;
219          my ( $package, $path, $line ) = caller;          $self->_add_css_js( 'css', $css );
220          $self->add_head( qq|  }
221          <style type="text/css">  
222          /* via package $package at $path line $line */  sub add_js {
223          $css          my ($self,$js) = @_;
224          </style>          $self->_add_css_js( 'js', $js );
         | );  
225  }  }
226    
227  our $reload_counter = 0;  our $reload_counter = 0;
# Line 200  sub page { Line 252  sub page {
252    
253          my $status_line = '';          my $status_line = '';
254    
         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 };  
   
255          foreach my $part ( @status ) {          foreach my $part ( @status ) {
256                  foreach my $name ( keys %$part ) {                  foreach my $name ( keys %$part ) {
257                          $status_line .= $self->popup( $name, $part->{$name} );                          $status_line .= $self->popup( $name, $part->{$name} );
# Line 214  sub page { Line 262  sub page {
262          $url =~ s{\?reload=\d+}{};          $url =~ s{\?reload=\d+}{};
263    
264          my $body = $a->{body};          my $body = $a->{body};
265          $body ||= $self->as_markup if $self->can('as_markup');          if ( ! $body ) {
266                    my $run = $a->{run} || 'as_markup';
267                    warn "# no body, invoke $self->$run on ", ref($self);
268                    $body = $self->$run;
269            }
270          if ( $self->content_type !~ m{html} ) {          if ( $self->content_type !~ m{html} ) {
271                  warn "# return only $self body ", $self->content_type;                  warn "# return only $self body ", $self->content_type;
272                  return $body                  return $body
# Line 233  sub page { Line 285  sub page {
285                  qq|                  qq|
286                          <span class="right">                          <span class="right">
287                          <a title="reload $url"  href="/reload$url">reload</a>                          <a title="reload $url"  href="/reload$url">reload</a>
288                          <a title="$description" href="/exit$url">$exit</a>                          <a title="$description" href="/exit$url" target="exit">$exit</a>
289                          </span>                          </span>
290                  |;                  |;
291    
# Line 289  sub editor { Line 341  sub editor {
341          qq|>$class</a>|;          qq|>$class</a>|;
342  }  }
343    
344  =head2 editor_links  =head2 html_links
345    
346  Create HTML links to editor for perl error message  Create HTML links to editor for perl error message
347    
348    my $html = $self->editor_links( $error )    my $html = $self->html_links( $error )
349    
350  =cut  =cut
351    
352  sub editor_links {  sub html_links {
353          my ( $self, $error ) = @_;          my ( $self, $error ) = @_;
354    
355            $error = $self->strip_full_path( $error );
356    
357    #       $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back
358    
359            # perl's backtrace
360          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}
361                  {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;
362    
363          $error =~ s{(via package ")([\w:]+)(")}          $error =~ s{(via (?:package)\s+"?)([\w:]+)("?)}
364                  {$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
365            || # or anything that looks like "Class::Name"
366            $error =~ s{"(\w+(?:::\w+)+)"}
367                    {"<a target="$1" href="/$1" title="introspect $1">$1</a>"}gsm;
368    
369            # method error messages
370            # FIXME replace with link to Frey::Introspect data
371            $error =~ s{(method ")(\w+)(" via)}
372                    {$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm;
373    
374            # link paths to editor
375            $error =~ s{((?:lib|t)/[\S]+)\s+(\d+\s+bytes)}
376                    {<a target="editor" href="/editor+$1+1" title="vi $1 [$2]">$1</a>}gsm;
377    
378            $error =~ s{(class ")([\w:]+)(")}
379                    {$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm;
380    
381          return $error;          return $error;
382  }  }
383    
384    sub html_self {
385            my $self = shift;
386            my $html = $self;
387            $html =~ s{([\w:]+)=}{<a target="$1" href="/$1" title="introspect $1">$1</a>=}gsm;
388            return $html;
389    }
390    
391    =head2 error
392    
393    This method will return error to browser and backtrace unless
394    error message ends with LF C<\n> just like L<warn>
395    
396    =cut
397    
398  sub error {  sub error {
399          my $self = shift;          my $self = shift;
400          my $error = join(" ", @_);          my $error = join(" ", @_);
401    
402          my @backtrace = $self->backtrace;          my $fatal = '';
403          $error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace;          my $backtrace = '';
404    
405            if ( $error !~ m{\n$} ) {
406                    if ( my @backtrace = $self->backtrace ) {
407                            $backtrace =
408                                      "\n" . $self->html_self . "->error backtrace\n\t"
409                                    . $self->html_links( join( "\n\t", @backtrace ) )
410                                    ;
411                            $fatal = qq| frey-fatal|;
412                    }
413            }
414    
415          warn "ERROR: $error\n";          warn "ERROR: $error\n";
416          return          $self->add_icon('error');
417                  qq|<pre class="frey-error">|          $error = $self->html_links( $error );
418                  . $self->editor_links( $error ) .          return qq|<pre class="frey-error$fatal">$error $backtrace</pre>| ;
                 qq|</pre>|  
                 ;  
419  }  }
420    
421  =head1 Status line  =head1 Status line
422    
423  =head2 add_status  =head2 add_status
424    
425    $self->add_status( name => { some => 'data' } );    $self->add_status( { name => { some => 'data' } } );
426    
427    $self->add_status( "append to last status popup" );    $self->add_status( "append to last status popup" );
428    
# Line 336  sub error { Line 430  sub error {
430    
431  sub add_status {  sub add_status {
432          my ( $self, $data ) = @_;          my ( $self, $data ) = @_;
433            push @status, { 'X' => [ $self->backtrace ] };
434          if ( ref($data) ) {          if ( ref($data) ) {
435                  push @status, $data;                  push @status, $data;
436          } else {          } else {
437                  $status[ $#status ]->{added} = $data;                  if ( defined $status[ $#status ] ) {
438                            $status[ $#status ]->{ '+' } = $data;
439                    } else {
440                            push @status, { '+' => $data };
441                    }
442          }          }
443  }  }
444    
# Line 353  Called at beginning of each request Line 452  Called at beginning of each request
452    
453  sub clean_status {  sub clean_status {
454          my ($self) = shift;          my ($self) = shift;
455          @head = ();          @head = ( 'static/frey.css' );
456          @status = ();          @status = (
457                    { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup },
458                    { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
459                    { 'INC' => Frey::INC->new->as_markup },
460            );
461          $icon_html = '';          $icon_html = '';
462  }  }
463    
# Line 388  sub DEMOLISH { Line 491  sub DEMOLISH {
491    
492  sub icon_path {  sub icon_path {
493          my ($self,$class,$variant) = @_;          my ($self,$class,$variant) = @_;
494          my $icon = $class;  
495          $icon =~ s{::}{/}g;          sub icon_exists {
496          $icon .= "/$variant" if $variant;                  my $class = shift;
497          my $path = 'static/icons/' . $icon . '.png';                  $class =~ s{::}{/}g;
498          if ( -e $path ) {                  $class .= "/$variant" if $variant;
499                  warn "# $class from $self icon_path $path" if $self->debug;                  my $icon_path = 'static/icons/' . $class . '.png';
500                  return $path;                  return $icon_path if -e $icon_path;
501          } else {                  return;
502                  $self->TODO( "add $path icon for $class" );          }
503    
504            my $path = icon_exists( $class );
505            if ( ! $path ) {
506                    my $super_class = $class;
507                    while ( $super_class =~ s{::[^:]+$}{} && ! $path ) {
508                            $path = icon_exists( $super_class ) unless $super_class eq 'Frey'; # don't default on Frey icon
509                    }
510            }
511    
512            if ( ! $path ) {
513                    $self->TODO( "add icon for $class" . ( $variant ? " variant $variant" : '' ) );
514                  return undef;                  return undef;
515          }          }
516    
517            warn "# $class from $self icon_path $path" if $self->debug;
518            return $path;
519  }  }
520    
521  sub add_icon {  sub add_icon {
522          my ($self,$variant) = @_;          my ($self,$variant) = @_;
523    
524          my $class = ref($self);          my $class = $self->class if $self->can('class');
525          $class = $self->class if $self->can('class');          #$class ||= $self->title;
526            $class ||= ref($self);
527          my $icon_path = $self->icon_path( $class, $variant ) || return;          my $icon_path = $self->icon_path( $class, $variant ) || return;
528    
529          $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 556  my $multiline_markers = {
556          '"' => '"',          '"' => '"',
557  };  };
558    
559    =for later
560    
561  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';
562  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";
563    
564    =cut
565    
566  sub log_path {  sub log_path {
567          $Frey::Bootstrap::log_path || warn "no log_path?";          $Frey::Bootstrap::log_path || die "no log_path?";
568    }
569    
570    our $pwd = `pwd`;
571    chomp $pwd;
572    
573    sub strip_full_path {
574            my ($self, $msg) = @_;
575            # Mojo seems to expand warn messages to full path which is annoying
576            $msg =~ s{/[^/]+/\.\./}{/}gs;
577            $msg =~ s{$pwd/*}{}gs;
578            return $msg;
579  }  }
580    
581    our $last_log_pos  = 0;
582    our $last_log_line = 0;
583    
584  sub warnings_html {  sub warnings_html {
585          my ($self,$level) = shift;          my ($self,$level) = shift;
586          $level ||= $self->debug,          $level ||= $self->debug,
587          my $path = $self->log_path;          my $path = $self->log_path;
588    
589          my $warnings;          my $max = 30;
590          my $line = 0;          my $pos = 0;
591            my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines
592            my $line = $last_log_line;
593          my $multiline_end;          my $multiline_end;
594    
595          open(my $log, '<', $path) || die "can't open $path: $!";          # XXX do we really want to do this every time?
596            my $css = qq|/* short css classes for levels */\n|;
597            my $level_to_class;
598            foreach ( keys %$warn_colors ) {
599                    my $l = length($_);
600                    my $class = 'l' . $l;
601                    $css .= qq|.$class { color: $warn_colors->{$_} }\n|;
602                    $level_to_class->{ $_ } = $class;
603            }
604            $self->add_css( $css );
605    
606            open(my $log, '<', $path)    || die "can't open $path: $!";
607            seek($log, $last_log_pos, 0) || warn "can't seek: $!";
608          while(<$log>) {          while(<$log>) {
609                  chomp;                  chomp;
610                  $line++;                  $line++;
611    
612                    next if m{^\s+(Mojo|Class::MOP|Moose)::};
613    
614                  my $style = '';                  my $style = '';
615    
616    =for filter
617    
618                  if ( $multiline_end ) {                  if ( $multiline_end ) {
619                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {                          if ( m{^\Q$multiline_end\E} || m{^\s.+\Q$multiline_end\E;$} ) {
620  #                               warn "## $line end of $multiline_end in '$_'\n";  #                               warn "## $line end of $multiline_end in '$_'\n";
# Line 477  sub warnings_html { Line 631  sub warnings_html {
631                                  next;                                  next;
632                          }                          }
633    
634                          $style = $warn_colors->{$1}  =cut
635                                  ? ' style="color:' . $warn_colors->{$1} . '"'                  if ( m{^(#*)} ) {
636                                  : '';  
637                            my $level = $1;
638                            my $msg = $self->strip_full_path( $_ );
639    
                         my $msg = $self->html_escape( $_ );  
640                          my $spacer = ' ';                          my $spacer = ' ';
641                          if ( length($msg) > $self->html_dump_width ) {                          my $real_msg = expand( $msg );
642                                  $msg = substr( $msg, 0, $self->html_dump_width );                          if ( length($real_msg) > $self->html_dump_width ) {
643                                    
644                                    $real_msg = substr( $msg, 0, $self->html_dump_width );
645                                    $msg = unexpand( $real_msg );
646                                  $spacer = '&hellip;'                                  $spacer = '&hellip;'
647                          }                          }
648                          $msg =~ s{^\s}{&nbsp;}g;  
649                          $warnings .= qq|<tt$style>$msg</tt>$spacer<small><a target="editor" href="/editor+$path+$line">+$line</a></small><br/>|;                          $msg = $self->html_escape( $msg );
650                          # FIXME <tt> should be <code> but CSS hates me  
651                            if ( my $class = $level_to_class->{ $level } ) {
652                                    $msg = qq|<span class="$class">$msg</span>|;
653                            }
654    
655                            #$msg .= $spacer . qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>\n|;
656                            $msg = qq|<a target="editor" href="/editor+$path+$line" style="float: right;">$line</a>$msg|
657                                    . ( $spacer ? $spacer : '' )
658                                    . "\n"; # XXX <pre> needs this
659    
660                            $warnings[ $pos++ % $max ] = $msg;
661                  }                  }
662          }          }
663            $last_log_pos = tell($log);
664            $last_log_line = $line;
665            warn "log has $line lines tell position $last_log_pos";
666          close($log) || die "can't close $path: $!";          close($log) || die "can't close $path: $!";
667    
668            my $size = -s $path;
669    
670            my $warnings = join("",
671                    map { $warnings[ ( $pos + $_ ) % $max ] || '' } 0 .. ( $max - 1 )
672            );
673    
674            my $s = length($warnings);
675    
676          return          return
677                    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
678                  . $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>|
679                  . qq|</span></span>|                  . $self->html_links( $warnings )
680                    . qq|</code></span>|
681                  ;                  ;
682  }  }
683    
# Line 514  sub backtrace { Line 694  sub backtrace {
694          my ($self) = @_;          my ($self) = @_;
695    
696          my @backtrace;          my @backtrace;
697          foreach ( 0 .. 5 ) {          foreach ( 1 .. 5 ) { # 0 = backtrace
698                  my (                  my (
699                          $package,$path,$line                          $package,$path,$line
700                          # subroutine hasargs                          # subroutine hasargs
# Line 523  sub backtrace { Line 703  sub backtrace {
703                  ) = caller($_) or last;                  ) = caller($_) or last;
704    
705                  push @backtrace,                  push @backtrace,
706                          qq|via package $package at $path line $line|;                          qq|via "$package" at $path line $line|;
707          }          }
708          warn "# backtrace: ", dump( @backtrace ) if @backtrace;          #warn "# backtrace: ", dump( @backtrace ) if @backtrace;
709          return @backtrace;          return @backtrace;
710  }  }
711    
712    =head2 checkbox
713    
714    Generate checkbox html markup from some attribute
715    
716      my $html = $self->checkbox('attribute_name', $value);
717    
718    =cut
719    
720    sub checkbox {
721            my ($self,$name,$value) = @_;
722            my $checked = '';
723            my $all_checkboxes = eval { $self->$name };
724            warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@;
725            $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty
726            $checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes;
727            warn "# checkbox $name $value $checked\t", $self->dump( $self->$name );
728            qq|<input name="$name" value="$value" type="checkbox"$checked>|;
729    }
730    
731    =head2 strip
732    
733    Strip whitespace around content
734    
735      my $stripped = strip('  no more whitespace around this   ');
736    
737    =cut
738    
739    sub strip {
740            my $t = shift;
741            $t =~ s{^\s+}{}gs;
742            $t =~ s{>\s+<}{><}gs;
743            $t =~ s{\s+$}{}gs;
744            return $t;
745    }
746    
747  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26