/[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 625 by dpavlin, Sat Nov 29 17:48:54 2008 UTC revision 1045 by dpavlin, Thu Mar 12 20:56:04 2009 UTC
# Line 3  use Moose::Role; Line 3  use Moose::Role;
3    
4  with 'Frey::Session';  with 'Frey::Session';
5    
 use Frey::Types;  
   
 #use Continuity::Widget::DomNode;  
6  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
7  use Carp qw/confess cluck/;  use Carp qw/confess cluck carp/;
8  use File::Slurp;  use File::Slurp;
9    use Text::Tabs; # expand, unexpand
10    
11    use lib 'lib';
12    
13    use Frey::Types;
14    
15  use Frey::Bookmarklet;  use Frey::Bookmarklet;
16  use Frey::ClassBrowser;  use Frey::Class::Browser;
17  use Frey::INC;  use Frey::INC;
18    
19  use Frey::SVK;  use Frey::SVK;
20    
 use Text::Tabs; # expand, unexpand  
   
21  our @head;  our @head;
22  sub head { @head }  sub head { @head }
23    
# Line 25  has 'request_url' => ( Line 25  has 'request_url' => (
25          is => 'rw',          is => 'rw',
26          isa => 'Uri', coerce => 1,          isa => 'Uri', coerce => 1,
27          required => 1,          required => 1,
28  #       default => '/',          default => sub {
29                    carp "undefined request_url";
30                    '/';
31            },
32  );  );
33    
34  has 'title' => (  has 'title' => (
# Line 64  has 'html_dump_width' => ( Line 67  has 'html_dump_width' => (
67          is => 'rw',          is => 'rw',
68          isa => 'Int',          isa => 'Int',
69  #       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
70          default => 120,          default => 250,
71    );
72    
73    has 'wrap_in_page' => (
74            documentation => 'wrap full html page with status bar around content',
75            is => 'rw',
76            isa => 'Bool',
77            default => 1,
78  );  );
79    
80  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');  my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
# Line 72  my $escape_re  = join '|' => keys %escap Line 82  my $escape_re  = join '|' => keys %escap
82    
83  sub html_escape {  sub html_escape {
84          my ( $self, $html ) = @_;          my ( $self, $html ) = @_;
85            return '' unless defined $html;
86          $html =~ s/($escape_re)/$escape{$1}/g;          $html =~ s/($escape_re)/$escape{$1}/g;
87          return $html;          return $html;
88  }  }
89    
90    # from Mojo::ByteStream
91    sub url_escape {
92            my ( $self, $url, $pattern ) = @_;
93            $pattern ||= 'A-Za-z0-9\-\.\_\~';
94            $url =~ s/([^$pattern])/sprintf('%%%02X',ord($1))/ge;
95            return $url;
96    }
97    
98  sub html_dump {  sub html_dump {
99          my ( $self, $dump ) = @_;          my ( $self, $dump ) = @_;
100          $dump = dump( $dump ) if ref($dump);          $dump = dump( $dump ) if ref($dump);
# Line 83  sub html_dump { Line 102  sub html_dump {
102          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;          $dump =~ s{(\n[^\n]{$width})([^\n]+?)([^\n]{5})}{\n$1...$3}gs;
103          $dump = $self->html_escape( $dump );          $dump = $self->html_escape( $dump );
104          $dump =~ s{\Q...\E}{&hellip;}gs;          $dump =~ s{\Q...\E}{&hellip;}gs;
105  #       $dump =~ $self->editor_links( $dump ); # FIXME include this  #       $dump =~ $self->html_links( $dump ); # FIXME include this
106          return "<code>$dump</code>";          return "<code>$dump</code>";
107  }  }
108    
109  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }  sub popup    { my $self = shift; $self->popup_dropdown('popup',    @_); }
110  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }  sub dropdown { my $self = shift; $self->popup_dropdown('dropdown', @_); }
111    
112  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
113    
114  sub popup_dropdown {  sub popup_dropdown {
115          my ( $self, $type, $name, $content, $full ) = @_;          my ( $self, $type, $name, $content, $full ) = @_;
# Line 112  sub popup_dropdown { Line 131  sub popup_dropdown {
131          }          }
132  }  }
133    
134  sub _inline_path {  sub _inline {
135          my ( $self, $path ) = @_;          my ( $self, $path ) = @_;
136          -s $path < $self->inline_smaller_than;          return unless defined $path;
137            warn "# _inline $path";
138            -e $path && -s $path < $self->inline_smaller_than && -s $path;
139  }  }
140    
141  sub _head_html {  sub _head_html {
# Line 123  sub _head_html { Line 144  sub _head_html {
144          foreach my $path ( @head ) {          foreach my $path ( @head ) {
145                  $path =~ s!^/!!;                  $path =~ s!^/!!;
146                  if ( $path =~ m/\.js$/ ) {                  if ( $path =~ m/\.js$/ ) {
147                          $out .= $self->_inline_path( $path ) ?                          my $size;
148                                  qq|<script type="text/javascript">\n/* inline $path */\n\n| . read_file($path) . qq|\n</script>| :                          $out .= $size = _inline( $path ) ?
149                                    qq|<script type="text/javascript">\n/* inline $path $size bytes */\n\n| . read_file($path) . qq|\n</script>| :
150                                  qq|<script type="text/javascript" src="/$path"></script>|;                                  qq|<script type="text/javascript" src="/$path"></script>|;
151                  } elsif ( $path =~ m/\.css$/ ) {                  } elsif ( $path =~ m/\.css$/ ) {
152                          $out .= $self->_inline_path( $path ) ?                          my $size;
153                                  qq|<style type="text/css">\n/* inline $path */\n\n| . read_file( $path ) . qq|\n</style>| :                          $out .= $size = _inline( $path ) ?
154                                    qq|<style type="text/css">\n/* inline $path $size bytes */\n\n| . read_file( $path ) . qq|\n</style>| :
155                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;                                  qq|<link type="text/css" rel="stylesheet" href="/$path" media="screen">|;
156                  } elsif ( $path =~ m{<.+>}s ) {                  } elsif ( $path =~ m{<.+>}s ) {
157                          $out .= $path;                          $out .= $path;
# Line 170  sub add_head { Line 193  sub add_head {
193    
194  }  }
195    
196    sub _add_css_js {
197            my ( $self, $what, $content ) = @_;
198    
199            my $tag  = $what eq 'css' ? 'style'    : 'script';
200            my $type = $what eq 'css' ? 'text/css' : 'text/javascript';
201            my $head;
202    
203            my ( $package, $path, $line ) = caller(1);
204    
205            $content = "/$content" if $content !~ m{[\n\r]} && -e $content;
206            if ( $content =~ $re_html && $what ne 'js' ) {
207                    $head = qq|
208                            $content
209                            <!-- $type via $package at $path line $line -->
210                    |;
211            } elsif ( $content =~ m{^(/\w+|https?://)} && $content !~ m{[\n\r]} ) {
212                    if ( $what eq 'js' ) {
213                            $head = qq|
214                                    <$tag type="$type" src="$content">
215                                    /* $what via $package at $path line $line */
216                                    </$tag>
217                            |;
218                    } else {
219                            $head = qq|
220                                    <link rel="stylesheet" type="$type" href="$content">
221                                    <!-- $what via $package at $path line $line -->
222                            |;
223                    }
224            } else {
225                    $head = qq|
226                            <$tag type="$type">
227                            /* via $package at $path line $line */
228                            $content
229                            </$tag>
230                    |;
231            };
232            $self->add_head( $head );
233    }
234    
235  sub add_css {  sub add_css {
236          my ($self,$css) = @_;          my ($self,$css) = @_;
237          my ( $package, $path, $line ) = caller;          $self->_add_css_js( 'css', $css );
238          $self->add_head( qq|  }
239          <style type="text/css">  
240          /* via $package at $path line $line */  sub add_js {
241          $css          my ($self,$js) = @_;
242          </style>          $self->_add_css_js( 'js', $js );
         | );  
243  }  }
244    
245  our $reload_counter = 0;  our $reload_counter = 0;
246    
247    
248  =head2 page  =head2 html_page
249    
250    $self->page(    $self->html_page(
251          title => 'page title',          title => 'page title',
252          head  => '<!-- optional head markup -->',          head  => '<!-- optional head markup -->',
253          body  => '<b>Page Body</b>',          body  => '<b>Page Body</b>',
# Line 199  sub status { @status }; Line 260  sub status { @status };
260    
261  our $icon_html;  our $icon_html;
262    
263  sub page {  sub html_page {
264          my $self = shift;          my $self = shift;
265          my $a = {@_};          my $a = {@_};
266    
         warn "## page ",dump($a);  
   
267          $reload_counter++;          $reload_counter++;
268    
269          my $status_line = '';          my $status_line = '';
# Line 224  sub page { Line 283  sub page {
283                  warn "# no body, invoke $self->$run on ", ref($self);                  warn "# no body, invoke $self->$run on ", ref($self);
284                  $body = $self->$run;                  $body = $self->$run;
285          }          }
286          if ( $self->content_type !~ m{html} ) {          if ( $self->content_type !~ m{html} || ! $self->wrap_in_page ) {
287                  warn "# return only $self body ", $self->content_type;                  warn "# return only $self body ", $self->content_type;
288                  return $body                  return $body
289          } elsif ( ! defined $body ) {          } elsif ( ! defined $body ) {
# Line 240  sub page { Line 299  sub page {
299    
300          my $right =          my $right =
301                  qq|                  qq|
302                          <span class="right">                          <span class="frey-status-right">
303                          <a title="reload $url"  href="/reload$url">reload</a>                          <a title="reload $url"  href="/reload$url">reload</a>
304                          <a title="$description" href="/exit$url">$exit</a>                          <a title="$description" href="/exit$url" target="exit">$exit</a>
305                          </span>                          </span>
306                  |;                  |;
307    
# Line 253  sub page { Line 312  sub page {
312    
313          $self->add_icon unless $icon_html;          $self->add_icon unless $icon_html;
314    
315            my $title = undef
316                    || $a->{title}
317                    || $self->title
318                    || ref($self)
319                    ;
320    
321    #       $title =~ s{(\w)\w+::}{$1:}g; # XXX compress names of classes
322    
323            $self->add_css(qq|
324                    body {
325                            padding-bottom: 3em; /* don't overlap status line */
326                    }
327            |);
328    
329          my $html = join("\n",          my $html = join("\n",
330                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,                  qq|<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head>|,
331                  $self->_head_html,                  $self->_head_html,
332                  '<title>' . ( $self->title || $a->{title} || ref($self) ) . '</title>',                  qq|<title>$title</title>|,
333                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',                  '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
334                  ( $icon_html || '<!-- no icon -->' ),                  ( $icon_html || '<!-- no icon -->' ),
335                  ( $a->{head} || '' ),                  ( $a->{head} || '' ),
# Line 298  sub editor { Line 371  sub editor {
371          qq|>$class</a>|;          qq|>$class</a>|;
372  }  }
373    
374  =head2 editor_links  =head2 html_links
375    
376  Create HTML links to editor for perl error message  Create HTML links to editor for perl error message
377    
378    my $html = $self->editor_links( $error )    my $html = $self->html_links( $error )
379    
380  =cut  =cut
381    
382  sub editor_links {  sub html_links {
383          my ( $self, $error ) = @_;          my ( $self, $error ) = @_;
384    
385            $error = $self->strip_full_path( $error );
386    
387  #       $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back  #       $error =~ s[(bless\({\s+.+?\s+},\s+)("[^"]+")(\) at)][<span class="frey-dropdown">$1<code>$2</code>$3</span>]gs; # FIXME insert bless hiding back
388    
389            # perl's backtrace
390          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}          $error =~ s{at\s+(\S+)\s+line\s+(\d+)}
391                  {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;
392    
393            $error =~ s{(via (?:package)\s+"?)([\w:]+)("?)}
394                    {$1<a target="$2" href="/$2" title="introspect $2">$2</a>$3}gsm
395            || # or anything that looks like "Class::Name"
396            $error =~ s{"(\w+(?:::\w+)+)"}
397                    {"<a target="$1" href="/$1" title="introspect $1">$1</a>"}gsm;
398    
399            # method error messages
400            # FIXME replace with link to Frey::Introspect data
401            $error =~ s{(method ")(\w+)(" via)}
402                    {$1<a target="$2" href="/Frey::Shell::Grep/as_markup?pattern=$2" title="grep $2">$2</a>$3}gsm;
403    
404            # link paths to editor
405            $error =~ s{((?:lib|t)/[\S]+)\s+(\d+\s+bytes)}
406                    {<a target="editor" href="/editor+$1+1" title="vi $1 [$2]">$1</a>}gsm;
407    
408          $error =~ s{(via (?:package) "?)([\w:]+)("?)}          $error =~ s{(class ")([\w:]+)(")}
409                  {$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;
410    
411          return $error;          return $error;
412  }  }
413    
414    sub html_self {
415            my $self = shift;
416            my $html = $self;
417            $html =~ s{([\w:]+)=}{<a target="$1" href="/$1" title="introspect $1">$1</a>=}gsm;
418            return $html;
419    }
420    
421    =head2 error
422    
423    This method will return error to browser and backtrace unless
424    error message ends with LF C<\n> just like L<warn>
425    
426    =cut
427    
428  sub error {  sub error {
429          my $self = shift;          my $self = shift;
430          my $error = join(" ", @_);          my $error = join(" ", @_);
431    
432          my @backtrace = $self->backtrace;          my $fatal = '';
433          $error .= "\n\t" . join( "\n\t", @backtrace ) if @backtrace;          my $backtrace = '';
434    
435            if ( $error !~ m{\n$} ) {
436                    if ( my @backtrace = $self->backtrace ) {
437                            $backtrace =
438                                      "\n" . $self->html_self . "->error backtrace\n\t"
439                                    . $self->html_links( join( "\n\t", @backtrace ) )
440                                    ;
441                            $fatal = qq| frey-fatal|;
442                    }
443            }
444    
445          warn "ERROR: $error\n";          warn "ERROR: $error\n";
446          return          $self->add_icon('error');
447                  qq|<pre class="frey-error">|          $error = $self->html_links( $error );
448                  . $self->editor_links( $error ) .          return qq|<pre class="frey-error$fatal">$error $backtrace</pre>| ;
                 qq|</pre>|  
                 ;  
449  }  }
450    
451  =head1 Status line  =head1 Status line
# Line 347  sub error { Line 460  sub error {
460    
461  sub add_status {  sub add_status {
462          my ( $self, $data ) = @_;          my ( $self, $data ) = @_;
463          push @status, { 'X' => [ $self->backtrace ] };          die "no data" unless $data;
464          if ( ref($data) ) {          if ( ref $data  ) {
465                  push @status, $data;                  push @status, $data;
466          } else {          } else {
467                  if ( defined $status[ $#status ] ) {                  if ( defined $status[ $#status ] ) {
# Line 370  Called at beginning of each request Line 483  Called at beginning of each request
483  sub clean_status {  sub clean_status {
484          my ($self) = shift;          my ($self) = shift;
485          @head = ( 'static/frey.css' );          @head = ( 'static/frey.css' );
         my $params = { request_url => $self->request_url };  
486          @status = (          @status = (
487                  { 'ClassBrowser' => Frey::ClassBrowser->new( %$params, usage_on_top => 0 )->as_markup },                  { 'ClassBrowser' => Frey::Class::Browser->new( usage_sort => 1, usage_on_top => 0 )->as_markup },
488                  { 'Bookmarklets' => Frey::Bookmarklet->new( %$params )->as_markup },                  { 'Bookmarklets' => Frey::Bookmarklet->new->as_markup },
489                  { 'INC' => Frey::INC->new( %$params )->as_markup },                  { 'INC' => Frey::INC->new->as_markup },
490          );          );
491          $icon_html = '';          $icon_html = '';
492  }  }
# Line 409  sub DEMOLISH { Line 521  sub DEMOLISH {
521    
522  sub icon_path {  sub icon_path {
523          my ($self,$class,$variant) = @_;          my ($self,$class,$variant) = @_;
524          my $icon = $class;  
525          $icon =~ s{::}{/}g;          sub icon_exists {
526          $icon .= "/$variant" if $variant;                  my $class = shift;
527          my $path = 'static/icons/' . $icon . '.png';                  $class =~ s{::}{/}g;
528          if ( -e $path ) {                  $class .= "/$variant" if $variant;
529                  warn "# $class from $self icon_path $path" if $self->debug;                  my $icon_path = 'static/icons/' . $class . '.png';
530                  return $path;                  return $icon_path if -e $icon_path;
531          } else {                  return;
532                  $self->TODO( "add $path icon for $class" );          }
533    
534            my $path = icon_exists( $class );
535            if ( ! $path ) {
536                    my $super_class = $class;
537                    while ( $super_class =~ s{::[^:]+$}{} && ! $path ) {
538                            $path = icon_exists( $super_class ) unless $super_class eq 'Frey'; # don't default on Frey icon
539                    }
540            }
541    
542            if ( ! $path ) {
543                    $self->TODO( "add icon for $class" . ( $variant ? " variant $variant" : '' ) );
544                  return undef;                  return undef;
545          }          }
546    
547            warn "# $class from $self icon_path $path" if $self->debug;
548            return $path;
549  }  }
550    
551  sub add_icon {  sub add_icon {
552          my ($self,$variant) = @_;          my ($self,$variant) = @_;
553    
554          my $class = ref($self);          my $class = $self->class if $self->can('class');
555          $class = $self->class if $self->can('class');          #$class ||= $self->title;
556            $class ||= ref($self);
557          my $icon_path = $self->icon_path( $class, $variant ) || return;          my $icon_path = $self->icon_path( $class, $variant ) || return;
558    
559          $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 459  my $multiline_markers = { Line 586  my $multiline_markers = {
586          '"' => '"',          '"' => '"',
587  };  };
588    
589    =for later
590    
591  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';  my $multiline_re = '[\\' . join('\\', keys %$multiline_markers ) . ']';
592  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";  warn "## multiline markers ", dump( $multiline_markers ), " -> $multiline_re";
593    
594    =cut
595    
596  sub log_path {  sub log_path {
597          $Frey::Bootstrap::log_path || warn "no log_path?";          $Frey::Bootstrap::log_path || die "no log_path?";
598  }  }
599    
600    our $pwd = `pwd`;
601    chomp $pwd;
602    
603    sub strip_full_path {
604            my ($self, $msg) = @_;
605            # Mojo seems to expand warn messages to full path which is annoying
606            $msg =~ s{/[^/]+/\.\./}{/}gs;
607            $msg =~ s{$pwd/*}{}gs;
608            return $msg;
609    }
610    
611    our $last_log_pos  = 0;
612    our $last_log_line = 0;
613    
614  sub warnings_html {  sub warnings_html {
615          my ($self,$level) = shift;          my ($self,$level) = shift;
616          $level ||= $self->debug,          $level ||= $self->debug,
# Line 474  sub warnings_html { Line 619  sub warnings_html {
619          my $max = 30;          my $max = 30;
620          my $pos = 0;          my $pos = 0;
621          my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines          my @warnings = ( '' x $max ); # XXX circualar buffer for 50 lines
622          my $line = 0;          my $line = $last_log_line;
623          my $multiline_end;          my $multiline_end;
624    
625          # XXX do we really want to do this every time?          # XXX do we really want to do this every time?
# Line 488  sub warnings_html { Line 633  sub warnings_html {
633          }          }
634          $self->add_css( $css );          $self->add_css( $css );
635    
636          open(my $log, '<', $path) || die "can't open $path: $!";          open(my $log, '<', $path)    || die "can't open $path: $!";
637            seek($log, $last_log_pos, 0) || warn "can't seek: $!";
638          while(<$log>) {          while(<$log>) {
639                  chomp;                  chomp;
640                  $line++;                  $line++;
641    
642                    next if m{^\s+(Mojo|Class::MOP|Moose)::};
643    
644                  my $style = '';                  my $style = '';
645    
646  =for filter  =for filter
# Line 517  sub warnings_html { Line 665  sub warnings_html {
665                  if ( m{^(#*)} ) {                  if ( m{^(#*)} ) {
666    
667                          my $level = $1;                          my $level = $1;
668                          my $msg = $_;                          my $msg = $self->strip_full_path( $_ );
669    
670                          my $spacer = ' ';                          my $spacer = ' ';
671                          my $real_msg = expand( $msg );                          my $real_msg = expand( $msg );
# Line 542  sub warnings_html { Line 690  sub warnings_html {
690                          $warnings[ $pos++ % $max ] = $msg;                          $warnings[ $pos++ % $max ] = $msg;
691                  }                  }
692          }          }
693          warn "log has $line lines tell position ",tell($log);          $last_log_pos = tell($log);
694            $last_log_line = $line;
695            warn "log has $line lines tell position $last_log_pos";
696          close($log) || die "can't close $path: $!";          close($log) || die "can't close $path: $!";
697    
698          my $size = -s $path;          my $size = -s $path;
# Line 556  sub warnings_html { Line 706  sub warnings_html {
706          return          return
707                  # need to wrap editor link into span so we can have links in warnings                  # need to wrap editor link into span so we can have links in warnings
708                    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>|                    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>|
709                  . $self->editor_links( $warnings )                  . $self->html_links( $warnings )
710                  . qq|</code></span></a>|                  . qq|</code></span>|
711                  ;                  ;
712  }  }
713    
# Line 574  sub backtrace { Line 724  sub backtrace {
724          my ($self) = @_;          my ($self) = @_;
725    
726          my @backtrace;          my @backtrace;
727          foreach ( 0 .. 5 ) {          foreach ( 1 .. 5 ) { # 0 = backtrace
728                  my (                  my (
729                          $package,$path,$line                          $package,$path,$line
730                          # subroutine hasargs                          # subroutine hasargs
# Line 583  sub backtrace { Line 733  sub backtrace {
733                  ) = caller($_) or last;                  ) = caller($_) or last;
734    
735                  push @backtrace,                  push @backtrace,
736                          qq|via $package at $path line $line|;                          qq|via "$package" at $path line $line|;
737          }          }
738          #warn "# backtrace: ", dump( @backtrace ) if @backtrace;          #warn "# backtrace: ", dump( @backtrace ) if @backtrace;
739          return @backtrace;          return @backtrace;
740  }  }
741    
742    =head2 checkbox
743    
744    Generate checkbox html markup from some attribute
745    
746      my $html = $self->checkbox('attribute_name', $value);
747    
748    =cut
749    
750    sub checkbox {
751            my ($self,$name,$value) = @_;
752            my $checked = '';
753            my $all_checkboxes = eval { $self->$name };
754            warn "ERROR tried to get checkbox value for '$name' which is unknown: $@" if $@;
755            $all_checkboxes = [ $all_checkboxes ] unless ref($all_checkboxes) eq 'ARRAY'; # sigh, too chatty
756            $checked = ' checked' if grep { defined $_ && $_ eq $value } @$all_checkboxes;
757            warn "# checkbox $name $value $checked\t", $self->dump( $self->$name );
758            qq|<input name="$name" value="$value" type="checkbox"$checked>|;
759    }
760    
761    =head2 strip
762    
763    Strip whitespace around content
764    
765      my $stripped = strip('  no more whitespace around this   ');
766    
767    =cut
768    
769    sub strip {
770            my $t = shift;
771            $t =~ s{^\s+}{}gs;
772            $t =~ s{>\s+<}{><}gs;
773            $t =~ s{\s+$}{}gs;
774            return $t;
775    }
776    
777  1;  1;

Legend:
Removed from v.625  
changed lines
  Added in v.1045

  ViewVC Help
Powered by ViewVC 1.1.26