package Leading::Zeros;
use version; $VERSION = qv('0.0.2');
use warnings;
use strict;
use Carp;
use overload;
sub import {
my ($package, @flags) = @_;
my $converting_to_decimals = !grep { m/\A -warning \z /xms } @flags;
overload::constant (
binary => sub {
my ($raw, $cooked) = @_;
my ($octal_flag, $digits) = $raw =~ m/\A (0+) (\d+) \z/xms
or return $cooked; # since it must have been a hexadecimal
return 0+$digits if $converting_to_decimals;
carp qq{Warning: octal constant $raw (decimal value: $cooked) used};
return $cooked;
},
);
}
sub unimport {
overload::constant (
binary => sub {
my ($raw, $cooked) = @_;
return $cooked if $raw !~ m/\A 0 \d+/xms;
croak qq{Can't use octal constant ($raw) },
qq{while 'no Leading::Zeros' in effect\nError};
},
);
}
1; # Magic true value required at end of module
__END__
=head1 NAME
Leading::Zeros - Defuse Perl's octal number representation
=head1 VERSION
This document describes Leading::Zeros version 0.0.2
=head1 SYNOPSIS
no Leading::Zeros;
my $answer = 042; # dies
=head1 DESCRIPTION
This module offers some control over Perl's insidious
"leading-zero-means-octal" notation.
=head1 INTERFACE
If the module is loaded via a C:
no Leading::Zeros;
then any subsequent attempt to use an integer constant with a leading
zero, causes an exception to be thrown. The intention is to prevent you
from doing so by accident.
If the module is loaded via a C