Here's a complete implementation with tests for an overloaded string that's greater than any other string. Its a pretty simple overload, why screw around with approximations?
package String::Infinity;
use overload
'""' => sub {
return "Infinity"
},
'cmp' => sub {
my($left, $right, $reverse) = @_;
return 0 if ref $right && $right->isa("String::Infinity");
return $reverse ? -1 : 1;
},
fallback => 1
;
sub new {
my $class = shift;
return bless \Inf, $class;
}
use Test::More;
my $inf = String::Infinity->new;
is "$inf", "Infinity", "stringification";
ok $inf eq $inf, "equals itself";
ok $inf ne "foo", " doesn't equal anything else";
ok $inf ne "Infinity", " even what it stringifies to";
ok $inf gt "lfkdlk", " greater than";
ok !$inf lt "lkafj", " not less than";
is $inf cmp "lkjd", 1, " cmp";
is "ldfjal;kjd" cmp $inf, -1, " cmp reversed";
done_testing;