/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 638 - (hide annotations)
Sun Nov 30 14:52:01 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 956 byte(s)
wrap grep -rn into dl/dt/dd list with edit links
1 dpavlin 638 package Frey::Shell::Grep;
2     use Moose;
3    
4     extends 'Frey';
5     with 'Frey::Web';
6     #with 'Frey::Storage';
7    
8     has pattern => (
9     documentation => 'grep for pattern',
10     is => 'rw',
11     isa => 'Str',
12     required => 1,
13     default => 'FIXME',
14     );
15    
16     sub as_markup {
17     my ($self) = @_;
18    
19     my $patt = $self->pattern || 'FIXME';
20    
21     $self->title( $patt );
22    
23     my $cmd = 'grep -rn ' . $patt . ' lib/ t/';
24     warn "# $cmd";
25    
26     my $html = qq|<h1>$patt</h1><dl>|;
27     my $last_path = '';
28    
29     $self->add_css(qq|
30     dd a {
31     float: left;
32     width: 3em;
33     }
34     dd code b {
35     background-color: #ff8;
36     }
37     |);
38    
39     open(my $fh, '-|', $cmd) or die "ack: $@";
40     while(<$fh>) {
41     my ( $path, $line, $text ) = split(/:/,$_,3);
42     if ( $path ne $last_path ) {
43     $html .= qq|<dt>$path</dt>|;
44     }
45     $text =~ s{(\Q$patt\E)}{<b>$1</b>};
46     $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
47     $last_path = $path;
48     }
49     close($fh) || die $!;
50    
51     $html .= qq|</dl>|;
52    
53     return $html;
54     }
55    
56     1;

  ViewVC Help
Powered by ViewVC 1.1.26