X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FFunction%2FParameters.pm;h=f0a9f7bdb004d3028cf8bb0e5a0b45cc55b30497;hb=b72eb6ee4e3b6553e62365de04c6271ac8e180e5;hp=dc96207d4c62c9ec6b74825546945a449ae5fe27;hpb=273c6544dcb5773b64d135f6671b999dce09ec45;p=p5sagit%2FFunction-Parameters.git diff --git a/lib/Function/Parameters.pm b/lib/Function/Parameters.pm index dc96207..f0a9f7b 100644 --- a/lib/Function/Parameters.pm +++ b/lib/Function/Parameters.pm @@ -12,7 +12,6 @@ BEGIN { } use Carp qw(confess); -use bytes (); sub _assert_valid_identifier { my ($name, $with_dollar) = @_; @@ -21,6 +20,12 @@ sub _assert_valid_identifier { or confess qq{"$name" doesn't look like a valid identifier}; } +sub _assert_valid_attributes { + my ($attrs) = @_; + $attrs =~ /^\s*:\s*[^\W\d]\w*\s*(?:(?:\s|:\s*)[^\W\d]\w*\s*)*(?:\(|\z)/ + or confess qq{"$attrs" doesn't look like valid attributes}; +} + my @bare_arms = qw(function method); my %type_map = ( function => { name => 'optional' }, @@ -30,7 +35,10 @@ my %type_map = ( sub import { my $class = shift; - @_ or @_ = ('fun', 'method'); + @_ or @_ = { + fun => 'function', + method => 'method', + }; if (@_ == 1 && ref($_[0]) eq 'HASH') { @_ = map [$_, $_[0]{$_}], keys %{$_[0]} or return; @@ -55,11 +63,9 @@ sub import { $type->{name} ||= 'optional'; $type->{name} =~ /^(?:optional|required|prohibited)\z/ or confess qq["$type->{name}" doesn't look like a valid name attribute (one of optional, required, prohibited)]; - if ($type->{shift}) { - _assert_valid_identifier $type->{shift}, 1; - bytes::length($type->{shift}) < SHIFT_NAME_LIMIT - or confess qq["$type->{shift}" is longer than I can handle]; - } + + $type->{shift} and _assert_valid_identifier $type->{shift}, 1; + $type->{attrs} and _assert_valid_attributes $type->{attrs}; $spec{$name} = $type; } @@ -68,6 +74,7 @@ sub import { my $type = $spec{$kw}; $^H{HINTK_SHIFT_ . $kw} = $type->{shift} || ''; + $^H{HINTK_ATTRS_ . $kw} = $type->{attrs} || ''; $^H{HINTK_NAME_ . $kw} = $type->{name} eq 'prohibited' ? FLAG_NAME_PROHIBITED : $type->{name} eq 'required' ? FLAG_NAME_REQUIRED :