File: Class.pm

package info (click to toggle)
libmoosex-app-perl 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 712 kB
  • sloc: perl: 4,011; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# ============================================================================
package MooseX::App::Plugin::Typo::Meta::Class;
# ============================================================================

use 5.010;
use utf8;

use namespace::autoclean;
use Moose::Role;

use Text::WagnerFischer qw(distance);

around 'command_candidates' => sub {
    my ($orig,$self,$command) = @_;

    my $lc_command = lc($command);
    my $commands = $self->app_commands;

    # Fuzzy match
    my @candidates;
    my $candidate_length = length($command);

    # Compare all commands to find matching candidates
    foreach my $command_name (keys %$commands) {
        my $candidate_substr = substr($command_name,0,$candidate_length+1);
        if ($lc_command eq $command_name) {
            return $command_name;
        } elsif ($lc_command eq $candidate_substr
            || distance($lc_command,$candidate_substr) <= 1) {
            push(@candidates,$command_name);
        }
    }
    return [ sort @candidates ];
};

1;