Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 98 lines (68 sloc) 1.431 kB
1053cc3 Merging https://ack.googlecode.com/svn/branches/plugins-v2 down to trunk
petdance authored
1 package App::Ack::Plugin::Tar;
2
3 package App::Ack::Repository::Tar;
4
5 use Archive::Tar;
6
7 sub extensions_handled {
8 return qw( .tar .gz .tgz .tar.gz );
9 }
10
11 sub new {
12 my $class = shift;
13 my $filename = shift;
14
15 my $self = bless {
16 filename => $filename,
17 }, $class;
18
19 my $tar = Archive::Tar->new( $filename );
20 if ( !$tar ) {
21 return;
22 }
23
24 $self->{tar} = $tar;
25 $self->{files} = [$tar->get_files];
26
27 return $self;
28 }
29
30 sub next_resource {
31 my $self = shift;
32
33 my $file = shift @{$self->{files}};
34
35 return unless $file;
36
37 my $tar = $self->{tar};
38 my $res = App::Ack::Resource::Tar->new( $self->{filename}, $file->name, $file->get_content );
39
40 return $res;
41 }
42
43 sub close {
44 }
45
46
47 package App::Ack::Resource::Tar;
48
49 sub new {
50 my $class = shift;
51 my $tarname = shift;
52 my $filename = shift;
53 my $content = shift;
54
55 my $self = bless {
56 tarname => $tarname,
57 filename => $filename,
58 lines => [split( /\n/, $content )],
59 lineno => 0,
60 }, $class;
61
62 return $self;
63 }
64
65 sub is_binary {
66 return;
67 }
68
69 sub name {
70 my $self = shift;
71
72 return $self->{filename};
73 }
74
75 sub needs_line_scan {
76 1; # XXX Do actual looking
77 }
78
79 sub reset {
80 }
81
82 sub next_text {
83 my $self = shift;
84
85 $_ = shift @{$self->{lines}};
86 if ( defined $_ ) {
87 $. = $self->{lineno}++;
88 return 1;
89 }
90
91 return 0;
92 }
93
94 sub close {
95 }
96
97 1;
Something went wrong with that request. Please try again.