root/lang/perl/Business-Address-POBox/tags/Business-Address-POBox-0.06/lib/Business/Address/POBox.pm @ 10087

Revision 10087, 2.8 kB (checked in by hanekomu, 5 years ago)

lang/perl/Business-Address-POBox: initial import

RevLine 
[10087]1package Business::Address::POBox;
2
3use strict;
4use warnings;
5use String::BlackWhiteList;
6
7
8our $VERSION = '0.06';
9
10
11use 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
20use 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
70sub init {
71    my $self = shift;
72    $self->update;
73}
74
75
76sub 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
87sub is_pobox {
88    my ($self, $text) = @_;
89    !$self->matcher->valid($text);
90}
91
92
931;
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
114This class tries to determine whether or not an string refers to a P.O. box.
115This is sometims relevant if your business process, for legal reasons, needs a
116real address and not a P.O. box.
117
118It has predefined blacklists and whitelists that should catch most english and
119german P.O. box addresses, but you can modify these lists with the methods
120provided. 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
130Call this method when you've changed the C<whitelist()> or the C<blacklist()>
131so the matcher knows about the changes.
132
133=item is_pobox
134
135This is the central method of this class. It takes a string argument and
136checks it against the whitelist and the blacklist. Returns a boolean value -
137true if the string passes the whitelist or is at least not caught by the
138blacklist, 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
Note: See TracBrowser for help on using the browser.