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   56 use utf8;
  11         15  
  11         49  
2 11     11   265 use strict;
  11         15  
  11         159  
3 11     11   38 use warnings;
  11         15  
  11         335  
4              
5             package DR::Tnt::Msgpack::Types::Bool;
6 11     11   42 use Carp;
  11         20  
  11         649  
7             $Carp::Internal{ (__PACKAGE__) }++;
8 11     11   58 use Scalar::Util ();
  11         16  
  11         216  
9 11     11   40 use feature 'state';
  11         21  
  11         3220  
10              
11             sub new {
12 22     22 0 35 my ($class, $value) = @_;
13              
14 22 100       40 $value = $value ? 1 : 0;
15 22   33     133 bless \$value => ref($class) || $class;
16             }
17              
18             sub TO_MSGPACK {
19 4     4 0 6 my ($self) = @_;
20 4 100       18 return pack 'C', 0xC3 if $$self;
21 2         14 return pack 'C', 0xC2;
22             }
23              
24             sub TO_JSON {
25 4     4 0 28 my ($self) = @_;
26              
27 4         4 state ($true, $false);
28              
29 4 100       8 unless (defined $true) {
30 1 50       40 if (eval "require JSON::XS; 1") {
    0          
31 1         5 $true = JSON::XS::true();
32 1         5 $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       18 return $true if $$self;
42 2         8 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;