File Coverage

blib/lib/Leading/Zeros.pm
Criterion Covered Total %
statement 18 28 64.2
branch 0 6 0.0
condition n/a
subroutine 6 9 66.6
pod n/a
total 24 43 55.8


line stmt bran cond sub pod time code
1             package Leading::Zeros;
2              
3 1     1   26724 use version; $VERSION = qv('0.0.2');
  1         1970  
  1         5  
4              
5 1     1   61 use warnings;
  1         1  
  1         23  
6 1     1   4 use strict;
  1         6  
  1         20  
7 1     1   5 use Carp;
  1         1  
  1         87  
8 1     1   1498 use overload;
  1         1038  
  1         4  
9              
10             sub import {
11 1     1   7 my ($package, @flags) = @_;
12 1         2 my $converting_to_decimals = !grep { m/\A -warning \z /xms } @flags;
  0         0  
13             overload::constant (
14             binary => sub {
15 0     0     my ($raw, $cooked) = @_;
16 0 0         my ($octal_flag, $digits) = $raw =~ m/\A (0+) (\d+) \z/xms
17             or return $cooked; # since it must have been a hexadecimal
18              
19 0 0         return 0+$digits if $converting_to_decimals;
20            
21 0           carp qq{Warning: octal constant $raw (decimal value: $cooked) used};
22 0           return $cooked;
23             },
24 1         5 );
25             }
26              
27             sub unimport {
28             overload::constant (
29             binary => sub {
30 0     0     my ($raw, $cooked) = @_;
31 0 0         return $cooked if $raw !~ m/\A 0 \d+/xms;
32 0           croak qq{Can't use octal constant ($raw) },
33             qq{while 'no Leading::Zeros' in effect\nError};
34             },
35 0     0     );
36             }
37              
38             1; # Magic true value required at end of module
39             __END__