File: FindMatch.pm

package info (click to toggle)
libnet-cli-interact-perl 1.121640-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 368 kB
  • sloc: perl: 1,805; makefile: 2
file content (20 lines) | stat: -rw-r--r-- 487 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package Net::CLI::Interact::Role::FindMatch;
{
  $Net::CLI::Interact::Role::FindMatch::VERSION = '1.121640';
}

use Moose::Role;

# see if any regexp in the arrayref match the response
sub find_match {
    my ($self, $text, $matches) = @_;
    $matches = ((ref $matches eq ref qr//) ? [$matches] : $matches);
    return undef unless
        (scalar grep {ref $_ eq ref qr//} @$matches) == scalar @$matches;

    use List::Util 'first';
    return first { $text =~ $_ } @$matches;
}


1;