File Coverage

blib/lib/Business/CA/GST.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1 1     1   766 use strict;
  1         2  
  1         30  
2 1     1   5 use warnings;
  1         1  
  1         31  
3              
4 1     1   19 use 5.006;
  1         3  
  1         45  
5              
6             package Business::CA::GST;
7             $Business::CA::GST::VERSION = '1.03';
8 1     1   850 use Moo;
  1         30383  
  1         10  
9 1     1   1809 use Carp qw( croak );
  1         2  
  1         346  
10              
11             my %TAX = (
12             AB => { rate => 0.05, type => 'GST' },
13             BC => { rate => 0.12, type => 'GST' },
14             MB => { rate => 0.05, type => 'GST' },
15             NB => { rate => 0.13, type => 'HST' },
16             NL => { rate => 0.13, type => 'HST' },
17             NS => { rate => 0.15, type => 'HST' },
18             NT => { rate => 0.05, type => 'GST' },
19             ON => { rate => 0.13, type => 'HST' },
20             PE => { rate => 0.05, type => 'GST' },
21             SK => { rate => 0.05, type => 'GST' },
22             QC => { rate => 0.05, type => 'GST' },
23             YT => { rate => 0.05, type => 'GST' },
24             NU => { rate => 0.05, type => 'GST' },
25             );
26              
27             has 'buyer_region' => ( is => 'rw', );
28              
29             sub rate {
30 28     28 1 1537 my $self = shift;
31              
32 28         44 $self->_validate_region;
33 27         229 return $TAX{ $self->buyer_region }->{rate};
34             }
35              
36             sub tax_type {
37 27     27 1 36 my $self = shift;
38              
39 27         42 $self->_validate_region;
40 27         104 return $TAX{ $self->buyer_region }->{type};
41             }
42              
43             sub _validate_region {
44 55     55   53 my $self = shift;
45              
46 55 100       143 if ( !exists $TAX{ $self->buyer_region } ) {
47 1         29 croak "invalid buyer_region: " . $self->buyer_region;
48             }
49              
50 54         67 return 1;
51             }
52              
53             __PACKAGE__->meta->make_immutable;
54              
55             1;
56              
57             # ABSTRACT: Look up Canadian Federal Sales Tax rates
58              
59             __END__