Games/AssaultCube/ServerQuery/Response.pm

filter: Statementstmt 75.7% 50 / 66 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 1 / 1 totaltotal 70.2% 66 / 94 CC 8 SCAR 16.2
CC
8
Cov
70%
__ANON__
12.0
BUILDARGS
9.3
__ANON__
2.0
CRAP 5.1
« Games/AssaultCube/Log/Line/Base/MasterMode.pm ↑ Summary Games/AssaultCube/Log/Line/MasterserverReply.pm »
1 # Declare our package
2 package Games::AssaultCube::ServerQuery::Response;
3  
4 # import the Moose stuff
5 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Initialize our version
9 2 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 $VERSION = '0.04';
11  
12 # get some utility stuff
13 2 ▶use Games::AssaultCube::Utils qw( parse_pingresponse default_port getpongflag stripcolors );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # This is a bit "weird" but very convenient, ha!
16 2 with 'Games::AssaultCube::Log::Line::Base::GameMode';
17  
18 # TODO improve validation for everything here, ha!
19  
20 2 has 'server' => (
21 isa => 'Str',
22 is => 'ro',
23 required => 1,
24 );
25  
26 2 has 'port' => (
27 isa => 'Int',
28 is => 'ro',
29 required => 1,
30 );
31  
32 2 has 'pingtime' => (
33 isa => 'Int',
34 is => 'ro',
35 required => 1,
36 );
37  
38 2 has 'query' => (
39 isa => 'Int',
40 is => 'ro',
41 required => 1,
42 );
43  
44 2 has 'protocol' => (
45 isa => 'Int',
46 is => 'ro',
47 required => 1,
48 );
49  
50 2 has 'players' => (
51 isa => 'Int',
52 is => 'ro',
53 required => 1,
54 );
55  
56 2 has 'minutes_left' => (
57 isa => 'Int',
58 is => 'ro',
59 required => 1,
60 );
61  
62 2 has 'map' => (
63 isa => 'Str',
64 is => 'ro',
65 required => 1,
66 );
67  
68 2 has 'desc' => (
69 isa => 'Str',
70 is => 'ro',
71 required => 1,
72 );
73  
74 has 'desc_nocolor' => (
75 isa => 'Str',
76 is => 'ro',
77 lazy => 1,
78 5 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 5 my $self = shift;
80 5 return stripcolors( $self->desc );
81 },
82 2 );
83  
84 2 has 'max_players' => (
85 isa => 'Int',
86 is => 'ro',
87 required => 1,
88 );
89  
90 2 has 'pong' => (
91 isa => 'Int',
92 is => 'ro',
93 default => 0,
94 );
95  
96 has 'pong_name' => (
97 isa => 'Str',
98 is => 'ro',
99 lazy => 1,
100 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 my $self = shift;
102 0 return getpongflag( $self->pong );
103 },
104 2 );
105  
106 has 'player_list' => (
107 isa => 'ArrayRef[Str]',
108 is => 'ro',
109 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 2 );
111  
112 has 'is_full' => (
113 isa => 'Bool',
114 is => 'ro',
115 lazy => 1,
116 5 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
117 5 my $self = shift;
118 5 ▶ if ( $self->players == $self->max_players ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->players == $self->max_players) { } 1 4 5
119 1 return 1;
120 } else {
121 4 return 0;
122 }
123 },
124 2 );
125  
126 2 has 'datagram' => (
127 isa => 'Str',
128 is => 'ro',
129 required => 1,
130 );
131  
132 has 'tohash' => (
133 isa => 'HashRef',
134 is => 'ro',
135 lazy => 1,
136 0 ▶ default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
137 0 my $self = shift;
138 0 my $data = {};
139  
140 0 foreach my $attr ( qw( timestamp gamemode server port pingtime protocol players minutes_left map desc max_players ) ) {
141 0 $data->{ $attr } = $self->$attr();
142 }
143  
144 # extra data
145 0 ▶ if ( scalar @{ $self->player_list } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->player_list;}) { } 0 0 0
146 0 $data->{player_list} = [ @{ $self->player_list } ];
147 } else {
148 0 $data->{player_list} = [];
149 }
150  
151 0 return $data;
152 },
153 2 );
154  
155 has 'timestamp' => (
156 isa => 'Int',
157 is => 'ro',
158 5 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
159 5 scalar time();
160 },
161 2 );
162  
163 6 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=5 SCAR=22.3
Pod documented
164 6 my $class = shift;
165  
166 # Normally, we would be created by Games::AssaultCube::ServerQuery and contain 2 args
167 6 ▶ if ( @_ == 2 && ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2 and ref $_[0]) { } 6 0 6
Condition33%1/3
@_ == 2 and ref $_[0]
!ll&&!rl&&r
006
MC/DC0%0/2
@_ == 2 and ref $_[0]
@_ == 2 ref $_[0]
Truth table33%1/3
A and B
A= @_ == 2B= ref $_[0]
ABresult
0X0
100
111
168 6 ▶ if ( ref( $_[0] ) eq 'Games::AssaultCube::ServerQuery' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'Games::AssaultCube::ServerQuery') { } 6 0 6
elsif (ref $_[0] eq 'POE::Component::AssaultCube::ServerQuery') { } 0 0 0
169 # call the parse method
170 return {
171 server => $_[0]->server,
172 port => $_[0]->port,
173 datagram => $_[1],
174 6 %{ parse_pingresponse( $_[1] ) },
175 };
176 } elsif ( ref( $_[0] ) eq 'POE::Component::AssaultCube::ServerQuery' ) {
177 # parse it a bit differently
178 return {
179 server => $_[1]->{addr},
180 port => $_[1]->{port},
181 datagram => $_[1]->{payload}->[0],
182 0 %{ parse_pingresponse( $_[1]->{payload}->[0] ) },
183 };
184 } else {
185 0 die "unknown arguments";
186 }
187 } else {
188 0 return $class->SUPER::BUILDARGS(@_);
189 }
190 }
191  
192 # from Moose::Manual::BestPractices
193 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 2 __PACKAGE__->meta->make_immutable;
195  
196 2 1;
197 __END__
« Games/AssaultCube/Log/Line/Base/MasterMode.pm ↑ Summary Games/AssaultCube/Log/Line/MasterserverReply.pm »