File Coverage

blib/lib/Business/CompanyDesignator/SplitResult.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 4 7 57.1
subroutine 7 7 100.0
pod 2 2 100.0
total 34 37 91.8


line stmt bran cond sub pod time code
1             package Business::CompanyDesignator::SplitResult;
2              
3 9     9   62 use Moose;
  9         19  
  9         74  
4 9     9   52664 use utf8;
  9         38  
  9         65  
5 9     9   261 use warnings qw(FATAL utf8);
  9         18  
  9         411  
6 9     9   70 use Carp;
  9         24  
  9         646  
7 9     9   65 use namespace::autoclean;
  9         25  
  9         78  
8              
9             has [ qw(before after designator designator_std) ] =>
10             ( is => 'ro', isa => 'Str', required => 1 );
11             has 'records' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
12              
13             sub short_name {
14 240     240 1 53255 my $self = shift;
15 240   66     7710 return $self->before || $self->after // '';
      50        
16             }
17              
18             sub extra {
19 240     240 1 474 my $self = shift;
20 240 100 50     7421 return $self->before ? ($self->after // '') : '';
21             }
22              
23             __PACKAGE__->meta->make_immutable;
24              
25             1;
26              
27             =head1 NAME
28              
29             Business::CompanyDesignator::SplitResult - class for modelling
30             L<Business::CompanyDesignator::split_designator> result records
31              
32             =head1 SYNOPSIS
33              
34             # Returned by split_designator in scalar context
35             $bcd = Business::CompanyDesignator->new;
36             $res = $bcd->split_designator("Open Fusion Pty Ltd (Australia)");
37              
38             # Accessors
39             say $res->designator; # Pty Ltd (designator as found in input string)
40             say $res->designator_std; # Pty. Ltd. (standardised version of designator)
41             say $res->before; # Open Fusion (trimmed text before designator)
42             say $res->after; # (Australia) (trimmed text after designator)
43             say $res->short_name; # Open Fusion ($res->before || $res->after)
44             say $res->extra; # (Australia) ($res->before ? $res->after : '')
45              
46             # Designator records arrayref (since designator might be ambiguous and map to multiple)
47             foreach (@{ $res->records }) {
48             say join ", ", $_->long, $_->lang;
49             }
50              
51              
52             =head1 ACCESSORS
53              
54             =head2 designator()
55              
56             If a designator is found, returns the matched designator as it exists in
57             the input string. Otherwise returns an empty string ('').
58              
59             say $res->designator;
60              
61             =head2 designator_std()
62              
63             If a designator is found, returns the standardised version of the designator
64             as it exists in the company designator dataset. This may or may not match
65             $res->designator().
66              
67             say $res->designator_std;
68              
69             e.g. "Open Fusion Pty Ltd" would return a designator of 'Pty Ltd', but a
70             designator_std of 'Pty. Ltd.' (with the dots).
71              
72             The designator_std version can be used to retrieve the matching dataset
73             record(s) using $bcd->records( $res->designator_short ).
74              
75             =head2 before()
76              
77             If a non-leading designator is found, returns the (whitespace-trimmed)
78             text before the designator. If a leading designator is found, returns
79             an empty string (''). If no designator is found, returns the full company
80             name i.e. the input.
81              
82             say $res->before;
83              
84             =head2 after()
85              
86             If a designator is found, returns the (whitespace-trimmed) text after the
87             designator, if any. Otherwise returns an empty string ('').
88              
89             say $res->after;
90              
91             =head2 short_name()
92              
93             If a non-leading designator is found, returns $res->before. If a leading
94             designator is found, returns, $res->after. That is, it returns the logical
95             'short name' of the company (stripped of the designator), for both trailing
96             and leading designators.
97              
98             =head2 extra()
99              
100             If a non-leading designator is found, returns $res->after. That is, it's any
101             extra text not include in $res->short_name, if any. Otherwise returns an
102             empty string ('').
103              
104             =head1 AUTHOR
105              
106             Gavin Carr <gavin@profound.net>
107              
108             =head1 COPYRIGHT AND LICENCE
109              
110             Copyright (C) 2013-2015 Gavin Carr
111              
112             This library is free software; you can redistribute it and/or modify it
113             under the same terms as Perl itself.
114              
115             =cut