| 1 | # -*- mode: perl; -*- | ||||||||||
| 2 | |||||||||||
| 3 | package Math::BigInt::Named; | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use 5.006001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use Carp qw( carp croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 5 | ▶ | use Math::BigInt 1.97; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | our @ISA = qw(Math::BigInt); | |||||||||
| 13 | |||||||||||
| 14 | 5 | our $VERSION = '0.08'; | |||||||||
| 15 | |||||||||||
| 16 | # Globals. | ||||||||||
| 17 | |||||||||||
| 18 | 5 | our ($accuracy, $precision, $round_mode, $div_scale); | |||||||||
| 19 | 5 | $accuracy = undef; | |||||||||
| 20 | 5 | $precision = undef; | |||||||||
| 21 | 5 | $round_mode = 'even'; | |||||||||
| 22 | 5 | $div_scale = 40; | |||||||||
| 23 | |||||||||||
| 24 | # Not all of them exist yet. | ||||||||||
| 25 | 5 | my $LANGUAGE = { | |||||||||
| 26 | en => 'english', | ||||||||||
| 27 | de => 'german', | ||||||||||
| 28 | sp => 'spanish', | ||||||||||
| 29 | fr => 'french', | ||||||||||
| 30 | ro => 'romana', | ||||||||||
| 31 | it => 'italian', | ||||||||||
| 32 | no => 'norwegian', | ||||||||||
| 33 | }; | ||||||||||
| 34 | |||||||||||
| 35 | # Index of languages that have been loaded. | ||||||||||
| 36 | |||||||||||
| 37 | 5 | my $LOADED = { }; | |||||||||
| 38 | |||||||||||
| 39 | 61 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=16 SCAR=29.0
Pod
documented
| |||||||||||
| 40 | # output the name of the number | ||||||||||
| 41 | 61 | my $x = shift; | |||||||||
| 42 | |||||||||||
| 43 | # make Math::BigInt::Named -> name(123) work | ||||||||||
| 44 | 61 | ▶ | $x = $x -> new(shift) unless ref($x); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 61 | ▶ | return 'NaN' if $x -> is_nan(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 60 | my @args = (); | |||||||||
| 49 | 60 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 58 | ▶ | if (ref($_[0]) eq 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | ▶ | carp "When the options are given as a hash ref, additional", | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | " arguments are ignored" if @_ > 1; | ||||||||||
| 53 | 0 | @args = %{ $_[0] }; | |||||||||
| 54 | } else { | ||||||||||
| 55 | 58 | @args = @_; | |||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 60 | my $lang; | |||||||||
| 60 | 60 | ▶ | while (@args) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 58 | my $param = shift @args; | |||||||||
| 62 | 58 | ▶ | croak "Parameter name can not be undefined" unless defined $param; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 58 | ▶ | croak "Parameter name can not be an empty string" unless length $param; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 58 | ▶ | if ($param =~ /^lang(uage)?$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 58 | $lang = shift @args; | |||||||||
| 67 | 58 | ▶ | croak "Language can not be undefined" unless defined $lang; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 58 | ▶ | croak "Language can not be an empty string" unless length $lang; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 58 | next; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | croak "Invalid parameter '$param'"; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 60 | ▶ | $lang = 'english' unless defined $lang; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 60 | ▶ | $lang = $LANGUAGE -> {$lang} if exists $LANGUAGE -> {$lang}; # en => english | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | 60 | $lang = 'Math::BigInt::Named::' . ucfirst($lang); | |||||||||
| 79 | |||||||||||
| 80 | 60 | ▶ | if (!defined $LOADED -> {$lang}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 4 | my $file = $lang; | |||||||||
| 82 | 4 | $file =~ s|::|/|g; | |||||||||
| 83 | 4 | $file .= ".pm"; | |||||||||
| 84 | 4 | eval { require $file; }; | |||||||||
| 85 | 4 | ▶ | croak $@ if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 4 | $LOADED -> {$lang} = 1; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 60 | my $y = $lang -> new($x); | |||||||||
| 90 | 60 | $y -> name(); | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 0 | ▶ | sub from_name { | ||||||||
|
Subroutine
from_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 94 | # Create a Math::BigInt::Named from a name string. Not implemented. | ||||||||||
| 95 | |||||||||||
| 96 | 0 | my $x = Math::BigInt -> bnan(); | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 5 | 1; | |||||||||
| 100 | |||||||||||
| 101 | __END__ | ||||||||||