Tanker/RequestGenerator/IRC.pm

filter: Statementstmt 63.1% 36 / 57 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 5 totaltotal 57.3% 47 / 82 CC 3 SCAR 5.7
CC
3
Cov
61%
new
3.5
bot_start
2.0
on_connect
2.0
CRAP 1.8
« Tanker/RequestGenerator.pm ↑ Summary Tanker/Plugin/Log.pm »
1 package Tanker::RequestGenerator::IRC;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Tanker::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Tanker::RequestGenerator;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw(@ISA $me $running);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use POE::Component::IRC;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 @ISA = qw (Tanker::RequestGenerator);
13  
14 1 my $NAME = "tanker" . $$ % 1000;
15 1 my $NICK = $NAME;
16 1 my $CHANNEL = "#tanker";
17 1 my $SERVER = "london.rhizomatic.net";
18  
19  
20 # this isn't very good and needs to be more flexible but
21 # it's a start and shows that the pipeline works concurrently
22  
23 sub new
24 1 ▶{
Subroutine new: called CC=3 SCAR=12.6
Pod undocumented
25 1 my $proto = shift;
26 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
27 1 my $pipeline = shift;
28  
29 1 my $self = $class->SUPER::new($pipeline);
30  
31 1 ▶ POE::Component::IRC->new($NAME) or die "Oh noooo! $!";
Branch: 1 branch
BranchTrueFalseTotal
"POE::Component::IRC"->new($NAME) or die "Oh noooo! $!" 1 0 1
32  
33 1 POE::Session->new
34 ( _start => \&bot_start,
35 irc_376 => \&on_connect,
36 irc_public => \&on_message,
37 );
38  
39  
40  
41 0 $me = $self;
42  
43 0 return $self;
44  
45  
46 }
47  
48 sub bot_start
49 0 ▶{
Subroutine bot_start: not called CC=1 SCAR=6.9
Pod undocumented
50 0 print STDERR "Attempting to connect\n";
51  
52  
53 0 my $kernel = $_[KERNEL];
54 0 my $heap = $_[HEAP];
55 0 my $session = $_[SESSION];
56  
57 0 $kernel->refcount_increment( $session->ID(), "irc bot" );
58 0 $kernel->post( $NAME => register => "all" );
59  
60  
61 0 $kernel->post($NAME, 'connect',
62 { Nick => $NICK,
63 Server => $SERVER,
64 Port => 6667,
65 Username => $NICK,
66 Ircname => $NICK, } );
67 }
68  
69 sub on_connect
70 0 ▶{
Subroutine on_connect: not called CC=1 SCAR=6.9
Pod undocumented
71 0 print STDERR "Joining\n";
72 0 $_[KERNEL]->post( $NAME => join => $CHANNEL );
73 }
74  
75 sub on_message
76 0 ▶{
Subroutine on_message: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my ($kernel, $who, $where, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
78 0 my $nick = (split /!/, $who)[0];
79 0 my $channel = $where->[0];
80  
81 0 my $ts = scalar(localtime);
82 0 print STDERR " [$ts] <$nick:$channel> $msg\n";
83  
84 0 my $r = {
85 ts => $ts,
86 nick => $nick,
87 channel => $channel,
88 msg => $msg,
89 };
90
91 0 my $req = new Tanker::Request($r);
92 0 $me->{pipeline}->inject($req);
93  
94  
95 }
96  
97  
98  
99 sub run ($)
100 0 ▶{
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
101 0 my ($self) = @_;
102 0 $poe_kernel->run();
103  
104 }
105  
106 1 1;
107 __END__
« Tanker/RequestGenerator.pm ↑ Summary Tanker/Plugin/Log.pm »