Games/AssaultCube/MasterserverQuery.pm

filter: Statementstmt 65.3% 32 / 49 Branchbran 12.5% 1 / 8 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 50.0% 1 / 2 totaltotal 54.3% 44 / 81 CC 7 SCAR 22.7
CC
7
Cov
54%
run
30.0
BUILDARGS
3.8
__ANON__
2.0
CRAP 9.6
« POE/Component/AssaultCube/ServerQuery/Server.pm ↑ Summary Games/AssaultCube/Log/Line/Killed.pm »
1 # Declare our package
2 package Games::AssaultCube::MasterserverQuery;
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::MasterserverQuery::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # TODO make validation so we accept a *real* URI
18 2 has 'server' => (
19 isa => 'Str',
20 is => 'ro',
21 default => 'http://masterserver.cubers.net/cgi-bin/AssaultCube.pl/retrieve.do?item=list',
22 );
23  
24 2 has 'timeout' => (
25 isa => 'Int',
26 is => 'rw',
27 default => 30,
28 );
29  
30 has 'useragent' => (
31 isa => 'LWP::UserAgent',
32 is => 'rw',
33 1 ▶ default => sub { return LWP::UserAgent->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 2 );
35  
36 has 'request' => (
37 isa => 'HTTP::Request',
38 is => 'rw',
39 lazy => 1,
40 0 ▶ default => sub { return HTTP::Request->new( GET => $_[0]->server ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 2 );
42  
43 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=3 SCAR=13.3
Pod documented
44 1 my $class = shift;
45  
46 1 ▶ if ( @_ == 1 && ! ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 0 1 1
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
47 # set the server as the first argument
48 0 return { server => $_[0] };
49 } else {
50 # normal hash/hashref way
51 1 return $class->SUPER::BUILDARGS(@_);
52 }
53 }
54  
55 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod undocumented
56 0 my $self = shift;
57  
58 # set the alarm, and wait for the response
59 0 my( $res );
60 0 eval {
61 # perldoc -f alarm says I need to put \n in the die... weird!
62 0 ▶ local $SIG{ALRM} = sub { die "alarm\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 alarm $self->timeout;
64 0 $res = $self->useragent->request( $self->request );
65 0 alarm 0;
66 };
67 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
68 0 ▶ if ( $@ =~ /^alarm/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /^alarm/) { } 0 0 0
69 0 die "Unable to query server: Timed out";
70 } else {
71 0 die "Unable to query server: $@";
72 }
73 } else {
74 0 ▶ if ( defined $res and $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res and $res->is_success) { } 0 0 0
Condition0%0/3
defined $res and $res->is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $res and $res->is_success
defined $res $res->is_success
Truth table0%0/3
A and B
A= defined $resB= $res->is_success
ABresult
0X0
100
111
75 0 return Games::AssaultCube::MasterserverQuery::Response->new( $self, $res );
76 } else {
77 0 return;
78 }
79 }
80 }
81  
82 # from Moose::Manual::BestPractices
83 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 __PACKAGE__->meta->make_immutable;
85  
86 2 1;
87 __END__
« POE/Component/AssaultCube/ServerQuery/Server.pm ↑ Summary Games/AssaultCube/Log/Line/Killed.pm »