NG/Log.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
process_log
2.0
BEGIN
2.0
CRAP 2.0
1 package Log;
2 use strict;
3 use warnings;
4 use autodie;
5 use 5.010;
6 use base qw(Object);
7 use Hashtable;
8 use Array;
9 use Geo::IP;
10  
11 sub new {
12 my $pkg = shift;
13 return bless {}, $pkg;
14 }
15  
16 =head1 process_log
17 my $logpath = '/opt/graphite/storage/log/webapp/access.log';
18 process_log($logpath, sub {
19 my ($fields) = @_; # 第一个参数是 Array 类型
20 say $fields->get(6); # 获取第6个字段
21 });
22 #}, '&');
23 =cut
24  
25 sub process_log {
26 my $logpath = shift;
27 my $cb = shift;
28 my $sep = shift || qr/\s+/;
29 open my $fh, '<', $logpath;
30 while (<$fh>) {
31 chomp;
32 my $lines = Array->new( split( $sep, $_ ) );
33 $cb->($lines);
34 }
35 }
36  
37 1;