File Coverage

lib/DR/Tnt/Msgpack/Types/Bool.pm
Criterion Covered Total %
statement 32 35 91.4
branch 9 12 75.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 3 0.0
total 51 62 82.2


line stmt bran cond sub pod time code
1 11     11   74 use utf8;
  11         22  
  11         66  
2 11     11   360 use strict;
  11         23  
  11         258  
3 11     11   57 use warnings;
  11         22  
  11         451  
4              
5             package DR::Tnt::Msgpack::Types::Bool;
6 11     11   77 use Carp;
  11         51  
  11         830  
7             $Carp::Internal{ (__PACKAGE__) }++;
8 11     11   79 use Scalar::Util ();
  11         23  
  11         293  
9 11     11   62 use feature 'state';
  11         25  
  11         4467  
10              
11             sub new {
12 22     22 0 55 my ($class, $value) = @_;
13              
14 22 100       57 $value = $value ? 1 : 0;
15 22   33     189 bless \$value => ref($class) || $class;
16             }
17              
18             sub TO_MSGPACK {
19 4     4 0 8 my ($self) = @_;
20 4 100       28 return pack 'C', 0xC3 if $$self;
21 2         19 return pack 'C', 0xC2;
22             }
23              
24             sub TO_JSON {
25 4     4 0 34 my ($self) = @_;
26              
27 4         6 state ($true, $false);
28              
29 4 100       12 unless (defined $true) {
30 1 50       53 if (eval "require JSON::XS; 1") {
    0          
31 1         6 $true = JSON::XS::true();
32 1         7 $false = JSON::XS::false();
33             } elsif (eval "require JSON; 1") {
34 0         0 $true = JSON::true();
35 0         0 $false = JSON::false();
36             } else {
37 0         0 croak "JSON or JSON::XS must be installed";
38             }
39             }
40              
41 4 100       26 return $true if $$self;
42 2         12 return $false;
43             }
44              
45             =head1 NAME
46              
47             DR::Tnt::Msgpack::Types::Bool - container for bool.
48              
49             =head1 SYNOPSIS
50              
51             use DR::Tnt::Msgpack::Types::Bool;
52              
53             my $o = DR::Tnt::Msgpack::Types::Bool->new(1);
54             my $blob = msgpack($o);
55              
56             =head1 DESCRIPTION
57              
58             See L.
59              
60             =cut
61              
62             1;