File Coverage

blib/lib/SilverGoldBull/API/AddressRole.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package SilverGoldBull::API::AddressRole;
2              
3 1     1   955 use strict;
  1         1  
  1         28  
4 1     1   3 use warnings;
  1         2  
  1         21  
5              
6 1     1   177 use Mouse::Role;
  0            
  0            
7             use Mouse::Util::TypeConstraints;
8             use Locale::Country qw(all_country_codes);
9              
10             enum 'ISO_3166-1' => map { uc($_) } all_country_codes();
11              
12             has 'country' => ( is => 'rw', isa => 'ISO_3166-1', required => 1 );
13             has 'first_name' => ( is => 'rw', isa => 'Str', required => 1 );
14             has 'last_name' => ( is => 'rw', isa => 'Str', required => 1 );
15             has 'street' => ( is => 'rw', isa => 'Str', required => 1 );
16             has 'city' => ( is => 'rw', isa => 'Str', required => 1 );
17             has 'company' => ( is => 'rw', isa => 'Str', required => 0 );
18             has 'region' => ( is => 'rw', isa => 'Str', required => 0 );
19             has 'phone' => ( is => 'rw', isa => 'Str', required => 0 );
20             has 'postcode' => ( is => 'rw', isa => 'Str', required => 0 );
21             has 'email' => ( is => 'rw', isa => 'Str', required => 0 );
22              
23             around BUILDARGS => sub {
24             my $orig = shift;
25             my $class = shift;
26             my $args = undef;
27              
28             if ( @_ == 1 && ref $_[0] ) {
29             $args = shift;
30             }
31             else {
32             my %hash = shift;
33             $args = \%hash;
34             }
35              
36             $args->{country} = uc($args->{country});
37              
38             return $class->$orig($args);
39             };
40              
41             sub to_hashref {
42             my ($self) = @_;
43             my $hashref = {};
44             for my $field (qw(company country first_name last_name street city region phone postcode email)) {
45             if (defined $self->{$field}) {
46             $hashref->{$field} = $self->{$field};
47             }
48             }
49            
50             return $hashref;
51             }
52              
53             1;