NAME
String::FlexMatch - flexible ways to match a string
SYNOPSIS
use String::FlexMatch;
my $s = String::FlexMatch->new(string => 'foobar');
if ($s eq 'foobar') {
...
}
my $s = String::FlexMatch->new(regex => 'Error .* at line \d+');
if ($s eq 'Error "foo" at line 58') {
...
}
my $s = String::FlexMatch->new(code => 'sub { length $_[0] < 10 }');
# or:
# my $s = String::FlexMatch->new(code => sub { length $_[0] < 10 });
if ($s ne 'somelongstring') {
...
}
DESCRIPTION
Normally when trying to see whether two strings are equal, you use the eq
operator. If you want to find out whether one string matches another more flexibly, you'd use a regular expression. And sometimes you have to call a subroutine with a string argument that will tell you whether that argument is interesting, i.e. matches in a broader sense.
When running data-driven tests, you sometimes don't know per se which form of matching (eq
, regex or code) you need. Take the following example:
use Test::More;
use String::FlexMatch;
use YAML;
sub frobnicate { $_[0] + $_[1] }
my $tests = Load do { local $/; <DATA> };
plan tests => scalar @$tests;
for my $test (@$tests) {
my $baz = frobnicate($test->{testarg}{foo}, $test->{testarg}{bar});
is($baz, $test->{expect}{baz});
}
__DATA__
-
testarg:
foo: 2
bar: 3
expect:
baz: 5
-
testarg:
foo: 21
bar: 34
expect:
baz: !perl/String::FlexMatch
regex: '\d+'
A setup like this was the reason for writing this class. If you find any other uses for it, please let me know so this manpage can be expanded with a few cookbook-style examples.
TAGS
If you talk about this module in blogs, on del.icio.us or anywhere else, please use the stringflexmatch
tag.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-string-flexmatch@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
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://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
AUTHOR
Marcel Grünauer, <marcel@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2004-2007 by Marcel Grünauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.