From: Shawn M Moore Date: Mon, 9 Jun 2008 23:42:53 +0000 (+0000) Subject: Use "undef" and avoid uninitialized warnings when the value we're type checking is... X-Git-Tag: 0.04~89 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f2b47800eef4a10a8a914b4663ae9af699c7f72;hp=f5fbe3cced480252b924d64511d69b325d4ddebd;p=gitmo%2FMouse.git Use "undef" and avoid uninitialized warnings when the value we're type checking is undef --- diff --git a/lib/Mouse/Attribute.pm b/lib/Mouse/Attribute.pm index 36c907a..4bb1856 100644 --- a/lib/Mouse/Attribute.pm +++ b/lib/Mouse/Attribute.pm @@ -54,7 +54,10 @@ sub generate_accessor { local $_ = $_[0];'; if ($constraint) { - $accessor .= 'Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $_") unless $constraint->();' + $accessor .= 'do { + my $display = defined($_) ? $_ : "undef"; + Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display") unless $constraint->(); + };' } $accessor .= '$self->{$key} = $_;'; @@ -203,6 +206,7 @@ sub verify_type_constraint { return 1 if $constraint->($_); my $name = $self->name; + local $_ = "undef" unless defined($_); Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $_"); }