NAME

String::BlackWhiteList - Match a string against a blacklist and a whitelist

VERSION

version 1.100860

SYNOPSIS

        use String::BlackWhiteList;
        use Test::More;

        use constant BLACKLIST => (
            'POST',
            'PO',
            'P O',
            'P O BOX',
            'P.O.',
            'P.O.B.',
            'P.O.BOX',
            'P.O. BOX',
            'P. O.',
            'P. O.BOX',
            'P. O. BOX',
            'POBOX',
        );

        use constant WHITELIST => (
            'Post Road',
            'Post Rd',
            'Post Street',
            'Post St',
            'Post Avenue',
            'Post Av',
            'Post Alley',
            'Post Drive',
        );

        my @ok = (
            'Post Road 123',
            'Post Rd 123',
            'Post Street 123',
            'Post St 123',
            'Post Avenue 123',
        );

        my @not_ok = (
            'Post',
            'P.O. BOX 37',
            'P.O. BOX 37, Post Drive 9',
            'Post Street, P.O.B.',
        );

        plan tests => @ok + @not_ok;

        my $matcher = String::BlackWhiteList->new(
            blacklist => [ BLACKLIST ],
            whitelist => [ WHITELIST ]
        )->update;

        ok( $matcher->valid($_), "[$_] valid")   for @ok;
        ok(!$matcher->valid($_), "[$] invalid") for @notok;

DESCRIPTION

Using this class you can match strings against a blacklist and a whitelist. The matching algorithm is explained in the "valid()" method's documentation.

METHODS
black_re
The actual regular expression (preferably created by "qr//") used for blacklist testing.

white_re
The actual regular expression (preferably created by "qr//") used for whitelist testing.

update
Takes the blacklist from "blacklist()", generates a regular expression that matches any string in the blacklist and sets the regular expression on "black_re()".

Also takes the whitelist from "whitelist()", generates a regular expression that matches any string in the whitelist and sets the regular expression on "white_re()".

The individual entries of "blacklist()" and "whitelist()" are assumed to be regular expressions. If you have some regular expressions and some literal strings, you can use "\Q...\E". If all your strings are literal strings, set "is_literal_text()".

If you set a "black_re()" and a "white_re()" yourself, you shouldn't use <"update()", of course.

valid
Takes a string and tries to determine whether it is valid according to the blacklist and the whitelist. This is the algorithm used to determine

validity

If the string matches the whitelist, then the part of the string that didn't match the whitelist is checked against the blacklist. If the remainder matches the blacklist, the string is still considered invalid. If not, it is considered valid.

Consider the example of "P.O. BOX 37, Post Drive 9" in the "SYNOPSIS". The "Post Drive" matches the whitelist, but the "P.O. BOX" matches the blacklist, so the string is still considered invalid.

If the string doesn't match the whitelist, but it matches the blacklist, then it is considered invalid.

If the string matches neither the whitelist nor the blacklist, it is considered valid.

Undefined values and empty strings are considered valid. This may seem strange, but there is no indication that they are invalid and when in doubt, trust them.

valid_relaxed
Like valid(), but once a string passes the whitelist, it is not checked against the blacklist anymore. That is, if a string matches the whitelist, it is valid. If not, it is checked against the blacklist - if it matches, it is invalid. If it matches neither whitelist nor blacklist, it is valid.

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=String-BlackWhiteList> .

AVAILABILITY

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you, or see
<http://search.cpan.org/dist/String-BlackWhiteList/>.

The development version lives at
<http://github.com/hanekomu/String-BlackWhiteList/>. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2005 by Marcel Gruenauer.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.