From: Jesse Luehrs Date: Sat, 21 Jul 2012 05:21:51 +0000 (-0500) Subject: improve the warning for unknown attribute parameters (mjd) X-Git-Tag: 2.0800~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoose.git;a=commitdiff_plain;h=a917d5ae83dc260c6a84fed0ffdc0d1b70c50266 improve the warning for unknown attribute parameters (mjd) --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 121fc9a..f21862d 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -67,7 +67,10 @@ sub has { Moose->throw_error('Usage: has \'name\' => ( key => value, ... )') if @_ % 2 == 1; - my %options = ( definition_context => Moose::Util::_caller_info(), @_ ); + my %context = Moose::Util::_caller_info; + $context{context} = 'has declaration'; + $context{type} = 'class'; + my %options = ( definition_context => \%context, @_ ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; $meta->add_attribute( $_, %options ) for @$attrs; } diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 56f3bc9..46a8412 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -94,7 +94,22 @@ sub new { if (@bad) { - Carp::cluck "Found unknown argument(s) passed to '$name' attribute constructor in '$class': @bad"; + my $s = @bad > 1 ? 's' : ''; + my $list = join "', '", @bad; + + my $package = $options{definition_context}{package}; + my $context = $options{definition_context}{context} + || 'attribute constructor'; + my $type = $options{definition_context}{type} || 'class'; + + my $location = ''; + if (defined($package)) { + $location = " in "; + $location .= "$type " if $type; + $location .= $package; + } + + Carp::cluck "Found unknown argument$s '$list' in the $context for '$name'$location"; } return $class->SUPER::new($name, %options); diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 48e40b7..3cc3467 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -39,7 +39,10 @@ sub has { my $meta = shift; my $name = shift; croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; - my %options = ( definition_context => Moose::Util::_caller_info(), @_ ); + my %context = Moose::Util::_caller_info; + $context{context} = 'has declaration'; + $context{type} = 'role'; + my %options = ( definition_context => \%context, @_ ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; $meta->add_attribute( $_, %options ) for @$attrs; } diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 09803d4..b03caa5 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -279,7 +279,7 @@ sub _caller_info { my $level = @_ ? ($_[0] + 1) : 2; my %info; @info{qw(package file line)} = caller($level); - return \%info; + return %info; } sub _create_alias {