File: Module.pm

package info (click to toggle)
plsense 0.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,012 kB
  • sloc: perl: 9,767; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (4)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package PlSense::Plugin::CodeAssistant::Module;

use parent qw{ PlSense::Plugin::CodeAssistant };
use strict;
use warnings;
use Class::Std;
use PlSense::Logger;
use PlSense::Util;
{
    sub is_only_valid_context {
        my ($self, $code, $tok) = @_;

        if ( $code !~ m{ \b (?:use|require) \s+ ([a-zA-Z0-9_:]*) \z }xms ) { return; }
        my $input = $1;
        $self->do_match($input);
        return 1;
    }

    sub is_valid_context {
        my ($self, $code, $tok) = @_;

        my $input;
        if ( $code =~ m{ ["'] ([a-zA-Z0-9_:]+) \z }xms ) {
            $input = $1;
        }
        elsif ( $code =~ m{ ["'] [^"']+ \s+ ([a-zA-Z0-9_:]+) \z }xms ) {
            $input = $1;
        }
        elsif ( $code =~ m{ ([a-zA-Z0-9_:]+) \s+ ([a-zA-Z0-9_:]+) \z }xms ) {
            my $preword = $1;
            $input = $2;
            if ( $preword eq "package" ) { return; }
            if ( $preword eq "sub" ) { return; }
            if ( $preword eq "my" ) { return; }
            if ( $preword eq "our" ) { return; }
            if ( $preword eq "local" ) { return; }
        }
        elsif ( $code =~ m{ (?:\s|^|;|,|\}|\{|\[|\(|=>|\.) \s* ([a-zA-Z0-9_:]+) \z }xms ) {
            $input = $1;
        }
        else {
            return;
        }
        $self->do_match($input);
        return 1;
    }

    sub do_match : PRIVATE {
        my ($self, $input) = @_;
        logger->info("Match context : input[$input]");
        $self->set_input($input);

        logger->notice("Found include modules");
        MODULE:
        foreach my $mdl ( mdlkeeper->get_packages ) {
            $self->push_candidate($mdl->get_name, $mdl);
        }
    }
}

1;

__END__