/[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 670 - (hide annotations)
Tue Dec 2 01:16:20 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 1196 byte(s)
escape diff to html
1 dpavlin 638 package Frey::Shell::Grep;
2     use Moose;
3    
4     extends 'Frey';
5     with 'Frey::Web';
6     #with 'Frey::Storage';
7    
8 dpavlin 661 use English;
9    
10 dpavlin 638 has pattern => (
11 dpavlin 670 documentation => 'grep pattern',
12 dpavlin 638 is => 'rw',
13     isa => 'Str',
14     required => 1,
15     default => 'FIXME',
16     );
17    
18     sub as_markup {
19     my ($self) = @_;
20    
21 dpavlin 666 my $patt = $self->pattern;
22 dpavlin 638
23     $self->title( $patt );
24    
25     my $cmd = 'grep -rn ' . $patt . ' lib/ t/';
26     warn "# $cmd";
27    
28     my $last_path = '';
29    
30     $self->add_css(qq|
31     dd a {
32     float: left;
33     width: 3em;
34     }
35     dd code b {
36     background-color: #ff8;
37     }
38     |);
39    
40 dpavlin 666 my $html;
41    
42 dpavlin 661 open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";
43 dpavlin 638 while(<$fh>) {
44     my ( $path, $line, $text ) = split(/:/,$_,3);
45 dpavlin 670 $text = $self->html_escape( $text );
46 dpavlin 638 if ( $path ne $last_path ) {
47     $html .= qq|<dt>$path</dt>|;
48     }
49     $text =~ s{(\Q$patt\E)}{<b>$1</b>};
50     $html .= qq|<dd><a target="editor" href="/editor+$path+$line">$line</a> <code>$text</code>|;
51     $last_path = $path;
52     }
53 dpavlin 661 if ( $INPUT_LINE_NUMBER > 0 ) { # closing pipe grep output results in error
54     close($fh) || die "can't close pipe to $cmd $!";
55 dpavlin 666
56     $html = qq|
57     <h1>$patt</h1>
58     <dl>$html</dl>
59     |;
60    
61     } else {
62    
63     $html = $self->error( "No results for $patt\n" );
64    
65 dpavlin 661 }
66 dpavlin 638
67     return $html;
68     }
69    
70     1;

  ViewVC Help
Powered by ViewVC 1.1.26