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

filter: Statementstmt 98.3% 60 / 61 Branchbran 50.0% 9 / 18 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 92.8% 13 / 14 Podpod 100% 1 / 1 totaltotal 76.3% 87 / 114 CC 14 SCAR 17.2
CC
14
Cov
80%
spawn
13.0
_client_flushed
3.3
_get_datagram
3.1
CRAP 5.6
↑ Summary
1 # $Id: Chargen.pm,v 1.3 2005/01/27 13:48:24 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::Chargen;
11 3 $POE::Component::Server::Chargen::VERSION = '1.16';
12 #ABSTRACT: A POE component that implements an RFC 864 Chargen 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 => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶sub spawn {
Subroutine spawn: called CC=9 SCAR=25.6
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'} = 'Chargen-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  
34 2 my $self = bless { }, $package;
35  
36 2 $self->{CONFIG} = \%parms;
37 2 $self->{start_ascii} = 32;
38  
39 POE::Session->create(
40 object_states => [
41 $self => { _start => '_server_start',
42 _stop => '_server_stop',
43 shutdown => '_server_close' },
44 $self => [ qw(_accept_new_client _accept_failed _client_input _client_error _client_flushed _get_datagram) ],
45 ],
46 2 ▶ ( ref $parms{'options'} eq 'HASH' ? ( options => $parms{'options'} ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
ref $parms{'options'} eq 'HASH' ? : 0 2 2
47 );
48  
49 2 return $self;
50 }
51  
52 1 ▶sub _accept_new_client {
Subroutine _accept_new_client: called CC=1 SCAR=0.0
53 1 my ($kernel,$self,$socket,$peeraddr,$peerport,$wheel_id) = @_[KERNEL,OBJECT,ARG0 .. ARG3];
54 1 $peeraddr = inet_ntoa($peeraddr);
55  
56 1 my $wheel = POE::Wheel::ReadWrite->new (
57 Handle => $socket,
58 Filter => POE::Filter::Line->new(),
59 InputEvent => '_client_input',
60 ErrorEvent => '_client_error',
61 FlushedEvent => '_client_flushed',
62 );
63  
64 1 $self->{Clients}->{ $wheel->ID() } = { Wheel => $wheel, peeraddr => $peeraddr, peerport => $peerport, start_ascii => $self->{start_ascii} };
65 1 $wheel->put( _generate_line(\$self->{Clients}->{ $wheel->ID() }->{start_ascii}) );
66 1 undef;
67 }
68  
69 0 ▶sub _client_input {
Subroutine _client_input: not called CC=1 SCAR=6.9
70 0 undef;
71 }
72  
73 2 ▶sub _client_flushed {
Subroutine _client_flushed: called CC=3 SCAR=12.0
74 2 my ($kernel,$self,$wheel_id) = @_[KERNEL,OBJECT,ARG0];
75  
76 2 ▶ if ( defined $self->{Clients}->{ $wheel_id } and defined $self->{Clients}->{ $wheel_id }->{Wheel} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Clients"}{$wheel_id} and defined $self->{"Clients"}{$wheel_id}{"Wheel"}) 2 0 2
Condition33%1/3
defined $self->{"Clients"}{$wheel_id} and defined $self->{"Clients"}{$wheel_id}{"Wheel"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"Clients"}{$wheel_id} and defined $self->{"Clients"}{$wheel_id}{"Wheel"}
defined $self->{"Clients"}{$wheel_id} defined $self->{"Clients"}{$wheel_id}{"Wheel"}
Truth table33%1/3
A and B
A= defined $self->{"Clients"}{$wheel_id}B= defined $self->{"Clients"}{$wheel_id}{"Wheel"}
ABresult
0X0
100
111
77 2 $self->{Clients}->{ $wheel_id }->{Wheel}->put( _generate_line(\$self->{Clients}->{ $wheel_id }->{start_ascii}) );
78 }
79 2 undef;
80 }
81  
82 1 ▶sub _get_datagram {
Subroutine _get_datagram: called CC=3 SCAR=11.2
83 1 my ( $kernel, $self, $socket ) = @_[ KERNEL, OBJECT, ARG0 ];
84  
85 1 my $remote_address = recv( $socket, my $message = "", DATAGRAM_MAXLEN, 0 );
86 1 ▶ return unless defined $remote_address;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remote_address 0 1 1
87  
88 1 my $start_ascii = $self->{start_ascii};
89  
90 1 my $reply = _generate_line( \$start_ascii );
91  
92 1 ▶ send( $socket, $reply, 0, $remote_address ) == length($reply)
Branch: 1 branch
BranchTrueFalseTotal
send($socket, $reply, 0, $remote_address) == length $reply or warn "Trouble sending response: $!" 1 0 1
93 or warn "Trouble sending response: $!";
94  
95 1 undef;
96 }
97  
98 4 ▶sub _generate_line {
Subroutine _generate_line: called CC=2 SCAR=7.0
99 4 my $start_ascii = shift;
100 my $chargen_line = join(
101 '',
102 4 map { chr }
103 ($$start_ascii .. $$start_ascii + 71)
104 );
105 4 $chargen_line =~ tr[\x7F-\xDD][\x20-\x7E];
106 4 ▶ $$start_ascii = 32 if ++$$start_ascii > 126;
Branch: 1 branch
BranchTrueFalseTotal
if ++$$start_ascii > 126 0 4 4
107 4 return $chargen_line;
108 }
109  
110 3 qq[A Gen of chars];
111  
112 __END__
↑ Summary