fixed
[gitmo/Class-MOP.git] / t / 020_attribute.t
index 33cafdd..3ec9921 100644 (file)
@@ -3,7 +3,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 73;
+use Scalar::Util 'reftype', 'blessed';
+
+use Test::More tests => 97;
 use Test::Exception;
 
 BEGIN {
@@ -33,6 +35,20 @@ BEGIN {
     } '... attached a class successfully';
 
     is($attr->associated_class, $class, '... the class was associated correctly');
+    
+    ok(!$attr->get_read_method, '... $attr does not have an read method');
+    ok(!$attr->get_write_method, '... $attr does not have an write method');    
+    
+    {
+        my $reader = $attr->get_read_method_ref;
+        my $writer = $attr->get_write_method_ref;        
+        
+        ok(!blessed($reader), '... it is a plain old sub');
+        ok(!blessed($writer), '... it is a plain old sub');        
+        
+        is(reftype($reader), 'CODE', '... it is a plain old sub');
+        is(reftype($writer), 'CODE', '... it is a plain old sub');                
+    }
 
     my $attr_clone = $attr->clone();
     isa_ok($attr_clone, 'Class::MOP::Attribute');
@@ -63,6 +79,20 @@ BEGIN {
     ok(!$attr->has_accessor, '... $attr does not have an accessor');
     ok(!$attr->has_reader, '... $attr does not have an reader');
     ok(!$attr->has_writer, '... $attr does not have an writer');
+    
+    ok(!$attr->get_read_method, '... $attr does not have an read method');
+    ok(!$attr->get_write_method, '... $attr does not have an write method');    
+    
+    {
+        my $reader = $attr->get_read_method_ref;
+        my $writer = $attr->get_write_method_ref;        
+        
+        ok(!blessed($reader), '... it is a plain old sub');
+        ok(!blessed($writer), '... it is a plain old sub');        
+        
+        is(reftype($reader), 'CODE', '... it is a plain old sub');
+        is(reftype($writer), 'CODE', '... it is a plain old sub');                
+    }    
 
     my $attr_clone = $attr->clone();
     isa_ok($attr_clone, 'Class::MOP::Attribute');
@@ -95,6 +125,20 @@ BEGIN {
 
     ok(!$attr->has_reader, '... $attr does not have an reader');
     ok(!$attr->has_writer, '... $attr does not have an writer');
+    
+    is($attr->get_read_method,  'foo', '... $attr does not have an read method');
+    is($attr->get_write_method, 'foo', '... $attr does not have an write method');    
+    
+    {
+        my $reader = $attr->get_read_method_ref;
+        my $writer = $attr->get_write_method_ref;        
+        
+        ok(!blessed($reader), '... it is not a plain old sub');
+        ok(!blessed($writer), '... it is not a plain old sub');         
+        
+        is(reftype($reader), 'CODE', '... it is a plain old sub');
+        is(reftype($writer), 'CODE', '... it is a plain old sub');                
+    }    
 
     my $attr_clone = $attr->clone();
     isa_ok($attr_clone, 'Class::MOP::Attribute');
@@ -125,6 +169,20 @@ BEGIN {
     is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
 
     ok(!$attr->has_accessor, '... $attr does not have an accessor');
+    
+    is($attr->get_read_method,  'get_foo', '... $attr does not have an read method');
+    is($attr->get_write_method, 'set_foo', '... $attr does not have an write method');    
+    
+    {
+        my $reader = $attr->get_read_method_ref;
+        my $writer = $attr->get_write_method_ref;        
+        
+        ok(!blessed($reader), '... it is not a plain old sub');
+        ok(!blessed($writer), '... it is not a plain old sub');           
+        
+        is(reftype($reader), 'CODE', '... it is a plain old sub');
+        is(reftype($writer), 'CODE', '... it is a plain old sub');                
+    }    
 
     my $attr_clone = $attr->clone();
     isa_ok($attr_clone, 'Class::MOP::Attribute');