—#######################################################################
# $Date: 2006-03-21 01:41:48 -0800 (Tue, 21 Mar 2006) $
# $Author: thaljef $
# $Revision: 342 $
########################################################################
use
strict;
use
warnings;
use
Perl::Critic::Utils;
our
$VERSION
=
'0.15'
;
$VERSION
=
eval
$VERSION
;
## no critic
#---------------------------------------------------------------------------
my
$leading_rx
=
qr{\A [+-]? (?: 0+ _* )+ [1-9]}
mx;
my
$desc
=
q{Integer with leading zeros}
;
my
$expl
= [ 55 ];
#---------------------------------------------------------------------------
sub
default_severity {
return
$SEVERITY_HIGHEST
}
sub
applies_to {
return
'PPI::Token::Number'
}
#---------------------------------------------------------------------------
sub
violates {
my
(
$self
,
$elem
,
$doc
) =
@_
;
if
(
$elem
=~
$leading_rx
) {
my
$sev
=
$self
->get_severity();
return
Perl::Critic::Violation->new(
$desc
,
$expl
,
$elem
,
$sev
);
}
return
;
#ok!
}
1;
__END__
#---------------------------------------------------------------------------
=pod
=head1 NAME
Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros
=head1 DESCRIPTION
Perl interprets numbers with leading zeros as octal. If that's what
you really want, its better to use C<oct> and make it obvious.
$var = 041; #not ok, actually 33
$var = oct(41); #ok
=head1 AUTHOR
Jeffrey Ryan Thalhammer <thaljef@cpan.org>
=head1 COPYRIGHT
Copyright (c) 2005-2006 Jeffrey Ryan Thalhammer. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
=cut