Perl-Critic / PPI

54 stars 44 forks source link

Parse DSL as a sub #272

Closed shantanu-deriv closed 2 years ago

shantanu-deriv commented 2 years ago

PPI::Statement::Sub can correctly parse subs from a module like this

use PPI;

my $FILE = "Module.pm";
my $doc = PPI::Document->new($FILE);
my $subs = $doc->find('PPI::Statement::Sub');

foreach my $sub (@$subs) {
    print $sub->name;
}

However when it comes to parsing special subs defined as another keywords, consider:

use PPI:
use Future::AsyncAwait; # provides a DSL to define 'async' subs

my $FILE = "AsyncModule.pm";
my $doc = PPI::Document->new($FILE);
my $subs = $doc->find('PPI::Statement::Sub');

foreach my $sub (@$subs) {
    print $sub->name;
}

Where the AsyncModule.pm may look like this:

async sub do {
    ...
}

sub that { ... }

1;

The output of the above script would be only

that

Is there a way to output do also? If not can it be supported?

oalders commented 2 years ago

Unfortunately, this isn't yet possible. I'm going to close this as discussion for this should probably happen in #213. See also #270.

oalders commented 2 years ago

Having said that, if you're volunteering to dig into this, I'm happy for someone to try to tackle it.