From: Dave Rolsky Date: Sat, 24 Nov 2007 18:05:01 +0000 (+0000) Subject: Throw an error if the constructor receives a class attribute. X-Git-Tag: 0.01~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a124b299407924009b3fbe5b3a4745444b1bbd67;hp=6b059c7811f9345c89ea07c4ebb63ad6310d7932;p=gitmo%2FMooseX-ClassAttribute.git Throw an error if the constructor receives a class attribute. --- diff --git a/lib/MooseX/ClassAttribute.pm b/lib/MooseX/ClassAttribute.pm index 3b899c3..66087b4 100644 --- a/lib/MooseX/ClassAttribute.pm +++ b/lib/MooseX/ClassAttribute.pm @@ -11,17 +11,27 @@ use MooseX::ClassAttribute::Meta::Method::Accessor; extends 'Moose::Meta::Attribute'; + sub accessor_metaclass { 'MooseX::ClassAttribute::Meta::Method::Accessor' } # This is called when an object is constructed. sub initialize_instance_slot { + my ( $self, $meta_instance, $instance, $params ) = @_; + + return unless $self->has_init_arg(); + + my $init_arg = $self->init_arg(); + + confess "Cannot set a class attribute via the constructor ($init_arg)" + if exists $params->{$init_arg}; + return; } # This is the bit of magic that lets you specify the metaclass as -# 'ClassAttribute', rather than the full name, when creating an +# 'ClassAttribute' rather than the full name when creating an # attribute. package Moose::Meta::Attribute::Custom::ClassAttribute;