Checking in changes prior to tagging of version 0.82.
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Accessor.pm
old mode 100755 (executable)
new mode 100644 (file)
index 69f5b30..6e4d402
@@ -1,6 +1,8 @@
 package Mouse::Meta::Method::Accessor;
 use Mouse::Util qw(:meta); # enables strict and warnings
 
+use constant _MOUSE_DEBUG => !!$ENV{MOUSE_DEBUG};
+
 sub _inline_slot{
     my(undef, $self_var, $attr_name) = @_;
     return sprintf '%s->{q{%s}}', $self_var, $attr_name;
@@ -33,7 +35,7 @@ sub _generate_accessor_any{
         }
         else{ # writer
             $accessor .= 
-                'if(@_ < 2){ Carp::confess("Not enough arguments for the writer of '.$name.'") }'.
+                'if(@_ < 2){ Carp::confess("Not enough arguments for the writer of $name") }'.
                 '{' . "\n";
         }
                 
@@ -69,13 +71,13 @@ sub _generate_accessor_any{
         $accessor .= "}\n";
     }
     elsif($type eq 'ro') {
-        $accessor .= 'Carp::confess("Cannot assign a value to a read-only accessor") if scalar(@_) >= 2;' . "\n";
+        $accessor .= 'Carp::confess("Cannot assign a value to a read-only accessor of $name") if scalar(@_) >= 2;' . "\n";
     }
     else{
         $class->throw_error("Unknown accessor type '$type'");
     }
 
-    if ($attribute->is_lazy) {
+    if ($attribute->is_lazy and $type ne 'wo') {
         my $value;
 
         if (defined $builder){
@@ -88,14 +90,13 @@ sub _generate_accessor_any{
             $value = '$default';
         }
 
-        $accessor .= "els" if $type eq 'rw' || $type eq 'wo';
+        $accessor .= "els" if $type eq 'rw';
         $accessor .= "if(!exists $slot){\n";
         if($should_coerce){
             $accessor .= "$slot = \$constraint->coerce($value)";
         }
         elsif(defined $constraint){
             $accessor .= "my \$tmp = $value;\n";
-
             $accessor .= "\$compiled_type_constraint->(\$tmp)";
             $accessor .= " || \$attribute->_throw_type_constraint_error(\$tmp, \$constraint);\n";
             $accessor .= "$slot = \$tmp;\n";
@@ -123,7 +124,7 @@ sub _generate_accessor_any{
 
     $accessor .= "return $slot;\n}\n";
 
-    #print $accessor, "\n";
+    warn $accessor if _MOUSE_DEBUG;
     my $code;
     my $e = do{
         local $@;
@@ -182,7 +183,7 @@ Mouse::Meta::Method::Accessor - A Mouse method generator for accessors
 
 =head1 VERSION
 
-This document describes Mouse version 0.52
+This document describes Mouse version 0.82
 
 =head1 SEE ALSO