« blib/lib/Perl/PrereqScanner/NotQuiteLite/Util.pm
↑ Summary
blib/lib/Perl/PrereqScanner/NotQuiteLite/Parser/AnyMoose.pm »
| 1 | package Perl::PrereqScanner::NotQuiteLite::Parser::PackageVariant; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Perl::PrereqScanner::NotQuiteLite::Util; | ||
| 6 | |||
| 7 | sub register {{ | ||
| 8 | use => { | ||
| 9 | 'Package::Variant' => 'parse_package_variant_args', | ||
| 10 | }, | ||
| 11 | }} | ||
| 12 | |||
| 13 | sub parse_package_variant_args { | ||
| 14 | my ($class, $c, $used_module, $raw_tokens) = @_; | ||
| 15 | |||
| 16 | my $tokens = convert_string_tokens($raw_tokens); | ||
| 17 | |||
| 18 | while(my $token = shift @$tokens) { | ||
| 19 | if (ref $token and $token->[0] eq 'importing') { | ||
| 20 | shift @$tokens if @$tokens && $tokens->[0][1] eq 'COMMA'; | ||
| 21 | my $next_token = shift @$tokens or last; | ||
| 22 | if (!ref $next_token) { | ||
| 23 | my $module = $next_token; | ||
| 24 | if (is_module_name($module)) { | ||
| 25 | $c->add($module); | ||
| 26 | if ($c->has_callback_for(use => $module)) { | ||
| 27 | $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], [";", ";"]]); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | elsif ($next_token->[1] eq '[]') { | ||
| 32 | my $modules = convert_string_token_list($next_token->[0]); | ||
| 33 | while(my $module = shift @$modules) { | ||
| 34 | next unless is_module_name($module); | ||
| 35 | $c->add($module); | ||
| 36 | if ($c->has_callback_for(use => $module)) { | ||
| 37 | $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], [";", ";"]]); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } elsif ($next_token->[1] eq '{}') { | ||
| 41 | my $hash_tokens = convert_string_token_list($next_token->[0]); | ||
| 42 | while(my $module = shift @$hash_tokens) { | ||
| 43 | my $arg = shift @$hash_tokens; | ||
| 44 | my @args = $arg->[1] eq '[]' ? @{$arg->[0]} : $arg; | ||
| 45 | $c->add($module); | ||
| 46 | if ($c->has_callback_for(use => $module)) { | ||
| 47 | $c->run_callback_for('use', $module, [["use", "KEYWORD"], [$module, "WORD"], @args, [";", ";"]]); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | elsif (ref $token && !ref $token->[0] && $token->[1] eq 'WORD') { | ||
| 53 | shift @$tokens if @$tokens && $tokens->[0][1] eq 'COMMA'; | ||
| 54 | shift @$tokens if @$tokens; | ||
| 55 | } | ||
| 56 | shift @$tokens if @$tokens && ref $tokens->[0] && $tokens->[0][1] eq 'COMMA'; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | |||
| 62 | __END__ |