From: Hans Dieter Pearcey Date: Wed, 24 Jun 2009 20:27:01 +0000 (-0400) Subject: warn instead of dying X-Git-Tag: 0.84~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86cf196bf3e70f3dfebe7a61e39fe6b2ff8a7a0f;p=gitmo%2FMoose.git warn instead of dying --- diff --git a/Changes b/Changes index 1d1f1df..03d33a7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. +0.XX + * Moose::Meta::Attribute + - When adding an attribute to a metaclass, if the attribute has no + methods associated with, it will give a deprecation warning. (hdp) + 0.83 Tue, Jun 23, 2009 * Moose::Meta::Class - Fix _construct_instance not setting the special __MOP__ object diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index df5cdfb..bc00a08 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -537,6 +537,18 @@ sub install_accessors { my $self = shift; $self->SUPER::install_accessors(@_); $self->install_delegation if $self->has_handles; + unless ( + # XXX handles should be in associated_methods + $self->has_handles + || @{ $self->associated_methods } + || ($self->_is_metadata || '') eq 'bare' + ) { + Carp::cluck( + 'Attribute (' . $self->name . ') has no associated methods' + . ' (did you mean to provide an "is" argument?)' + . "\n" + ) + } return; } diff --git a/t/020_attributes/026_attribute_without_any_methods.t b/t/020_attributes/026_attribute_without_any_methods.t new file mode 100644 index 0000000..5f0ba66 --- /dev/null +++ b/t/020_attributes/026_attribute_without_any_methods.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; + +use Moose (); +use Moose::Meta::Class; + +my $meta = Moose::Meta::Class->create_anon_class; + +my $warn; +$SIG{__WARN__} = sub { $warn = "@_" }; + +$meta->add_attribute('foo'); +like $warn, qr/Attribute \(foo\) has no associated methods/, + 'correct error message'; + +$warn = ''; +$meta->add_attribute('bar', is => 'bare'); +is $warn, '', 'add attribute with no methods and is => "bare"';