| 1 | package Algorithm::BestChoice::Matcher; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 10 | ▶ | sub parse { | ||||||||||||
|
Subroutine
parse: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||||
| 4 | 10 | my $class = shift; | |||||||||||||
| 5 | 10 | my $matcher = shift; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 10 | ▶ | return Algorithm::BestChoice::Matcher::Always->new unless defined $matcher; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 8 | ▶ | $matcher = qr/^\Q$matcher\E$/ unless ref $matcher; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 8 | ▶ | if (ref $matcher eq 'Regexp') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 12 | 8 | return Algorithm::BestChoice::Matcher::Regexp->new( regexp => $matcher ); | |||||||||||||
| 13 | } | ||||||||||||||
| 14 | elsif (ref $matcher eq 'CODE') { | ||||||||||||||
| 15 | 0 | return Algorithm::BestChoice::Matcher::Code->new( code => $matcher ); | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | die "Don't understand matcher $matcher"; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 3 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | # TODO Make this a role? | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | ▶ | sub match { | ||||||||||||
|
Subroutine
match: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 26 | 0 | die "Unspecific matcher can't match"; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | package Algorithm::BestChoice::Matcher::Always; | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 3 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | |||||||||||||||
| 33 | 3 | extends qw/Algorithm::BestChoice::Matcher/; | |||||||||||||
| 34 | |||||||||||||||
| 35 | 15 | ▶ | sub match { 1 } | ||||||||||||
|
Subroutine
match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 36 | |||||||||||||||
| 37 | 3 | 1; | |||||||||||||
| 38 | |||||||||||||||
| 39 | package Algorithm::BestChoice::Matcher::Regexp; | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 3 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 42 | |||||||||||||||
| 43 | 3 | extends qw/Algorithm::BestChoice::Matcher/; | |||||||||||||
| 44 | |||||||||||||||
| 45 | 3 | has regexp => qw/is ro required 1 isa RegexpRef/; | |||||||||||||
| 46 | |||||||||||||||
| 47 | 33 | ▶ | sub match { | ||||||||||||
|
Subroutine
match: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 48 | 33 | my $self = shift; | |||||||||||||
| 49 | 33 | my $key = shift; | |||||||||||||
| 50 | |||||||||||||||
| 51 | 33 | ▶ | return 0 unless defined $key; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 30 | return $key =~ $self->regexp; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | package Algorithm::BestChoice::Matcher::Code; | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 3 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 3 | extends qw/Algorithm::BestChoice::Matcher/; | |||||||||||||
| 60 | |||||||||||||||
| 61 | 3 | has code => qw/is ro required 1 isa CodeRef/; | |||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | ▶ | sub match { | ||||||||||||
|
Subroutine
match: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||
| 65 | 0 | my $key = shift; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | return $self->code( $key ); | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 3 | 1; | |||||||||||||