| 1 | package Seis::Int; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use utf8; | ||
| 5 | use 5.010_001; | ||
| 6 | |||
| 7 | package # Hide from PAUSE | ||
| 8 | Int; | ||
| 9 | |||
| 10 | sub perl { $_[0] } | ||
| 11 | |||
| 12 | sub clone { 0+$_[0] } | ||
| 13 | |||
| 14 | sub say { CORE::say($_[0]) } | ||
| 15 | |||
| 16 | sub isa { | ||
| 17 | my ($self, $stuff) = @_; | ||
| 18 | return $stuff->{name} eq 'Int' if UNIVERSAL::isa($stuff, 'Seis::Class'); | ||
| 19 | # Yes, it's boolean. | ||
| 20 | return 1 if Bool::_isBoolean($self) && $stuff eq 'Seis::Bool'; | ||
| 21 | return 1 if $stuff eq 'Int'; | ||
| 22 | return 0; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub Bool { Bool::boolean($_[0]) } | ||
| 26 | |||
| 27 | sub WHAT { | ||
| 28 | my $self = shift; | ||
| 29 | Seis::Class->_new(name => 'Int'); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub base { | ||
| 33 | my ($num, $base) = @_; | ||
| 34 | require Math::BaseCnv; | ||
| 35 | Math::BaseCnv::cnv($num, 10, $base); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub defined { 1 } | ||
| 39 | |||
| 40 | sub chr: method { CORE::chr($_[0]) } | ||
| 41 | |||
| 42 | sub rand:method { CORE::rand($_[0]) } | ||
| 43 | |||
| 44 | sub fmt { | ||
| 45 | my ($self, $pattern) = @_; | ||
| 46 | $pattern //= "%d"; | ||
| 47 | sprintf($pattern, $self); | ||
| 48 | } | ||
| 49 | |||
| 50 | { | ||
| 51 | # Note. | ||
| 52 | # I don't think Math::Prime::Util is the best solution to solve the 'is_prime' problem. | ||
| 53 | # If you know the best module for this issue, patches welcome. | ||
| 54 | # Small memory foot point is great. And if you can write a fast xs code, it's the best. | ||
| 55 | sub isーprime { | ||
| 56 | require Math::Prime::Util; | ||
| 57 | Math::Prime::Util::is_prime($_[0]) | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub Int { $_[0] } | ||
| 62 | |||
| 63 | sub ords { | ||
| 64 | my @ret = map { ord($_) } split //, $_[0]; | ||
| 65 | wantarray ? @ret : \@ret; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub rindex:method { goto &Str::rindex } | ||
| 69 | |||
| 70 | sub kv { | ||
| 71 | [0, $_[0]] | ||
| 72 | } | ||
| 73 | |||
| 74 | sub sign { | ||
| 75 | my $self = shift; | ||
| 76 | if ($self < 0) { | ||
| 77 | -1; | ||
| 78 | } elsif ($self == 0) { | ||
| 79 | 0; | ||
| 80 | } else { | ||
| 81 | 1; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 1; | ||
| 86 |