blib/lib/POE/Component/Server/Qotd.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 50.0% 8 / 16 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 92.3% 12 / 13 Podpod 100% 1 / 1 totaltotal 74.7% 77 / 103 CC 13 SCAR 22.1
CC
13
Cov
79%
spawn
18.7
_get_datagram
3.1
_client_input
2.0
CRAP 9.1
↑ Summary
1 # $Id: Qotd.pm,v 1.1.1.1 2005/01/27 14:15:42 chris Exp $
2 #
3 # POE::Component::Server::Echo, by Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
4 #
5 # This module may be used, modified, and distributed under the same
6 # terms as Perl itself. Please see the license that came with your Perl
7 # distribution for details.
8 #
9  
10 package POE::Component::Server::Qotd;
11 3 $POE::Component::Server::Qotd::VERSION = '1.16';
12 #ABSTRACT: A POE component that implements an RFC 865 QotD server.
13  
14 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use base qw(POE::Component::Server::Echo);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use constant DATAGRAM_MAXLEN => 1024;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use constant DEFAULT_PORT => 17;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶sub spawn {
Subroutine spawn: called CC=11 SCAR=29.3
Pod documented
25 2 my $package = shift;
26 2 ▶ croak "$package requires an even number of parameters" if @_ & 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 2 2
27  
28 2 my %parms = @_;
29  
30 2 ▶ $parms{'Alias'} = 'Qotd-Server' unless defined $parms{'Alias'} and $parms{'Alias'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"Alias"} and $parms{"Alias"} 0 2 2
Condition33%1/3
defined $parms{"Alias"} and $parms{"Alias"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $parms{"Alias"} and $parms{"Alias"}
defined $parms{"Alias"} $parms{"Alias"}
Truth table33%1/3
A and B
A= defined $parms{"Alias"}B= $parms{"Alias"}
ABresult
0X0
100
111
31 2 ▶ $parms{'tcp'} = 1 unless defined $parms{'tcp'} and $parms{'tcp'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"tcp"} and $parms{"tcp"} == 0 2 0 2
Condition33%1/3
defined $parms{"tcp"} and $parms{"tcp"} == 0
!ll&&!rl&&r
200
MC/DC0%0/2
defined $parms{"tcp"} and $parms{"tcp"} == 0
defined $parms{"tcp"} $parms{"tcp"} == 0
Truth table33%1/3
A and B
A= defined $parms{"tcp"}B= $parms{"tcp"} == 0
ABresult
0X0
100
111
32 2 ▶ $parms{'udp'} = 1 unless defined $parms{'udp'} and $parms{'udp'} == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"udp"} and $parms{"udp"} == 0 2 0 2
Condition33%1/3
defined $parms{"udp"} and $parms{"udp"} == 0
!ll&&!rl&&r
200
MC/DC0%0/2
defined $parms{"udp"} and $parms{"udp"} == 0
defined $parms{"udp"} $parms{"udp"} == 0
Truth table33%1/3
A and B
A= defined $parms{"udp"}B= $parms{"udp"} == 0
ABresult
0X0
100
111
33 $parms{'Quote'} = 'Parts that positively cannot be assembled in improper order will be.'
34 2 ▶ unless defined $parms{'Quote'} and length $parms{'Quote'} <= 512;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"Quote"} and length $parms{"Quote"} <= 512 2 0 2
Condition33%1/3
defined $parms{"Quote"} and length $parms{"Quote"} <= 512
!ll&&!rl&&r
200
MC/DC0%0/2
defined $parms{"Quote"} and length $parms{"Quote"} <= 512
defined $parms{"Quote"} length $parms{"Quote"} <= 512
Truth table33%1/3
A and B
A= defined $parms{"Quote"}B= length $parms{"Quote"} <= 512
ABresult
0X0
100
111
35  
36 2 my $self = bless { }, $package;
37  
38 2 $self->{CONFIG} = \%parms;
39  
40 POE::Session->create(
41 object_states => [
42 $self => { _start => '_server_start',
43 _stop => '_server_stop',
44 shutdown => '_server_close' },
45 $self => [ qw(_accept_new_client _accept_failed _client_input _client_error _client_flushed _get_datagram) ],
46 ],
47 2 ▶ ( ref $parms{'options'} eq 'HASH' ? ( options => $parms{'options'} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
ref $parms{'options'} eq 'HASH' ? : 0 2 2
48 );
49  
50 2 return $self;
51 }
52  
53 1 ▶sub _accept_new_client {
Subroutine _accept_new_client: called CC=1 SCAR=0.0
54 1 my ($kernel,$self,$socket,$peeraddr,$peerport,$wheel_id) = @_[KERNEL,OBJECT,ARG0 .. ARG3];
55 1 $peeraddr = inet_ntoa($peeraddr);
56  
57 1 my $wheel = POE::Wheel::ReadWrite->new (
58 Handle => $socket,
59 Filter => POE::Filter::Line->new(),
60 InputEvent => '_client_input',
61 ErrorEvent => '_client_error',
62 FlushedEvent => '_client_flushed',
63 );
64  
65 1 $self->{Clients}->{ $wheel->ID() } = { Wheel => $wheel, peeraddr => $peeraddr, peerport => $peerport };
66 1 $wheel->put( $self->{CONFIG}->{Quote} );
67 1 undef;
68 }
69  
70 0 ▶sub _client_input {
Subroutine _client_input: not called CC=1 SCAR=6.9
71 0 undef;
72 }
73  
74 1 ▶sub _client_flushed {
Subroutine _client_flushed: called CC=1 SCAR=0.0
75 1 my ($kernel,$self,$wheel_id) = @_[KERNEL,OBJECT,ARG0];
76 1 delete $self->{Clients}->{ $wheel_id }->{Wheel};
77 1 delete $self->{Clients}->{ $wheel_id };
78 1 undef;
79 }
80  
81 1 ▶sub _get_datagram {
Subroutine _get_datagram: called CC=3 SCAR=11.3
82 1 my ( $kernel, $self, $socket ) = @_[ KERNEL, OBJECT, ARG0 ];
83  
84 1 my $remote_address = recv( $socket, my $message = "", DATAGRAM_MAXLEN, 0 );
85 1 ▶ return unless defined $remote_address;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remote_address 0 1 1
86  
87 send( $socket, $self->{CONFIG}->{Quote}, 0, $remote_address ) == length( $self->{CONFIG}->{Quote} )
88 1 ▶ or warn "Trouble sending response: $!";
Branch: 1 branch
BranchTrueFalseTotal
send($socket, $self->{"CONFIG"}{"Quote"}, 0, $remote_address) == length $self->{"CONFIG"}{"Quote"} or warn "Trouble sending response: $!" 1 0 1
89 1 undef;
90 }
91  
92 3 qq[What is the frequency, Kenneth?];
93  
94 __END__
↑ Summary