X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FFunction%2FParameters.pm;h=5734c7dcb791e786bebe4fa5dff990150c227c6f;hb=53c979f03d47fc61fcbbb9c922d755bd21fa139e;hp=a397246044f446edc18424ae2fd9dfea212b7f77;hpb=e1e43949a1c53e34bc045bd4ad9278c496dcc53f;p=p5sagit%2FFunction-Parameters.git diff --git a/lib/Function/Parameters.pm b/lib/Function/Parameters.pm index a397246..5734c7d 100644 --- a/lib/Function/Parameters.pm +++ b/lib/Function/Parameters.pm @@ -2,7 +2,6 @@ package Function::Parameters; use v5.14.0; -use strict; use warnings; use Carp qw(confess); @@ -156,6 +155,50 @@ sub unimport { } +our %metadata; + +sub _register_info { + my ( + $key, + $declarator, + $invocant, + $positional_required, + $positional_optional, + $named_required, + $named_optional, + $slurpy, + ) = @_; + + my $blob = pack '(Z*)*', + $declarator, + $invocant // '', + join(' ', @$positional_required), + join(' ', @$positional_optional), + join(' ', @$named_required), + join(' ', @$named_optional), + $slurpy // '', + ; + + $metadata{$key} = $blob; +} + +sub info { + my ($func) = @_; + my $key = _cv_root $func or return undef; + my $blob = $metadata{$key} or return undef; + my @info = unpack '(Z*)*', $blob; + require Function::Parameters::Info; + Function::Parameters::Info->new( + keyword => $info[0], + invocant => $info[1] || undef, + _positional_required => [split ' ', $info[2]], + _positional_optional => [split ' ', $info[3]], + _named_required => [split ' ', $info[4]], + _named_optional => [split ' ', $info[5]], + slurpy => $info[6] || undef, + ) +} + 'ok' __END__