From: Guillermo Roditi Date: Tue, 13 Nov 2007 20:46:45 +0000 (+0000) Subject: error messgae fixes + new test X-Git-Tag: 0_29~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0b26305c71e911cc79c587a8a7cda8f697c7d3ff;p=gitmo%2FMoose.git error messgae fixes + new test --- diff --git a/Changes b/Changes index 549a15e..c0dce31 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,16 @@ Revision history for Perl extension Moose +0.29 + * Moose::Meta::Attribute + -Fix error message on missing builder method (groditi) + + * Moose::Meta::Method::Accessor + -Fix error message on missing builder method (groditi) + + * t/ + -Add test to check for the correct error message when + builder method is missing (groditi) + 0.28 Tues. Nov. 13, 2007 - 0.27 packaged incorrectly (groditi) diff --git a/lib/Moose.pm b/lib/Moose.pm index b38e30a..aa4ef94 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,7 +4,7 @@ package Moose; use strict; use warnings; -our $VERSION = '0.28'; +our $VERSION = '0.29'; our $AUTHORITY = 'cpan:STEVAN'; use Scalar::Util 'blessed', 'reftype'; @@ -361,8 +361,8 @@ instead of switching to Ruby, I wrote Moose :) =head2 Moose Extensions The L namespace is the official place to find Moose extensions. -There are a number of these modules out on CPAN right now the best way to -find them is to search for MooseX:: on search.cpan.org. +There are a number of these modules out on CPAN right now the best way to +find them is to search for MooseX:: on search.cpan.org. =head1 BUILDING CLASSES WITH MOOSE diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 9be1657..bcb095c 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -8,7 +8,7 @@ use Scalar::Util 'blessed', 'weaken', 'reftype'; use Carp 'confess'; use overload (); -our $VERSION = '0.13'; +our $VERSION = '0.14'; our $AUTHORITY = 'cpan:STEVAN'; use Moose::Meta::Method::Accessor; @@ -220,12 +220,11 @@ sub initialize_instance_slot { $val = $self->default($instance); $value_is_set = 1; } elsif ($self->has_builder) { - my $builder = $self->builder; - if($builder = $instance->can($builder)){ + if(my $builder = $instance->can($self->builder)){ $val = $instance->$builder; $value_is_set = 1; } else { - confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'"); + confess(blessed($instance)." does not support builder method '".$self->builder."' for attribute '" . $self->name . "'"); } } } @@ -313,11 +312,10 @@ sub get_value { $self->set_value($instance, $default); } if ( $self->has_builder ){ - my $builder = $self->builder; - if($builder = $instance->can($builder)){ + if(my $builder = $instance->can($self->builder)){ $self->set_value($instance, $instance->$builder); } else { - confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'"); + confess(blessed($instance)." does not support builder method '".$self->builder."' for attribute '" . $self->name . "'"); } } else { $self->set_value($instance, undef); diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 6b387da..a382999 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -6,7 +6,7 @@ use warnings; use Carp 'confess'; -our $VERSION = '0.06'; +our $VERSION = '0.07'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', @@ -160,11 +160,10 @@ sub _inline_check_lazy { ' my $default; '. ' $default = $attr->default(' . $inv . ') if $attr->has_default;' . ' if ( $attr->has_builder ) { '. - ' my $builder = $attr->builder;'. - ' if($builder = '.$inv.'->can($builder)){ '. + ' if(my $builder = '.$inv.'->can($attr->builder)){ '. ' $default = '.$inv.'->$builder; '. ' } else { '. - ' confess(blessed('.$inv.')." does not support builder method \'$builder\' for attribute \'" . $attr->name . "\'");'. + ' confess(Scalar::Util::blessed('.$inv.')." does not support builder method \'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. ' }'. ' }'. ($attr->should_coerce @@ -185,11 +184,10 @@ sub _inline_check_lazy { return 'unless ( ' . $slot_exists . ') {' . ' if ($attr->has_default) { ' . $slot_access . ' = $attr->default(' . $inv . '); }' . ' elsif ($attr->has_builder) { '. - ' my $builder = $attr->builder; ' . - ' if($builder = '.$inv.'->can($builder)){ '. + ' if(my $builder = '.$inv.'->can($attr->builder)){ '. ' ' . $slot_access . ' = ' . $inv . '->$builder; '. ' } else { '. - ' confess(blessed('.$inv.')." does not support builder method \'$builder\' for attribute \'" . $attr->name . "\'");'. + ' confess(Scalar::Util::blessed('.$inv.')." does not support builder method \'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. ' }'. ' } else { ' .$slot_access . ' = undef; } '. '}'; diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index d7be475..2d7e1d0 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 41; use Test::Exception; BEGIN { @@ -171,6 +171,7 @@ BEGIN { has 'foo' => ( lazy_build => 1, is => 'ro'); has '_foo' => ( lazy_build => 1, is => 'ro'); + has 'fool' => ( lazy_build => 1, is => 'ro'); sub _build_foo { return "works" }; sub _build__foo { return "works too" }; } @@ -210,6 +211,9 @@ BEGIN { ok(!$instance->_has_foo, "noo _foo value yet"); is($instance->foo, 'works', "foo builder works"); is($instance->_foo, 'works too', "foo builder works too"); + throws_ok { $instance->fool } + qr/Test::LazyBuild::Attribute does not support builder method \'_build_fool\' for attribute \'fool\'/, + "Correct error when a builder method is not present"; }