« blib/lib/Perl/PrereqScanner/NotQuiteLite/Parser/Superclass.pm
↑ Summary
blib/lib/Perl/PrereqScanner/NotQuiteLite/Parser/Catalyst.pm »
| 1 | package Perl::PrereqScanner::NotQuiteLite::Parser::SyntaxCollector; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Perl::PrereqScanner::NotQuiteLite::Util; | ||
| 6 | |||
| 7 | sub register { return { | ||
| 8 | use => { | ||
| 9 | 'Syntax::Collector' => 'parse_syntax_collector_args', | ||
| 10 | }, | ||
| 11 | }} | ||
| 12 | |||
| 13 | sub parse_syntax_collector_args { | ||
| 14 | my ($class, $c, $used_module, $raw_tokens) = @_; | ||
| 15 | |||
| 16 | my $tokens = convert_string_token_list($raw_tokens); | ||
| 17 | |||
| 18 | if (is_version($tokens->[0])) { | ||
| 19 | $c->add($used_module => shift @$tokens); | ||
| 20 | } | ||
| 21 | |||
| 22 | my $spec; | ||
| 23 | if (!(@$tokens % 2)) { | ||
| 24 | while(my ($key, $value) = splice @$tokens, 0, 2) { | ||
| 25 | my $keystr = ref $key ? $key->[0] : $key; | ||
| 26 | if ($keystr eq '-collect') { | ||
| 27 | $spec = $value; | ||
| 28 | last; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } else { | ||
| 32 | $spec = $tokens->[0]; | ||
| 33 | } | ||
| 34 | if (ref $spec) { | ||
| 35 | $spec = $spec->[0]; | ||
| 36 | } | ||
| 37 | return unless $spec; | ||
| 38 | |||
| 39 | my @features = | ||
| 40 | map { | ||
| 41 | m{^ | ||
| 42 | (use|no) \s+ # "use" or "no" | ||
| 43 | (\S+) \s+ # module name | ||
| 44 | ([\d\._v]+) # module version | ||
| 45 | (?: # everything else | ||
| 46 | \s* (.+) | ||
| 47 | )? # ... perhaps | ||
| 48 | [;] \s* # semicolon | ||
| 49 | $}x | ||
| 50 | ? [$1, $2, $3, [ defined($4) ? eval "($4)" : ()] ] | ||
| 51 | : die("Line q{$_} doesn't conform to 'use MODULE VERSION [ARGS];'") | ||
| 52 | } | ||
| 53 | grep { ! m/^#/ } # not a comment | ||
| 54 | grep { m/[A-Z0-9]/i } # at least one alphanum | ||
| 55 | map { s/(^\s+)|(\s+$)//; $_ } # trim | ||
| 56 | map { split /(\r?\n|\r)/ } # split lines | ||
| 57 | $spec; | ||
| 58 | |||
| 59 | for my $feature (@features) { | ||
| 60 | $c->add($feature->[1], $feature->[2]); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | 1; | ||
| 65 | |||
| 66 | __END__ |