Filter/Syslog.pm

filter: Statementstmt 100% 41 / 41 Branchbran 75.0% 9 / 12 Conditioncond 52.9% 9 / 17 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 88.8% 8 / 9 Podpod 100% 5 / 5 totaltotal 78.9% 75 / 95 CC 13 SCAR 17.0
CC
13
Cov
84%
get
8.9
get_one
6.2
BEGIN
1.0
CRAP 5.5
« Component/Server/Syslog/UDP.pm ↑ Summary Component/Server/Syslog.pm »
1 # $Id: Syslog.pm 579 2005-11-20 22:52:26Z sungo $
2 package POE::Filter::Syslog;
3 11 $POE::Filter::Syslog::VERSION = '1.22';
4 #ABSTRACT: syslog parser
5  
6 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Time::ParseDate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 11 our $SYSLOG_REGEXP = q|
13 ^<(\d+)> # priority -- 1
14 (?:
15 (\S{3})\s+(\d+) # month day -- 2, 3
16 \s
17 (\d+):(\d+):(\d+) # time -- 4, 5, 6
18 )?
19 \s*
20 (.*) # text -- 7
21 $
22 |;
23  
24 10 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
25 10 return bless {
26 buffer => '',
27 }, shift;
28 }
29  
30 6 ▶sub get_one_start {
Subroutine get_one_start: called CC=1 SCAR=0.0
Pod documented
31 6 my $self = shift;
32 6 my $input = shift;
33 6 $self->{buffer} .= join("",@$input);
34 }
35  
36 5 ▶sub get {
Subroutine get: called CC=8 SCAR=21.9
Pod documented
37 5 my $self = shift;
38 5 my $incoming = shift;
39 5 ▶ return [] unless $incoming and @$incoming;
Branch: 1 branch
BranchTrueFalseTotal
unless $incoming and @$incoming 0 5 5
Condition33%1/3
$incoming and @$incoming
!ll&&!rl&&r
005
MC/DC0%0/2
$incoming and @$incoming
$incoming @$incoming
Truth table33%1/3
A and B
A= $incomingB= @$incoming
ABresult
0X0
100
111
40 5 my $stream = join ("", @$incoming);
41  
42 5 my @found;
43 5 ▶ if($stream and length $stream) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream and length $stream) 5 0 5
Condition33%1/3
$stream and length $stream
!ll&&!rl&&r
005
MC/DC0%0/2
$stream and length $stream
$stream length $stream
Truth table33%1/3
A and B
A= $streamB= length $stream
ABresult
0X0
100
111
44  
45 5 ▶ while ( $stream =~ s/$SYSLOG_REGEXP//sx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream =~ s/$POE::Filter::Syslog::SYSLOG_REGEXP//sx) 4 5 9
46 4 ▶ my $time = $2 && parsedate("$2 $3 $4:$5:$6");
Condition66%2/3
$2 && parsedate("$2 $3 $4:$5:$6")
!ll&&!rl&&r
103
MC/DC50%1/2
$2 && parsedate("$2 $3 $4:$5:$6")
$2 parsedate("$2 $3 $4:$5:$6")
Truth table66%2/3
A && B
A= $2B= parsedate("$2 $3 $4:$5:$6")
ABresult
0X0
100
111
47 4 ▶ $time ||= time();
Condition100%2/2
$time ||= time
l!l
31
MC/DC100%1/1
$time ||= time
$time
Truth table100%2/2
A
A= $time
Aresult
11
00
48  
49 4 my $msg = {
50 time => $time,
51 pri => $1,
52 facility => int($1/8),
53 severity => int($1%8),
54 msg => $7,
55 };
56 4 push @found, $msg;
57 }
58 }
59 5 return \@found;
60 }
61  
62  
63 12 ▶sub get_one {
Subroutine get_one: called CC=6 SCAR=18.3
Pod documented
64 12 my $self = shift;
65 12 my $found = 0;
66 12 ▶ if($self->{buffer} and length $self->{buffer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"buffer"} and length $self->{"buffer"}) 6 6 12
Condition66%2/3
$self->{"buffer"} and length $self->{"buffer"}
!ll&&!rl&&r
606
MC/DC50%1/2
$self->{"buffer"} and length $self->{"buffer"}
$self->{"buffer"} length $self->{"buffer"}
Truth table66%2/3
A and B
A= $self->{"buffer"}B= length $self->{"buffer"}
ABresult
0X0
100
111
67 6 ▶ if ( $self->{buffer} =~ s/$SYSLOG_REGEXP//sx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"buffer"} =~ s/$POE::Filter::Syslog::SYSLOG_REGEXP//sx) 6 0 6
68 6 ▶ my $time = $2 && parsedate("$2 $3 $4:$5:$6");
Condition33%1/3
$2 && parsedate("$2 $3 $4:$5:$6")
!ll&&!rl&&r
006
MC/DC0%0/2
$2 && parsedate("$2 $3 $4:$5:$6")
$2 parsedate("$2 $3 $4:$5:$6")
Truth table33%1/3
A && B
A= $2B= parsedate("$2 $3 $4:$5:$6")
ABresult
0X0
100
111
69 6 my $msg = {
70 time => $time,
71 pri => $1,
72 facility => int($1/8),
73 severity => int($1%8),
74 msg => $7,
75 };
76 6 $found = $msg;
77 }
78 }
79 12 ▶ if($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 6 6 12
80 6 return [ $found ];
81 } else {
82 6 return [];
83 }
84 }
85  
86 0 ▶sub put {} # XXX
Subroutine put: not called CC=1 SCAR=0.0
Pod documented
87  
88 11 1;
89  
90  
91 # sungo // vim: ts=4 sw=4 noexpandtab
92  
93 __END__
« Component/Server/Syslog/UDP.pm ↑ Summary Component/Server/Syslog.pm »