blib/lib/Games/TF2/Demo/StateReader.pm

filter: Statementstmt 44.3% 47 / 106 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 52.3% 11 / 21 Podpod 100% 3 / 3 totaltotal 38.6% 61 / 158 CC 11 SCAR 19.9
CC
11
Cov
36%
string_table
20.0
_check_index
20.0
entity
6.0
CRAP 7.3
« blib/lib/Games/TF2/Demo/StringTable.pm ↑ Summary blib/lib/Games/TF2/Demo/Iterator.pm »
1 package Games::TF2::Demo::StateReader;
2  
3 11 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = '0.01';
9  
10 11 ▶use Object::Pad 0.800;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 role Games::TF2::Demo::StateReader {
13 11 ▶ use Games::TF2::Demo::Entity;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶ use Games::TF2::Demo::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶ use Games::TF2::Demo::GameState;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶ use Games::TF2::Demo::Player;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶ use Games::TF2::Demo::ServerInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶ use Games::TF2::Demo::StringTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # The XS handle whose state the methods read: a Games::TF2::Demo::_Parser
21 # or a Games::TF2::Server::_Connection.
22 11 method _state_handle;
23  
24 # The start of this binding's own error messages, such as
25 # 'Games::TF2::Demo'.
26 11 method _error_prefix;
27  
28 0 ▶ method entity ($index) {
Subroutine entity: not called CC=2 SCAR=17.9
29 0 $self->_check_index( entity => $index );
30 0 my $fields = $self->_state_handle->entity($index);
31 0 ▶ return undef unless $fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $fields 0 0 0
32 0 return Games::TF2::Demo::Entity->new( $fields->%* );
33 11 }
34  
35 0 ▶ method game_state () {
Subroutine game_state: not called CC=1 SCAR=6.9
Pod documented
36 0 return Games::TF2::Demo::GameState->from_fields( $self->_state_handle->game_state );
37 11 }
38  
39 0 ▶ method player_by_entity ($index) {
Subroutine player_by_entity: not called CC=2 SCAR=17.9
40 0 $self->_check_index( player_by_entity => $index );
41 0 my $fields = $self->_state_handle->player_by_entity($index);
42 0 ▶ return $fields ? Games::TF2::Demo::Player->new( $fields->%* ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fields ? : 0 0 0
43 11 }
44  
45 0 ▶ method player_by_user_id ($user_id) {
Subroutine player_by_user_id: not called CC=2 SCAR=17.9
Pod documented
46 0 $self->_check_index( player_by_user_id => $user_id );
47 0 my $fields = $self->_state_handle->player_by_user_id($user_id);
48 0 ▶ return $fields ? Games::TF2::Demo::Player->new( $fields->%* ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fields ? : 0 0 0
49 11 }
50  
51 0 ▶ method players () {
Subroutine players: not called CC=1 SCAR=6.9
52 0 return map { Games::TF2::Demo::Player->new( $_->%* ) } $self->_state_handle->players;
53 11 }
54  
55 0 ▶ method string_tables () {
Subroutine string_tables: not called CC=1 SCAR=6.9
Pod documented
56 0 return $self->_state_handle->string_table_names;
57 11 }
58  
59 0 ▶ method string_table ($name) {
Subroutine string_table: not called CC=4 SCAR=30.0
60 0 ▶ $self->_state_argument_error('string_table needs a table name') unless defined $name && !ref $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and not ref $name 0 0 0
Condition0%0/3
defined $name and not ref $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and not ref $name
defined $name not ref $name
Truth table0%0/3
A and not(B)
A= defined $nameB= not ref $name
ABresult
0X0
100
111
61 0 my $fields = $self->_state_handle->string_table($name);
62 0 ▶ return $fields ? Games::TF2::Demo::StringTable->new( $fields->%* ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fields ? : 0 0 0
63 11 }
64  
65 0 ▶ method server_info () {
Subroutine server_info: not called CC=2 SCAR=17.9
66 0 my $fields = $self->_state_handle->server_info;
67 0 ▶ return $fields ? Games::TF2::Demo::ServerInfo->new( $fields->%* ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fields ? : 0 0 0
68 11 }
69  
70 0 ▶ method _state_argument_error ($message) {
Subroutine _state_argument_error: not called CC=1 SCAR=6.9
71 0 Games::TF2::Demo::Error::Argument->throw( message => $self->_error_prefix . ": $message" );
72 11 }
73  
74 0 ▶ method _check_index ( $method, $number ) {
Subroutine _check_index: not called CC=4 SCAR=30.0
75 0 ▶ return if defined $number && !ref $number && $number =~ /\A[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $number and not ref $number and $number =~ /\A[0-9]+\z/u 0 0 0
Condition0%0/6
defined $number and not ref $number and $number =~ /\A[0-9]+\z/u
!ll&&!rl&&r
000
defined $number and not ref $number
!ll&&!rl&&r
000
MC/DC0%0/3
defined $number and not ref $number and $number =~ /\A[0-9]+\z/u
defined $number not ref $number $number =~ /\A[0-9]+\z/u
Truth table0%0/4
A and not(B) and C
A= defined $numberB= not ref $numberC= $number =~ /\A[0-9]+\z/u
ABCresult
0XX0
10X0
1100
1111
76 0 $self->_state_argument_error("$method needs a non-negative integer");
77 11 }
78 }
79  
80 11 1;
81  
82 __END__
« blib/lib/Games/TF2/Demo/StringTable.pm ↑ Summary blib/lib/Games/TF2/Demo/Iterator.pm »