File Coverage

blib/lib/Bitcoin/Crypto/Types.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 31 31 100.0


line stmt bran cond sub pod time code
1             package Bitcoin::Crypto::Types;
2             $Bitcoin::Crypto::Types::VERSION = '1.008';
3 11     11   72292 use v5.10;
  11         55  
4 11     11   67 use strict;
  11         26  
  11         253  
5 11     11   55 use warnings;
  11         25  
  11         372  
6 11     11   547 use Type::Library -base;
  11         38145  
  11         82  
7 11     11   2725 use Type::Coercion;
  11         4117  
  11         303  
8 11     11   2878 use Types::Common::Numeric qw(assert_PositiveInt);
  11         212751  
  11         76  
9 11     11   9302 use Types::Standard qw(Int InstanceOf Enum);
  11         28  
  11         70  
10              
11             # make sure Math::BigInt is loaded - this module loads it
12 11     11   30811 use Bitcoin::Crypto::Helpers;
  11         34  
  11         3055  
13              
14             __PACKAGE__->add_type(
15             name => "BIP44Purpose",
16             parent => Enum->of(44, 49, 84),
17             );
18              
19             __PACKAGE__->add_type(
20             name => "IntMaxBits",
21             parent => InstanceOf->of("Math::BigInt"),
22              
23             constraint_generator => sub {
24             my $bits = assert_PositiveInt(shift) - 1;
25             my $limit = Math::BigInt->new(2)->blsft($bits);
26             return sub {
27             return $_->bge(0) && $_->blt($limit);
28             };
29             },
30              
31             coercion_generator => sub {
32             return Type::Coercion->new(
33             type_coercion_map => [
34             Int, q{Math::BigInt->new($_)},
35             ],
36             );
37             },
38              
39             message => sub {
40             my $bits = shift;
41             return "Value does not fit in $bits bits";
42             },
43             );
44              
45             1;
46