| 1 | package CXC::Number::Types; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Type::Tiny types for CXC::Number | ||||||||||
| 4 | |||||||||||
| 5 | 26 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 26 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 26 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 26 | our $VERSION = '0.12'; | |||||||||
| 10 | |||||||||||
| 11 | 26 | ▶ | use Math::BigInt upgrade => 'Math::BigFloat'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 26 | ▶ | use Math::BigFloat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 26 | ▶ | use Type::Utils; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 26 | ▶ | use Types::Standard qw[ Num Int InstanceOf ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 26 | ▶ | use Types::Common::Numeric qw[ PositiveNum PositiveOrZeroNum PositiveInt ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 26 | use Type::Library -base, -declare => qw( | |||||||||
| 18 | BigInt | ||||||||||
| 19 | BigNum | ||||||||||
| 20 | BigPositiveInt | ||||||||||
| 21 | BigPositiveNum | ||||||||||
| 22 | BigPositiveOrZeroNum | ||||||||||
| 23 | 26 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | class_type BigNum, | ||||||||||
| 30 | { | ||||||||||
| 31 | class => 'Math::BigFloat', | ||||||||||
| 32 | 2 | ▶ | message { 'Not a number or a Math::BigFloat' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 26 | }; | |||||||||
| 34 | |||||||||||
| 35 | coerce BigNum, from Num, via { | ||||||||||
| 36 | 637 | ▶ | my $bignum = Math::BigFloat->new( $_ ); | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||
| 37 | 637 | ▶ | $bignum->is_nan ? $_ : $bignum; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 26 | }; | |||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | declare BigPositiveNum, as BigNum, | ||||||||||
| 45 | 35 | ▶ | where { $_ > 0 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 5 | ▶ | message { BigNum->validate( $_ ) or "$_ is not greater than zero" }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 47 | 26 | coercion => 1; | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | coerce BigPositiveNum, from PositiveNum, via { Math::BigFloat->new( $_ ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | 21 | ▶ | declare BigPositiveOrZeroNum, as BigNum, where { $_ >= 0 }, message { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 0 | ▶ | BigNum->validate( $_ ) | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 57 | or "$_ is not greater than or equal to zero" | ||||||||||
| 58 | 26 | }, coercion => 1; | |||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | coerce BigPositiveOrZeroNum, from PositiveOrZeroNum, via { Math::BigFloat->new( $_ ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | declare BigInt, as( InstanceOf ['Math::BigInt'] | InstanceOf ['Math::BigFloat'] ), | ||||||||||
| 71 | 37 | ▶ | where { $_->is_int() }, message { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 72 | 3 | ▶ | 'Not an integer or a Math::BigInt' | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 26 | }; | |||||||||
| 74 | |||||||||||
| 75 | coerce BigInt, from Int, via { | ||||||||||
| 76 | 29 | ▶ | Math::BigInt->new( $_ ); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 26 | }; | |||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | declare BigPositiveInt, as BigInt, | ||||||||||
| 86 | 28 | ▶ | where { $_ > 0 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 87 | 6 | ▶ | message { BigInt->validate( $_ ) or "$_ is not greater than zero" }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 88 | 26 | coercion => 1; | |||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | coerce BigPositiveInt, from PositiveInt, via { Math::BigFloat->new( $_ ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | # | ||||||||||
| 94 | # This file is part of CXC-Number | ||||||||||
| 95 | # | ||||||||||
| 96 | # This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 97 | # | ||||||||||
| 98 | # This is free software, licensed under: | ||||||||||
| 99 | # | ||||||||||
| 100 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 101 | # | ||||||||||
| 102 | |||||||||||
| 103 | 26 | 1; | |||||||||
| 104 | |||||||||||
| 105 | __END__ | ||||||||||
| 106 | |||||||||||
| 107 | =pod | ||||||||||
| 108 | |||||||||||
| 109 | =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory BigInt BigNum | ||||||||||
| 110 | BigPositiveInt BigPositiveNum BigPositiveOrZeroNum BigPositiveZeroNum | ||||||||||
| 111 | |||||||||||
| 112 | =head1 NAME | ||||||||||
| 113 | |||||||||||
| 114 | CXC::Number::Types - Type::Tiny types for CXC::Number | ||||||||||
| 115 | |||||||||||
| 116 | =head1 VERSION | ||||||||||
| 117 | |||||||||||
| 118 | version 0.12 | ||||||||||
| 119 | |||||||||||
| 120 | =head1 TYPES | ||||||||||
| 121 | |||||||||||
| 122 | =head2 BigNum | ||||||||||
| 123 | |||||||||||
| 124 | =head2 BigPositiveNum | ||||||||||
| 125 | |||||||||||
| 126 | =head2 BigPositiveZeroNum | ||||||||||
| 127 | |||||||||||
| 128 | =head2 BigPositiveOrZeroNum | ||||||||||
| 129 | |||||||||||
| 130 | =head2 BigInt | ||||||||||
| 131 | |||||||||||
| 132 | =head2 BigPositiveInt | ||||||||||
| 133 | |||||||||||
| 134 | A BigInt > 0. | ||||||||||
| 135 | |||||||||||
| 136 | =head1 INTERNALS | ||||||||||
| 137 | |||||||||||
| 138 | =head1 SUPPORT | ||||||||||
| 139 | |||||||||||
| 140 | =head2 Bugs | ||||||||||
| 141 | |||||||||||
| 142 | Please report any bugs or feature requests to bug-cxc-number@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number> | ||||||||||
| 143 | |||||||||||
| 144 | =head2 Source | ||||||||||
| 145 | |||||||||||
| 146 | Source is available at | ||||||||||
| 147 | |||||||||||
| 148 | https://gitlab.com/djerius/cxc-number | ||||||||||
| 149 | |||||||||||
| 150 | and may be cloned from | ||||||||||
| 151 | |||||||||||
| 152 | https://gitlab.com/djerius/cxc-number.git | ||||||||||
| 153 | |||||||||||
| 154 | =head1 SEE ALSO | ||||||||||
| 155 | |||||||||||
| 156 | Please see those modules/websites for more information related to this module. | ||||||||||
| 157 | |||||||||||
| 158 | =over 4 | ||||||||||
| 159 | |||||||||||
| 160 | =item * | ||||||||||
| 161 | |||||||||||
| 162 | L<CXC::Number|CXC::Number> | ||||||||||
| 163 | |||||||||||
| 164 | =back | ||||||||||
| 165 | |||||||||||
| 166 | =head1 AUTHOR | ||||||||||
| 167 | |||||||||||
| 168 | Diab Jerius <djerius@cpan.org> | ||||||||||
| 169 | |||||||||||
| 170 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 171 | |||||||||||
| 172 | This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 173 | |||||||||||
| 174 | This is free software, licensed under: | ||||||||||
| 175 | |||||||||||
| 176 | The GNU General Public License, Version 3, June 2007 | ||||||||||
| 177 | |||||||||||
| 178 | =cut | ||||||||||