Filter/Syslog.pm

filter: Statementstmt 100% 41 / 41 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 9 / 18 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 88.8% 8 / 9 Podpod 100% 5 / 5 totaltotal 76.2% 74 / 97 CC 13 SCAR 17.3
CC
13
Cov
83%
get
9.2
get_one
6.2
BEGIN
1.0
CRAP 5.6
« 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  
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Time::ParseDate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 our $VERSION = '1.20';
11  
12 9 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 sub new {
25 10 ▶ return bless {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
26 buffer => '',
27 }, shift;
28 }
29  
30 sub get_one_start {
31 6 ▶ my $self = shift;
Subroutine get_one_start: called CC=1 SCAR=0.0
Pod documented
32 6 my $input = shift;
33 6 $self->{buffer} .= join("",@$input);
34 }
35  
36 sub get {
37 5 ▶ my $self = shift;
Subroutine get: called CC=8 SCAR=22.2
Pod documented
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();
Condition66%2/3
$time ||= time
l!l&&r!l&&!r
310
MC/DC0%0/2
$time ||= time
$time time
Truth table66%2/3
A ||= B
A= $timeB= time
ABresult
1X1
011
000
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 sub get_one {
64 12 ▶ my $self = shift;
Subroutine get_one: called CC=6 SCAR=18.3
Pod documented
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 ▶sub put {} # XXX
Subroutine put: not called CC=1 SCAR=0.0
Pod documented
87  
88 9 1;
89 __END__
« Component/Server/Syslog/UDP.pm ↑ Summary Component/Server/Syslog.pm »