From: Dagfinn Ilmari Mannsåker Date: Tue, 19 Mar 2013 01:08:09 +0000 (+0000) Subject: Stricter checking of attributes in Catalyst::DispatchType::Chained X-Git-Tag: 5.90040~3^2~10^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=2e29aec2a437208ba0e76d4ee469fd06686abf12 Stricter checking of attributes in Catalyst::DispatchType::Chained 1) Only allow one of either :CaptureArgs or :Args 2) :CaptureArgs() argument must be numeric --- diff --git a/Changes b/Changes index 115949c..ae21dcc 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ # This file documents the revision history for Perl extension Catalyst. + ! Stricter checking of attributes in Catalyst::DispatchType::Chained: + 1) Only allow one of either :CaptureArgs or :Args + 2) :CaptureArgs() argument must be numeric - Add Devel::InnerPackage to dependencies, fixing tests on perl 5.17.11 as it's been removed from core. RT#84787 diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 44f890e..504c717 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -285,6 +285,32 @@ Calls register_path for every Path attribute for the given $action. =cut +sub _check_args_attr { + my ( $self, $action, $name ) = @_; + + return unless exists $action->attributes->{$name}; + + if (@{$action->attributes->{$name}} > 1) { + Catalyst::Exception->throw( + "Multiple $name attributes not supported registering " . $action->reverse() + ); + } + my $args = $action->attributes->{$name}->[0]; + if (defined($args) and not ( + Scalar::Util::looks_like_number($args) and + int($args) == $args + )) { + require Data::Dumper; + local $Data::Dumper::Terse = 1; + local $Data::Dumper::Indent = 0; + $args = Data::Dumper::Dumper($args); + Catalyst::Exception->throw( + "Invalid $name($args) for action " . $action->reverse() . + " (use '$name' or '$name()')" + ); + } +} + sub register { my ( $self, $c, $action ) = @_; @@ -329,21 +355,14 @@ sub register { $self->_actions->{'/'.$action->reverse} = $action; - if (exists $action->attributes->{Args}) { - my $args = $action->attributes->{Args}->[0]; - if (defined($args) and not ( - Scalar::Util::looks_like_number($args) and - int($args) == $args - )) { - require Data::Dumper; - local $Data::Dumper::Terse = 1; - local $Data::Dumper::Indent = 0; - $args = Data::Dumper::Dumper($args); - Catalyst::Exception->throw( - "Invalid Args($args) for action " . $action->reverse() . - " (use 'Args' or 'Args()')" - ); - } + foreach my $name (qw(Args CaptureArgs)) { + $self->_check_args_attr($action, $name); + } + + if (exists $action->attributes->{Args} and exists $action->attributes->{CaptureArgs}) { + Catalyst::Exception->throw( + "Combining Args and CaptureArgs not allowed registering " . $action->reverse() + ); } unless ($action->attributes->{CaptureArgs}) {