rewrite attribute validation regex to check everything
[p5sagit/Function-Parameters.git] / lib / Function / Parameters.pm
index dc6a79f..82d7486 100644 (file)
@@ -8,7 +8,9 @@ use Carp qw(confess);
 
 use XSLoader;
 BEGIN {
-       our $VERSION = '1.0003';
+       our $VERSION = '1.0103_01';
+       our $XS_VERSION = $VERSION;
+       $VERSION = eval $VERSION;
        XSLoader::load;
 }
 
@@ -21,8 +23,36 @@ sub _assert_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};
+       $attrs =~ m{
+               ^ \s*+
+               : \s*+
+               (?&ident) (?! [^\s:(] ) (?&param)?+ \s*+
+               (?:
+                       (?: : \s*+ )?
+                       (?&ident) (?! [^\s:(] ) (?&param)?+ \s*+
+               )*+
+               \z
+
+               (?(DEFINE)
+                       (?<ident>
+                               [^\W\d]
+                               \w*+
+                       )
+                       (?<param>
+                               \(
+                               [^()\\]*+
+                               (?:
+                                       (?:
+                                               \\ .
+                                       |
+                                               (?&param)
+                                       )
+                                       [^()\\]*+
+                               )*+
+                               \)
+                       )
+               )
+       }sx or confess qq{"$attrs" doesn't look like valid attributes};
 }
 
 my @bare_arms = qw(function method);
@@ -645,7 +675,9 @@ function, and returns either C<undef> (if it knows nothing about the function)
 or a L<Function::Parameters::Info> object describing the parameter list.
 
 Note: This feature is implemented using L<Moo>, so you'll need to have L<Moo>
-installed if you want to call C<Function::Parameters::info>.
+installed if you want to call C<Function::Parameters::info> (alternatively, if
+L<Moose> is already loaded by the time C<Function::Parameters::info> is first
+called, it will use that instead).
 
 See L<Function::Parameters::Info> for examples.
 
@@ -760,7 +792,7 @@ Lukas Mai, C<< <l.mai at web.de> >>
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2010, 2011, 2012 Lukas Mai.
+Copyright 2010-2013 Lukas Mai.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of either: the GNU General Public License as published