| 1 | package Sub::Meta::Finder::FunctionParameters; | ||
| 2 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 0 | ▶ | use Function::Parameters; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | sub find_materials { | ||
| 8 | my $sub = shift; | ||
| 9 | |||
| 10 | my $info = Function::Parameters::info($sub); | ||
| 11 | return unless $info; | ||
| 12 | |||
| 13 | my $keyword = $info->keyword; | ||
| 14 | my $nshift = $info->nshift; | ||
| 15 | |||
| 16 | my @args; | ||
| 17 | for ($info->positional_required) { | ||
| 18 | push @args => { | ||
| 19 | type => $_->type, | ||
| 20 | name => $_->name, | ||
| 21 | positional => 1, | ||
| 22 | required => 1, | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | for ($info->positional_optional) { | ||
| 27 | push @args => { | ||
| 28 | type => $_->type, | ||
| 29 | name => $_->name, | ||
| 30 | positional => 1, | ||
| 31 | required => 0, | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | for ($info->named_required) { | ||
| 36 | push @args => { | ||
| 37 | type => $_->type, | ||
| 38 | name => $_->name, | ||
| 39 | named => 1, | ||
| 40 | required => 1, | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | for ($info->named_optional) { | ||
| 45 | push @args => { | ||
| 46 | type => $_->type, | ||
| 47 | name => $_->name, | ||
| 48 | named => 1, | ||
| 49 | required => 0, | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | my $invocant = $info->invocant ? +{ | ||
| 54 | name => $info->invocant->name, | ||
| 55 | $info->invocant->type ? ( type => $info->invocant->type ) : (), | ||
| 56 | } : undef; | ||
| 57 | |||
| 58 | my $slurpy = $info->slurpy ? +{ | ||
| 59 | name => $info->slurpy->name, | ||
| 60 | $info->slurpy->type ? ( type => $info->slurpy->type ) : (), | ||
| 61 | } : undef; | ||
| 62 | |||
| 63 | return +{ | ||
| 64 | sub => $sub, | ||
| 65 | is_method => $keyword eq 'method' ? !!1 : !!0, | ||
| 66 | parameters => { | ||
| 67 | args => \@args, | ||
| 68 | nshift => $nshift, | ||
| 69 | $invocant ? ( invocant => $invocant ) : (), | ||
| 70 | $slurpy ? ( slurpy => $slurpy ) : (), | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; | ||
| 76 | __END__ | ||