IMP/Example/IRCShout.pm

filter: Statementstmt 44.0% 22 / 50 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 63.6% 7 / 11 Podpod 50.0% 2 / 4 totaltotal 34.8% 31 / 89 CC 10 SCAR 40.2
CC
10
Cov
31%
data
110.0
INTERFACE
2.0
new_analyzer
2.0
CRAP 55.6
« IMP/Debug.pm ↑ Summary IMP/Pattern.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Net::IMP::Example::IRCShout;
5 1 ▶use base 'Net::IMP::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use fields (
7 1 'pos', # current position in stream
8 'line', # buffer for unfinished lines
9 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Net::IMP; # import IMP_ constants
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Net::IMP::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub INTERFACE {
16 return ([
17 0 ▶ IMP_DATA_STREAM,
Subroutine INTERFACE: not called CC=1 SCAR=6.9
Pod undocumented
18 [ IMP_PASS, IMP_REPLACE ]
19 ])
20 }
21  
22  
23 # create new analyzer object
24 sub new_analyzer {
25 0 ▶ my ($factory,%args) = @_;
Subroutine new_analyzer: not called CC=1 SCAR=6.9
Pod documented
26 0 my $self = $factory->SUPER::new_analyzer(%args);
27  
28 0 $self->run_callback(
29 # we are not interested in data from server
30 [ IMP_PASS, 1, IMP_MAXOFFSET ],
31 );
32  
33 0 $self->{line} = '';
34 0 $self->{pos} = 0;
35 0 return $self;
36 }
37  
38 sub data {
39 0 ▶ my ($self,$dir,$data) = @_;
Subroutine data: not called CC=10 SCAR=47.0
Pod documented
40 0 ▶ return if $dir == 1; # should not happen
Branch: 1 branch
BranchTrueFalseTotal
if $dir == 1 0 0 0
41 0 ▶ if ( $data eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data eq "") 0 0 0
42 # eof
43 0 $self->run_callback([ IMP_PASS,0,IMP_MAXOFFSET ]);
44 0 return;
45 }
46  
47 0 $self->{line} .= $data;
48  
49 0 my @rv;
50 0 ▶ while ( $self->{line} =~s{\A([^\n]*\n)}{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"line"} =~ s/\A([^\n]*\n)//) 0 0 0
51 0 my $line = $1;
52 0 $self->{pos} += length($line);
53 0 ▶ if ( shout(\$line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (shout(\$line)) { } 0 0 0
54 0 ▶ if ( @rv and $rv[-1][0] == IMP_REPLACE ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rv and $rv[-1][0] == 4113) { } 0 0 0
Condition0%0/3
@rv and $rv[-1][0] == "replace"
!ll&&!rl&&r
000
MC/DC0%0/2
@rv and $rv[-1][0] == "replace"
@rv $rv[-1][0] == "replace"
Truth table0%0/3
A and B
A= @rvB= $rv[-1][0] == "replace"
ABresult
0X0
100
111
55 # update last replacement
56 0 $rv[-1][2] = $self->{pos};
57 0 $rv[-1][3].= $line;
58 } else {
59 # add new replacement
60 0 push @rv, [ IMP_REPLACE,0,$self->{pos},$line ];
61 }
62 } else {
63 0 ▶ if ( @rv and $rv[-1][0] == IMP_PASS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rv and $rv[-1][0] == 4097) { } 0 0 0
Condition0%0/3
@rv and $rv[-1][0] == "pass"
!ll&&!rl&&r
000
MC/DC0%0/2
@rv and $rv[-1][0] == "pass"
@rv $rv[-1][0] == "pass"
Truth table0%0/3
A and B
A= @rvB= $rv[-1][0] == "pass"
ABresult
0X0
100
111
64 # update last pass
65 0 $rv[-1][2] = $self->{pos};
66 } else {
67 # add new pass
68 0 push @rv, [ IMP_PASS,0,$self->{pos} ];
69 }
70 }
71 }
72 0 ▶ $self->run_callback(@rv) if @rv;
Branch: 1 branch
BranchTrueFalseTotal
if @rv 0 0 0
73 }
74  
75  
76 sub shout {
77 0 ▶ my $line = shift;
Subroutine shout: not called CC=1 SCAR=6.9
Pod undocumented
78 0 return $$line =~s{\A
79 (
80 (?: :\S+\x20+ )? # opt msg prefix
81 PRIVMSG\x20+\S+\x20+ # privmsg rcpt
82 )
83 (.+) # message
84 }{$1\U$2}x # shout message
85 }
86  
87 1 1;
88  
89 __END__
« IMP/Debug.pm ↑ Summary IMP/Pattern.pm »