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 |
|
|
73 |
}); |
}); |
74 |
|
|
75 |
sub as_markup { |
sub as_markup { |
76 |
my ($self) = @_; |
my $self = shift; |
77 |
|
my $callback = {@_}; |
78 |
|
|
79 |
my $patt = $self->pattern; |
my $patt = $self->pattern; |
80 |
$self->title( $patt ); |
$self->title( $patt ); |
100 |
|
|
101 |
foreach my $result ( @{ $self->results_as_data } ) { |
foreach my $result ( @{ $self->results_as_data } ) { |
102 |
|
|
103 |
warn $self->dump( $result ); |
warn $self->dump( $result ) if $self->debug; |
104 |
|
|
105 |
my $text = $result->{text} || die "no text"; |
my $text = $result->{text} || die "no text"; |
106 |
|
|
110 |
if ( $path ne $last_path ) { |
if ( $path ne $last_path ) { |
111 |
$html .= qq|<dt class="p">$path</dt>|; |
$html .= qq|<dt class="p">$path</dt>|; |
112 |
} |
} |
113 |
$text =~ s{(\Q$patt\E)}{<b>$1</b>}; |
if ( my $dd = $callback->{dd} ) { |
114 |
$html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|; |
$html .= $dd->( $patt, $path, $line, $text ); |
115 |
|
} else { |
116 |
|
$text =~ s{(\Q$patt\E)}{<b>$1</b>}; |
117 |
|
$html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|; |
118 |
|
} |
119 |
$last_path = $path; |
$last_path = $path; |
120 |
} else { |
} else { |
121 |
$html .= qq|<dt>$text</dt>|; |
$html .= qq|<dt>$text</dt>|; |
133 |
$html = $self->error( "No results for $patt\n" ); |
$html = $self->error( "No results for $patt\n" ); |
134 |
} |
} |
135 |
|
|
136 |
|
$self->add_head(qq| |
137 |
|
<link rel="search" type="application/opensearchdescription+xml" title="Frey::Shell::Grep" href="/Frey::OpenSearch/grep_as_markup"> |
138 |
|
|); |
139 |
|
|
140 |
return $html; |
return $html; |
141 |
} |
} |
142 |
|
|