/[Frey]/trunk/lib/Frey/Shell/Grep.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Shell/Grep.pm

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

revision 638 by dpavlin, Sun Nov 30 14:52:01 2008 UTC revision 670 by dpavlin, Tue Dec 2 01:16:20 2008 UTC
# Line 5  extends 'Frey'; Line 5  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6  #with 'Frey::Storage';  #with 'Frey::Storage';
7    
8    use English;
9    
10  has pattern => (  has pattern => (
11          documentation => 'grep for pattern',          documentation => 'grep pattern',
12          is => 'rw',          is => 'rw',
13          isa => 'Str',          isa => 'Str',
14          required => 1,          required => 1,
# Line 16  has pattern => ( Line 18  has pattern => (
18  sub as_markup {  sub as_markup {
19          my ($self) = @_;          my ($self) = @_;
20    
21          my $patt = $self->pattern || 'FIXME';          my $patt = $self->pattern;
22    
23          $self->title( $patt );          $self->title( $patt );
24    
25          my $cmd = 'grep -rn ' . $patt . ' lib/ t/';          my $cmd = 'grep -rn ' . $patt . ' lib/ t/';
26          warn "# $cmd";          warn "# $cmd";
27    
         my $html = qq|<h1>$patt</h1><dl>|;  
28          my $last_path = '';          my $last_path = '';
29    
30          $self->add_css(qq|          $self->add_css(qq|
# Line 36  sub as_markup { Line 37  sub as_markup {
37                  }                  }
38          |);          |);
39    
40          open(my $fh, '-|', $cmd) or die "ack: $@";          my $html;
41    
42            open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";
43          while(<$fh>) {          while(<$fh>) {
44                  my ( $path, $line, $text ) = split(/:/,$_,3);                  my ( $path, $line, $text ) = split(/:/,$_,3);
45                    $text = $self->html_escape( $text );
46                  if ( $path ne $last_path ) {                  if ( $path ne $last_path ) {
47                          $html .= qq|<dt>$path</dt>|;                          $html .= qq|<dt>$path</dt>|;
48                  }                  }
# Line 46  sub as_markup { Line 50  sub as_markup {
50                  $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;                  $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
51                  $last_path = $path;                  $last_path = $path;
52          }          }
53          close($fh) || die $!;          if ( $INPUT_LINE_NUMBER > 0 ) { # closing pipe grep output results in error
54                    close($fh) || die "can't close pipe to $cmd $!";
55    
56                    $html = qq|
57                            <h1>$patt</h1>
58                            <dl>$html</dl>
59                    |;
60    
61          $html .= qq|</dl>|;          } else {
62    
63                    $html = $self->error( "No results for $patt\n" );
64    
65            }
66    
67          return $html;          return $html;
68  }  }

Legend:
Removed from v.638  
changed lines
  Added in v.670

  ViewVC Help
Powered by ViewVC 1.1.26