{ my $isint = qr{^\s*-?\d+\s*$}; my $isfrac = qr{^\s*(-?\d+)(/(-?\d+))?$}; my %_const_handlers = (q => sub { if ($_[1] =~ $isfrac) { return __PACKAGE__->new(num => $1, den => $3 || 1) || $_[1]; } else { $_[1]; } }); sub import { overload::constant %_const_handlers if $_[1] and $_[1] eq ':constants'; } sub unimport { overload::remove_constant(q => undef); }
Casiano Rodríguez León