NAME String::FlexMatch - Flexible ways to match a string SYNOPSIS use String::FlexMatch; my $s = String::FlexMatch->new(string => 'foobar'); if ($s eq 'foobar') { # ... } $s = String::FlexMatch->new(regex => 'Error .* at line \d+'); if ($s eq 'Error "foo" at line 58') { # ... } $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 beforehand 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 $/; }; 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. METHODS "new" my $obj = String::FlexMatch->new; my $obj = String::FlexMatch->new(%args); Creates and returns a new object. The constructor will accept as arguments a list of pairs, from component name to initial value. For each pair, the named component is initialized by calling the method of the same name with the given value. If called with a single hash reference, it is dereferenced and its key/value pairs are set as described before. BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests through the web interface at . 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 to find a CPAN site near you. Or see . AUTHORS Marcel Grünauer, "" COPYRIGHT AND LICENSE Copyright 2004-2009 by the authors. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.