File Coverage

blib/lib/Business/CompanyDesignator/Record.pm
Criterion Covered Total %
statement 27 27 100.0
branch 6 6 100.0
condition 2 2 100.0
subroutine 8 8 100.0
pod n/a
total 43 43 100.0


line stmt bran cond sub pod time code
1             package Business::CompanyDesignator::Record;
2              
3 9     9   59 use Moose;
  9         17  
  9         85  
4 9     9   58689 use utf8;
  9         20  
  9         64  
5 9     9   285 use warnings qw(FATAL utf8);
  9         19  
  9         447  
6 9     9   51 use Carp;
  9         18  
  9         570  
7 9     9   4836 use namespace::autoclean;
  9         64508  
  9         54  
8              
9             has 'long' => ( is => 'ro', isa => 'Str', required => 1 );
10             has 'record' => ( is => 'ro', isa => 'HashRef', required => 1 );
11              
12             has [qw(abbr1 lang)] => ( is => 'ro', lazy_build => 1 );
13             has 'abbr' => ( is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, builder => '_build_abbr',
14             reader => '_abbr', traits => [ qw(Array) ], handles => { abbr => 'elements' } );
15              
16             sub _build_abbr {
17 665     665   997 my $self = shift;
18 665         17842 my $abbr_std = $self->record->{abbr_std};
19 665   100     16748 my $abbr = $self->record->{abbr} || [];
20 665 100       1594 $abbr = [ $abbr ] if ! ref $abbr;
21 665 100       1292 push @$abbr, $abbr_std if $abbr_std;
22 665         20860 return $abbr;
23             }
24              
25             sub _build_abbr1 {
26 665     665   1010 my $self = shift;
27 665         21432 my @abbr = $self->abbr;
28 665 100       2487 if (@abbr) {
29 653         17305 return $abbr[0];
30             }
31             }
32              
33             sub _build_lang {
34 943     943   1610 my $self = shift;
35 943         25912 $self->record->{lang};
36             }
37              
38             __PACKAGE__->meta->make_immutable;
39              
40             1;
41              
42             =head1 NAME
43              
44             Business::CompanyDesignator::Record - class for modelling individual L<Business::CompanyDesignator> input records
45              
46             =head1 SYNOPSIS
47              
48             # Typically instantiated via Business::CompanyDesignator->record() or records()
49             use Business::CompanyDesignator;
50            
51             $bcd = Business::CompanyDesignator->new;
52             $record = $bcd->record("Limited");
53             @records = $bcd->records("Inc.");
54              
55             # Accessors
56             $long = $record->long;
57             @abbr = $record->abbr;
58             $abbr1 = $record->abbr1;
59             $lang = $record->lang;
60              
61             =head1 METHODS
62              
63             =head2 new()
64              
65             Create a new Business::CompanyDesignator::Record object.
66              
67             B<Note:> objects are normally instantiated via Business::CompanyDesignator->record()
68             or records(), however:
69              
70             use Business::CompanyDesignator;
71            
72             $bcd = Business::CompanyDesignator->new;
73             $record = $bcd->record("Limited");
74             @records = $bcd->records("Inc.");
75              
76             =head2 long()
77              
78             Returns the record's long designator (a string).
79              
80             $long = $record->long;
81              
82             =head2 abbr()
83              
84             Returns a list of the abbreviations associated with this record (if any).
85              
86             @abbr = $record->abbr;
87              
88             =head2 abbr1()
89              
90             Returns the first abbreviation associated with this record (a string, if any).
91              
92             $abbr1 = $record->abbr1;
93              
94             =head2 lang()
95              
96             Returns the ISO-639 language code associated with this record (a string).
97              
98             $lang = $record->lang;
99              
100             =head1 AUTHOR
101              
102             Gavin Carr <gavin@profound.net>
103              
104             =head1 COPYRIGHT AND LICENCE
105              
106             Copyright (C) 2013-2015 Gavin Carr
107              
108             This library is free software; you can redistribute it and/or modify it
109             under the same terms as Perl itself.
110              
111             =cut
112