File Coverage

blib/lib/Net/RCON/Minecraft/Response.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 33 33 100.0


line stmt bran cond sub pod time code
1             package Net::RCON::Minecraft::Response;
2              
3             # Minecraft command response
4              
5 11     11   211 use 5.010;
  11         41  
6 11     11   107 use Mouse;
  11         26  
  11         59  
7 11     11   4075 use Mouse::Util::TypeConstraints;
  11         34  
  11         65  
8 11     11   8391 use Term::ANSIColor;
  11         99454  
  11         779  
9 11     11   79 use Carp;
  11         22  
  11         647  
10 11     11   72 no warnings 'uninitialized';
  11         23  
  11         1335  
11              
12             our $VERSION = '0.03';
13              
14 65     65   28384 use overload q("") => sub { shift->plain },
15 1     1   707 '++' => sub { $_[0] = $_[0]->plain + 1 },
16 1     1   1189 '--' => sub { $_[0] = $_[0]->plain - 1 },
17 11     11   4904 fallback => 1;
  11         3743  
  11         187  
18              
19             # Minecraft -> ANSI color map
20             my %COLOR = map { $_->[1] => color($_->[0]) } (
21             [black => '0'], [blue => '1'], [green => '2'],
22             [cyan => '3'], [red => '4'], [magenta => '5'],
23             [yellow => '6'], [white => '7'], [bright_black => '8'],
24             [bright_blue => '9'], [bright_green => 'a'], [bright_cyan => 'b'],
25             [bright_red => 'c'], [bright_magenta => 'd'], [yellow => 'e'],
26             [bright_white => 'f'],
27             [bold => 'l'], [concealed => 'm'], [underline => 'n'],
28             [reverse => 'o'], [reset => 'r'],
29             );
30              
31             has id => ( is => 'ro', isa => 'Int' );
32              
33             has raw => ( is => 'ro', isa => 'Str' );
34              
35             has plain => ( is => 'ro', isa => 'Str', lazy => 1, default => sub {
36             my $raw = $_[0]->raw;
37             $raw =~ s/\x{00A7}.//g;
38             $raw;
39             });
40              
41             has ansi => ( is => 'ro', isa => 'Str', lazy => 1, default => sub {
42             local $_ = $_[0]->raw;
43             s/\x{00A7}(.)/$COLOR{$1}/g;
44             $_ . $COLOR{r};
45             });
46              
47             __PACKAGE__->meta->make_immutable();