/[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 716 by dpavlin, Thu Dec 4 17:35:11 2008 UTC revision 967 by dpavlin, Fri Jan 9 14:52:13 2009 UTC
# Line 19  has path => ( Line 19  has path => (
19          is => 'rw',          is => 'rw',
20          isa => 'Str',          isa => 'Str',
21          required => 1,          required => 1,
22          default => 'lib/ t/ etc/',          default => 'bin/ lib/ static/Frey/ t/ etc/',
23  );  );
24    
25  has _grep_command => (  has _grep_command => (
# Line 38  sub { Line 38  sub {
38          my ($self) = @_;          my ($self) = @_;
39    
40          my $patt = $self->pattern;          my $patt = $self->pattern;
41            my $opt = '';
42            $opt = '--' if $patt =~ m{^-};
43    
44          my $cmd = 'grep -rn ' . $patt . ' ' . $self->path;          if ( $patt =~ m{'} ) {
45          $self->_grep_command( $cmd );                  $patt = qq|"$patt"|;
46            } else {
47                    $patt = qq|'$patt'|;
48            }
49    
50            my $cmd = qq|grep -rn $opt $patt | . $self->path;
51          warn "# $cmd";          warn "# $cmd";
52            $self->_grep_command( $cmd );
53    
54          my @results;          my @results;
55    
# Line 65  sub { Line 73  sub {
73  });  });
74    
75  sub as_markup {  sub as_markup {
76          my ($self) = @_;          my $self = shift;
77            my $callback = {@_};
78    
79            warn "# callbacks: ",$self->dump( $callback ) if $callback;
80    
81          my $patt = $self->pattern;          my $patt = $self->pattern;
82          $self->title( $patt );          $self->title( $patt );
# Line 91  sub as_markup { Line 102  sub as_markup {
102    
103          foreach my $result ( @{ $self->results_as_data } ) {          foreach my $result ( @{ $self->results_as_data } ) {
104    
105                  warn $self->dump( $result );                  warn $self->dump( $result ) if $self->debug;
106    
107                  my $text = $result->{text} || die "no text";                  my $text = $result->{text} || die "no text";
108    
                 $text = $self->html_escape( $text );  
109                  if ( my $path = $result->{path} ) {                  if ( my $path = $result->{path} ) {
110                          my $line = $result->{line} || die "no line";                          my $line = $result->{line} || die "no line";
111                          if ( $path ne $last_path ) {                          if ( $path ne $last_path ) {
112                                  $html .= qq|<dt class="p">$path</dt>|;                                  $html .= qq|<dt class="p">$path</dt>|;
113                          }                          }
114                          $text =~ s{(\Q$patt\E)}{<b>$1</b>};                          if ( my $dd = $callback->{dd} ) {
115                          $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;                                  $html .= $dd->( $patt, $path, $line, $text );
116                            } else {
117                                    $text = $self->html_escape( $text );
118                                    $text =~ s{(\Q$patt\E)}{<b>$1</b>};
119                                    $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
120                            }
121                          $last_path = $path;                          $last_path = $path;
122                  } else {                  } else {
123                            $text = $self->html_escape( $text );
124                          $html .= qq|<dt>$text</dt>|;                          $html .= qq|<dt>$text</dt>|;
125                  }                  }
126          }          }
# Line 120  sub as_markup { Line 136  sub as_markup {
136                  $html = $self->error( "No results for $patt\n" );                  $html = $self->error( "No results for $patt\n" );
137          }          }
138    
139            $self->add_head(qq|
140                    <link rel="search" type="application/opensearchdescription+xml" title="Frey::Shell::Grep" href="/Frey::OpenSearch/grep_as_markup">
141            |);
142    
143          return $html;          return $html;
144  }  }
145    

Legend:
Removed from v.716  
changed lines
  Added in v.967

  ViewVC Help
Powered by ViewVC 1.1.26