line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::dategrep::Iterators; |
2
|
8
|
|
|
8
|
|
28
|
use strict; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
210
|
|
3
|
8
|
|
|
8
|
|
26
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
194
|
|
4
|
8
|
|
|
8
|
|
3574
|
use Moo; |
|
8
|
|
|
|
|
73987
|
|
|
8
|
|
|
|
|
37
|
|
5
|
8
|
|
|
8
|
|
8216
|
use App::dategrep::Date qw(date_to_epoch); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
290
|
|
6
|
8
|
|
|
8
|
|
2846
|
use App::dategrep::Iterator::File; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
229
|
|
7
|
8
|
|
|
8
|
|
3013
|
use App::dategrep::Iterator::Stdin; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
195
|
|
8
|
8
|
|
|
8
|
|
2729
|
use App::dategrep::Iterator::Uncompress; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
3008
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has iterators => ( is => 'rw', default => sub { [] } ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub as_array { |
13
|
34
|
|
|
34
|
0
|
28
|
return @{ shift->iterators }; |
|
34
|
|
|
|
|
180
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub BUILDARGS { |
17
|
27
|
|
|
27
|
0
|
5864
|
my ( $class, %options ) = @_; |
18
|
|
|
|
|
|
|
my @filenames = |
19
|
27
|
50
|
|
|
|
81
|
ref $options{filenames} ? @{ $options{filenames} } : $options{filenames}; |
|
27
|
|
|
|
|
71
|
|
20
|
|
|
|
|
|
|
my @args = ( |
21
|
|
|
|
|
|
|
start => $options{start}, |
22
|
|
|
|
|
|
|
end => $options{end}, |
23
|
|
|
|
|
|
|
multiline => $options{multiline}, |
24
|
|
|
|
|
|
|
format => $options{format}, |
25
|
27
|
|
|
|
|
110
|
skip_unparsable => $options{'skip-unparsable'}, |
26
|
|
|
|
|
|
|
); |
27
|
27
|
|
|
|
|
26
|
my @iterators; |
28
|
27
|
|
|
|
|
53
|
for my $filename (@filenames) { |
29
|
31
|
100
|
|
|
|
1456
|
if ( $filename eq '-' ) { |
|
|
100
|
|
|
|
|
|
30
|
3
|
|
|
|
|
46
|
push @iterators, App::dategrep::Iterator::Stdin->new(@args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( $filename =~ /\.(bz|bz2|gz|z)$/ ) { |
33
|
4
|
|
|
|
|
88
|
push @iterators, |
34
|
|
|
|
|
|
|
App::dategrep::Iterator::Uncompress->new( @args, |
35
|
|
|
|
|
|
|
filename => $filename ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
24
|
|
|
|
|
372
|
push @iterators, |
39
|
|
|
|
|
|
|
App::dategrep::Iterator::File->new( @args, |
40
|
|
|
|
|
|
|
filename => $filename ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
27
|
|
|
|
|
7485
|
return { iterators => \@iterators }; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub sort { |
47
|
8
|
|
|
8
|
0
|
9
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
8
|
my @timestamps; |
50
|
8
|
|
|
|
|
16
|
for my $iterator ( $self->as_array ) { |
51
|
20
|
|
|
|
|
65
|
my $entry = $iterator->peek_entry; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## remove all iterators with eof |
54
|
20
|
100
|
|
|
|
36
|
next if not defined $entry; |
55
|
|
|
|
|
|
|
|
56
|
17
|
|
|
|
|
54
|
my ( $epoch, $error ) = date_to_epoch( $entry, $iterator->format ); |
57
|
17
|
50
|
|
|
|
3008
|
if ( !$epoch ) { |
58
|
|
|
|
|
|
|
## TODO Which iterator produced the error? |
59
|
0
|
|
|
|
|
0
|
die "No date found in first line: $error\n"; |
60
|
|
|
|
|
|
|
} |
61
|
17
|
|
|
|
|
36
|
push @timestamps, [ $epoch, $iterator ]; |
62
|
|
|
|
|
|
|
} |
63
|
8
|
|
|
|
|
32
|
$self->iterators([ map { $_->[1] } sort { $a->[0] <=> $b->[0] } @timestamps ]); |
|
17
|
|
|
|
|
94
|
|
|
13
|
|
|
|
|
21
|
|
64
|
8
|
|
|
|
|
28
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub interleave { |
68
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
69
|
1
|
|
|
|
|
3
|
while ( $self->sort, $self->iterators->[0] ) { |
70
|
6
|
|
|
|
|
33
|
print $self->iterators->[0]->get_entry; |
71
|
|
|
|
|
|
|
} |
72
|
1
|
|
|
|
|
2
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |