| 1 | # ABSTRACT: Declarations of the signatures of Function::Parameters | ||||||||||
| 2 | # PODNAME: Pod::Coverage::More::Declared::FunctionParameters | ||||||||||
| 3 | |||||||||||
| 4 | package Pod::Coverage::More::Declared::FunctionParameters 0.001; | ||||||||||
| 5 | |||||||||||
| 6 | 9 | ▶ | use 5.036; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 9 | ▶ | use warnings FATAL => q{all}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 9 | ▶ | use Package::Stash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | # Whether L<Function::Parameters> is loaded, so that it can have declared subs of C<package>. | ||||||||||
| 13 | # @param package Str the name of the package | ||||||||||
| 14 | # @returns Bool | ||||||||||
| 15 | # @example next if !Pod::Coverage::More::Declared::FunctionParameters->applies_to('Some::Class'); | ||||||||||
| 16 | 37 | ▶ | sub applies_to { | ||||||||
|
Subroutine
applies_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | 37 | ▶ | return $INC{'Function/Parameters.pm'} ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | # The declarations of the subs of C<package> that C<names> lists, as L<Pod::Coverage::More::Declared> describes them. | ||||||||||
| 21 | # @param package Str the name of the package | ||||||||||
| 22 | # @param names ArrayRef[Str] the names of the subs | ||||||||||
| 23 | # @returns HashRef from the name of each declared sub to its declaration | ||||||||||
| 24 | # @example my $declared = Pod::Coverage::More::Declared::FunctionParameters->declarations( 'Some::Class', ['new'] ); | ||||||||||
| 25 | 5 | ▶ | sub declarations { | ||||||||
|
Subroutine
declarations: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||
| 26 | 5 | my ( $class, $package, $names ) = @_; | |||||||||
| 27 | 5 | my $stash = Package::Stash->new($package); | |||||||||
| 28 | 5 | my %declared; | |||||||||
| 29 | 5 | foreach my $name (@$names) { | |||||||||
| 30 | 11 | ▶ | my $info = Function::Parameters::info( $stash->get_symbol("&$name") ) or next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 2 | my $index = 0; | |||||||||
| 32 | 2 | my @params; | |||||||||
| 33 | 2 | my @positional = ( [ [ $info->invocants ], { invocant => 1 } ], [ [ $info->positional_required ], {} ], [ [ $info->positional_optional ], { optional => 1 } ] ); | |||||||||
| 34 | 2 | foreach my $group (@positional) { | |||||||||
| 35 | 6 | my ( $list, $extra ) = @$group; | |||||||||
| 36 | 6 | foreach my $param (@$list) { | |||||||||
| 37 | 3 | push @params, _param( $param, index => $index++, %$extra ); | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | 2 | my @named = ( [ [ $info->named_required ], {} ], [ [ $info->named_optional ], { optional => 1 } ] ); | |||||||||
| 41 | 2 | foreach my $group (@named) { | |||||||||
| 42 | 4 | my ( $list, $extra ) = @$group; | |||||||||
| 43 | 4 | foreach my $param (@$list) { | |||||||||
| 44 | 2 | push @params, _param( $param, named => _key($param), %$extra ); | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | 2 | ▶ | push @params, _param( $info->slurpy, index => $index, optional => 1 ) if $info->slurpy; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 2 | ▶ | $declared{$name} = { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | via => 'Function::Parameters', | ||||||||||
| 50 | role => $info->keyword eq 'method' ? 'method' : 'function', | ||||||||||
| 51 | params => \@params, | ||||||||||
| 52 | returns => [], | ||||||||||
| 53 | }; | ||||||||||
| 54 | } | ||||||||||
| 55 | 5 | return \%declared; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 5 | ▶ | sub _param { | ||||||||
|
Subroutine
_param: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 5 | my ( $param, %where ) = @_; | |||||||||
| 60 | 5 | return { name => $param->name, type => $param->type, optional => 0, invocant => 0, %where }; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | # The key of a named parameter is its name without the sigil. | ||||||||||
| 64 | 2 | ▶ | sub _key { | ||||||||
|
Subroutine
_key: called CC=1 SCAR=0.0
| |||||||||||
| 65 | 2 | my ($param) = @_; | |||||||||
| 66 | 2 | return substr( $param->name, 1 ); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 9 | 1; | |||||||||
| 70 | |||||||||||
| 71 | __END__ | ||||||||||