blib/lib/Business/AU/ACN.pm

filter: Statementstmt 75.8% 22 / 29 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 50.0% 1 / 2 totaltotal 71.7% 33 / 46 CC 6 SCAR 14.1
CC
6
Cov
72%
pretty
6.0
validate
5.2
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package Business::AU::ACN;
2 1 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $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 <scottp@dd.com.au>,
32 Tom Harrison <tomh@apnic.net>
33  
34 =head1 SEE ALSO
35  
36 L<Business:AU::ACN>
37  
38 =cut
39  
40 4 ▶sub validate {
Subroutine validate: called CC=5 SCAR=16.4
Pod undocumented
41 4 my ($acn) = @_;
42 4 my @acn = _split($acn);
43
44 # check length is 9
45 4 ▶ unless (@acn == 9) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@acn == 9) 0 4 4
46 0 return "invalid length (must be 9)";
47 }
48  
49 # add accumulation
50 4 my $acc = 0;
51 4 ▶ for (my $i = 0; $i < 8; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 8) 32 4 36
52 32 $acc += $acn[$i] * (8 - $i);
53 }
54 4 $acc = 10 - ($acc % 10);
55 4 ▶ if ($acc == 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acc == 10) 2 2 4
56 2 $acc = 0;
57 }
58  
59 # check it is valid
60 4 ▶ if ($acn[8] == $acc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acn[8] == $acc) 4 0 4
61 4 return "valid";
62 }
63  
64 0 return "invalid sum";
65 }
66  
67 4 ▶sub _split {
Subroutine _split: called CC=1 SCAR=0.0
68 4 my ($acn) = @_;
69 # Original change was - $acn =~ s/[^0-9]//g;
70 # Now we just allow white space to be removed
71 4 $acn =~ s/\s//g;
72 4 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 0 ▶sub pretty {
Subroutine pretty: not called CC=2 SCAR=17.9
Pod documented
83 0 my ($acn) = @_;
84 0 my @acn = _split($acn);
85 0 ▶ if (validate($acn) eq "valid") {
Branch: 1 branch
BranchTrueFalseTotal
if (validate($acn) eq 'valid') { } 0 0 0
86 0 return join('', @acn[0..2], ' ', @acn[3..5], ' ', @acn[6..8]);
87 } else {
88 0 return "invalid";
89 }
90 }
91  
92 1 1;
93  
↑ Summary