File Coverage

blib/lib/Business/AU/ACN.pm
Criterion Covered Total %
statement 20 27 74.0
branch 4 8 50.0
condition n/a
subroutine 4 5 80.0
pod 1 2 50.0
total 29 42 69.0


line stmt bran cond sub pod time code
1             package Business::AU::ACN;
2 1     1   9835 use base qw/Exporter/;
  1         2  
  1         157  
3 1     1   6 use vars qw/$VERSION/;
  1         2  
  1         359  
4             $VERSION = "0.31";
5              
6             =head1 NAME
7              
8             Business::AU::ACN - Validate ACN - Australian Company Number
9              
10             =head1 SYNOPSIS
11              
12             use Business::AU::ACN;
13            
14             print Business::AU::ACN::validate("123 456 789");
15              
16             =head1 DESCRIPTION
17              
18             NOTE: This also covers ARSN (Australian Registerted Scheme Numbers) and
19             ARBN (Australian Registered Body Numbers), but not ABN (Australian Business
20             Numbers).
21              
22             =head1 NOTES
23              
24             This is bound to change (damn content management system URLs) but here is where
25             the original ifnormation is:
26              
27             http://www.asic.gov.au/asic/ASIC_INFOCO.NSF/byid/CA256AE900038AEACA256AFB008053ED?opendocument
28              
29             =head1 AUTHOR
30              
31             Scott Penrose ,
32             Tom Harrison
33              
34             =head1 SEE ALSO
35              
36             L
37              
38             =cut
39              
40             sub validate {
41 4     4 0 151 my ($acn) = @_;
42 4         11 my @acn = _split($acn);
43            
44             # check length is 9
45 4 50       15 unless (@acn == 9) {
46 0         0 return "invalid length (must be 9)";
47             }
48              
49             # add accumulation
50 4         5 my $acc = 0;
51 4         12 for (my $i = 0; $i < 8; $i++) {
52 32         88 $acc += $acn[$i] * (8 - $i);
53             }
54 4         6 $acc = 10 - ($acc % 10);
55 4 100       10 if ($acc == 10) {
56 2         3 $acc = 0;
57             }
58              
59             # check it is valid
60 4 50       13 if ($acn[8] == $acc) {
61 4         25 return "valid";
62             }
63              
64 0         0 return "invalid sum";
65             }
66              
67             sub _split {
68 4     4   5 my ($acn) = @_;
69             # Original change was - $acn =~ s/[^0-9]//g;
70             # Now we just allow white space to be removed
71 4         25 $acn =~ s/\s//g;
72 4         26 return split(//, $acn);
73             }
74              
75             =head2 pretty($acn)
76              
77             This prints out a valid pretty print of an ACN. The standards says that it must
78             be showed in groups of three (nnn nnn nnn).
79              
80             =cut
81              
82             sub pretty {
83 0     0 1   my ($acn) = @_;
84 0           my @acn = _split($acn);
85 0 0         if (validate($acn) eq "valid") {
86 0           return join('', @acn[0..2], ' ', @acn[3..5], ' ', @acn[6..8]);
87             } else {
88 0           return "invalid";
89             }
90             }
91              
92             1;
93