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   238 use 5.008;
  11         38  
6 11     11   55 use Mouse;
  11         20  
  11         54  
7 11     11   3773 use Mouse::Util::TypeConstraints;
  11         41  
  11         77  
8 11     11   7640 use Term::ANSIColor;
  11         92341  
  11         834  
9 11     11   88 use Carp;
  11         21  
  11         910  
10 11     11   72 no warnings 'uninitialized';
  11         19  
  11         1358  
11              
12             our $VERSION = '0.02';
13              
14 65     65   23450 use overload q("") => sub { shift->plain },
15 1     1   494 '++' => sub { $_[0] = $_[0]->plain + 1 },
16 1     1   860 '--' => sub { $_[0] = $_[0]->plain - 1 },
17 11     11   4688 fallback => 1;
  11         3584  
  11         131  
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();