File Coverage

blib/lib/Business/CPI/Role/Account/Business.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition 2 3 66.6
subroutine 3 3 100.0
pod n/a
total 14 15 93.3


line stmt bran cond sub pod time code
1             package Business::CPI::Role::Account::Business;
2             # ABSTRACT: Business::CPI representation of corporations
3 1     1   401 use Moo::Role;
  1         1  
  1         6  
4 1     1   238 use utf8;
  1         2  
  1         4  
5              
6             our $VERSION = '0.923'; # VERSION
7              
8             has _gateway => ( is => 'ro', required => 1 );
9              
10             has corporate_name => ( is => 'rw' );
11             has trading_name => ( is => 'rw' );
12             has phone => ( is => 'rw' );
13              
14             has address => ( is => 'rw' );
15              
16             around address => sub {
17             my $orig = shift;
18             my $self = shift;
19              
20             if (my $new_address = shift) {
21             return $self->$orig( $self->_inflate_address($new_address) );
22             }
23              
24             return $self->$orig();
25             };
26              
27             around BUILDARGS => sub {
28             my $orig = shift;
29             my $class = shift;
30             my $args = $class->$orig(@_);
31              
32             return $args if !$args->{_gateway};
33              
34             if (exists $args->{address}) {
35             $args->{address} = $class->_inflate_address($args->{address}, $args->{_gateway});
36             }
37              
38             return $args;
39             };
40              
41             sub _inflate_address {
42 2     2   5 my ($self, $addr, $gateway) = @_;
43              
44 2   66     14 $gateway ||= $self->_gateway;
45              
46 2         24 return $gateway->account_address_class->new($addr);
47             }
48              
49             1;
50              
51             __END__