From: Guillermo Roditi Date: Mon, 29 Dec 2008 17:57:58 +0000 (+0000) Subject: immutable error X-Git-Tag: 0.00701~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Emulate-Class-Accessor-Fast.git;a=commitdiff_plain;h=b3050bf25950c0e381193e9d5bffb0d41c81986b immutable error --- diff --git a/Changes b/Changes index aa6e458..c1b802e 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ +0.00800 + - Better errors when trying to modify an immutable class 0.00700 Dec 29, 2008 - Creating a new accessor with the same name as an old one would result in a new attribute with no reader/writer/accessor. Reported by t0m diff --git a/lib/MooseX/Emulate/Class/Accessor/Fast.pm b/lib/MooseX/Emulate/Class/Accessor/Fast.pm index c0c1b6a..562fbbd 100644 --- a/lib/MooseX/Emulate/Class/Accessor/Fast.pm +++ b/lib/MooseX/Emulate/Class/Accessor/Fast.pm @@ -102,6 +102,11 @@ will be passed. Please see L for more information. sub mk_accessors{ my $self = shift; my $meta = $locate_metaclass->($self); + my $class = $meta->name; + confess("You are trying to modify ${class}, which has been made immutable, this is ". + "not supported. Try subclassing ${class}, rather than monkeypatching it") + if $meta->is_immutable; + for my $attr_name (@_){ $meta->remove_attribute($attr_name) if $meta->find_attribute_by_name($attr_name); @@ -135,6 +140,10 @@ Create read-only accessors. sub mk_ro_accessors{ my $self = shift; my $meta = $locate_metaclass->($self); + my $class = $meta->name; + confess("You are trying to modify ${class}, which has been made immutable, this is ". + "not supported. Try subclassing ${class}, rather than monkeypatching it") + if $meta->is_immutable; for my $attr_name (@_){ $meta->remove_attribute($attr_name) if $meta->find_attribute_by_name($attr_name); @@ -158,6 +167,10 @@ Create write-only accessors. sub mk_wo_accessors{ my $self = shift; my $meta = $locate_metaclass->($self); + my $class = $meta->name; + confess("You are trying to modify ${class}, which has been made immutable, this is ". + "not supported. Try subclassing ${class}, rather than monkeypatching it") + if $meta->is_immutable; for my $attr_name (@_){ $meta->remove_attribute($attr_name) if $meta->find_attribute_by_name($attr_name);