| [10087] | 1 | package Business::Address::POBox; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use String::BlackWhiteList; |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | our $VERSION = '0.06'; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | use base qw(Class::Accessor::Complex Class::Accessor::Constructor); |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | __PACKAGE__ |
|---|
| 15 | ->mk_constructor |
|---|
| 16 | ->mk_object_accessors('String::BlackWhiteList' => 'matcher') |
|---|
| 17 | ->mk_array_accessors(qw(blacklist whitelist)); |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | use constant DEFAULTS => ( |
|---|
| 21 | blacklist => [ |
|---|
| 22 | 'BOX', |
|---|
| 23 | 'POB', |
|---|
| 24 | 'POSTBOX', |
|---|
| 25 | 'POST', |
|---|
| 26 | 'POSTSCHACHTEL', |
|---|
| 27 | 'PO', |
|---|
| 28 | 'P O', |
|---|
| 29 | 'P O BOX', |
|---|
| 30 | 'P.O.', |
|---|
| 31 | 'P.O.B.', |
|---|
| 32 | 'P.O.BOX', |
|---|
| 33 | 'P.O. BOX', |
|---|
| 34 | 'P. O.', |
|---|
| 35 | 'P. O.BOX', |
|---|
| 36 | 'P. O. BOX', |
|---|
| 37 | 'POBOX', |
|---|
| 38 | 'PF', |
|---|
| 39 | 'P.F.', |
|---|
| 40 | 'POSTFACH', |
|---|
| 41 | 'POSTLAGERND', |
|---|
| 42 | 'POSTBUS' |
|---|
| 43 | ], |
|---|
| 44 | whitelist => [ |
|---|
| 45 | 'Post Road', |
|---|
| 46 | 'Post Rd', |
|---|
| 47 | 'Post Street', |
|---|
| 48 | 'Post St', |
|---|
| 49 | 'Post Avenue', |
|---|
| 50 | 'Post Av', |
|---|
| 51 | 'Post Alley', |
|---|
| 52 | 'Post Drive', |
|---|
| 53 | 'Post Grove', |
|---|
| 54 | 'Post Walk', |
|---|
| 55 | 'Post Parkway', |
|---|
| 56 | 'Post Row', |
|---|
| 57 | 'Post Lane', |
|---|
| 58 | 'Post Bridge', |
|---|
| 59 | 'Post Boulevard', |
|---|
| 60 | 'Post Square', |
|---|
| 61 | 'Post Garden', |
|---|
| 62 | 'Post Strasse', |
|---|
| 63 | 'Post Allee', |
|---|
| 64 | 'Post Gasse', |
|---|
| 65 | 'Post Platz', |
|---|
| 66 | ], |
|---|
| 67 | ); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | sub init { |
|---|
| 71 | my $self = shift; |
|---|
| 72 | $self->update; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | sub update { |
|---|
| 77 | my $self = shift; |
|---|
| 78 | for ($self->matcher) { |
|---|
| 79 | $_->set_is_literal_text; |
|---|
| 80 | $_->blacklist($self->blacklist); |
|---|
| 81 | $_->whitelist($self->whitelist); |
|---|
| 82 | $_->update; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | sub is_pobox { |
|---|
| 88 | my ($self, $text) = @_; |
|---|
| 89 | !$self->matcher->valid($text); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | 1; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | __END__ |
|---|
| 97 | |
|---|
| 98 | {% USE p = PodGenerated %} |
|---|
| 99 | |
|---|
| 100 | =head1 NAME |
|---|
| 101 | |
|---|
| 102 | {% p.package %} - Check whether an address looks like a P.O.Box |
|---|
| 103 | |
|---|
| 104 | =head1 SYNOPSIS |
|---|
| 105 | |
|---|
| 106 | use {% p.package %}; |
|---|
| 107 | |
|---|
| 108 | if ({% p.package %}->new->is_pobox($address)) { |
|---|
| 109 | ... |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | =head1 DESCRIPTION |
|---|
| 113 | |
|---|
| 114 | This class tries to determine whether or not an string refers to a P.O. box. |
|---|
| 115 | This is sometims relevant if your business process, for legal reasons, needs a |
|---|
| 116 | real address and not a P.O. box. |
|---|
| 117 | |
|---|
| 118 | It has predefined blacklists and whitelists that should catch most english and |
|---|
| 119 | german P.O. box addresses, but you can modify these lists with the methods |
|---|
| 120 | provided. Note that the entries are literal strings, not regular expressions. |
|---|
| 121 | |
|---|
| 122 | =head1 METHODS |
|---|
| 123 | |
|---|
| 124 | =over 4 |
|---|
| 125 | |
|---|
| 126 | {% p.write_methods %} |
|---|
| 127 | |
|---|
| 128 | =item update |
|---|
| 129 | |
|---|
| 130 | Call this method when you've changed the C<whitelist()> or the C<blacklist()> |
|---|
| 131 | so the matcher knows about the changes. |
|---|
| 132 | |
|---|
| 133 | =item is_pobox |
|---|
| 134 | |
|---|
| 135 | This is the central method of this class. It takes a string argument and |
|---|
| 136 | checks it against the whitelist and the blacklist. Returns a boolean value - |
|---|
| 137 | true if the string passes the whitelist or is at least not caught by the |
|---|
| 138 | blacklist, false if the string is caught by the blacklist. |
|---|
| 139 | |
|---|
| 140 | =back |
|---|
| 141 | |
|---|
| 142 | {% p.write_inheritance %} |
|---|
| 143 | |
|---|
| 144 | {% PROCESS standard_pod %} |
|---|
| 145 | |
|---|
| 146 | =cut |
|---|
| 147 | |
|---|