From: Shawn M Moore Date: Mon, 14 Sep 2009 02:22:04 +0000 (+0900) Subject: Include method name in immutable methods (fixes #49680) X-Git-Tag: 0.93~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e347ce3fe9e40dc060e73e07f282729f4191c878;p=gitmo%2FClass-MOP.git Include method name in immutable methods (fixes #49680) --- diff --git a/lib/Class/MOP/Class/Immutable/Trait.pm b/lib/Class/MOP/Class/Immutable/Trait.pm index c3cd83b..2bf6074 100644 --- a/lib/Class/MOP/Class/Immutable/Trait.pm +++ b/lib/Class/MOP/Class/Immutable/Trait.pm @@ -28,15 +28,14 @@ sub superclasses { } sub _immutable_cannot_call { - Carp::confess "This method cannot be called on an immutable instance"; + my $name = shift; + Carp::confess "The '$name' method cannot be called on an immutable instance"; } -sub add_method { _immutable_cannot_call() } -sub alias_method { _immutable_cannot_call() } -sub remove_method { _immutable_cannot_call() } -sub add_attribute { _immutable_cannot_call() } -sub remove_attribute { _immutable_cannot_call() } -sub remove_package_symbol { _immutable_cannot_call() } +for my $name (qw/add_method alias_method remove_method add_attribute remove_attribute remove_package_symbol/) { + no strict 'refs'; + *{__PACKAGE__."::$name"} = sub { _immutable_cannot_call($name) }; +} sub class_precedence_list { my $orig = shift;