| 1 | # | ||||||||||
| 2 | # Copyright (c) 2019-2020 Christian Jaeger, copying@christianjaeger.ch | ||||||||||
| 3 | # | ||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||
| 7 | # bundled with this file. | ||||||||||
| 8 | # | ||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | FP::BigInt | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use FP::Equal 'is_equal'; use FP::Show; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use FP::BigInt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | is_equal ref(bigint(13)), 'Math::BigInt'; | ||||||||||
| 20 | is_equal "".(bigint(10)**20), '100000000000000000000'; | ||||||||||
| 21 | is_equal bigint(13) / bigint(10), bigint('1'); | ||||||||||
| 22 | |||||||||||
| 23 | is show(bigint(7)), "bigint('7')"; | ||||||||||
| 24 | |||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||
| 26 | |||||||||||
| 27 | Loads L<Math::BigInt>, monkey patches C<FP_Show_show> and | ||||||||||
| 28 | C<FP_Equal_equal> methods into it, and exports the C<bigint> | ||||||||||
| 29 | constructor function. | ||||||||||
| 30 | |||||||||||
| 31 | =head1 SEE ALSO | ||||||||||
| 32 | |||||||||||
| 33 | L<Math::BigInt> | ||||||||||
| 34 | |||||||||||
| 35 | L<FP::Abstract::Show>, L<FP::Abstract::Equal> -- implemented protocols | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | package FP::BigInt; | ||||||||||
| 40 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 3 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 3 | ▶ | use Exporter "import"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 3 | our @EXPORT = qw(bigint); | |||||||||
| 46 | 3 | our @EXPORT_OK = qw(); | |||||||||
| 47 | 3 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||
| 48 | |||||||||||
| 49 | 3 | ▶ | use Math::BigInt; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 3 | ▶ | use FP::Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | |||||||||||
| 52 | #use FP::Interfaces; | ||||||||||
| 53 | |||||||||||
| 54 | 242 | ▶ | sub bigint { | ||||||||
|
Subroutine
bigint: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 55 | 242 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 242 | Math::BigInt->new($_[0]) | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | package # Monkey patching; but using long ucfirst (TODO: go all | ||||||||||
| 60 | # uppercase(?)) method names that should never conflict with | ||||||||||
| 61 | # anybody else's. Use case doesn't really allow for | ||||||||||
| 62 | # subclassing. Might look into implementing some sort of | ||||||||||
| 63 | # lexical extensions of classes at some point. | ||||||||||
| 64 | 3 | Math::BigInt { | |||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub FP_Show_show { | ||||||||
|
Subroutine
FP_Show_show: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 67 | 1 | my $s = shift; | |||||||||
| 68 | 1 | "bigint('$s')" | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 8 | ▶ | sub FP_Equal_equal { | ||||||||
|
Subroutine
FP_Equal_equal: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 72 | 8 | my ($a, $b) = @_; | |||||||||
| 73 | 8 | $a == $b | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # commented out to not modify Math::BigInt's @ISA, although it | ||||||||||
| 77 | # would be good to have for consistency. | ||||||||||
| 78 | #FP::Interfaces::implemented qw(FP::Abstract::Show | ||||||||||
| 79 | # FP::Abstract::Equal); | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 3 | 1 | |||||||||