File: 014_attribute_introspection.t

package info (click to toggle)
libclass-mop-perl 0.36-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 552 kB
  • ctags: 209
  • sloc: perl: 6,157; makefile: 46
file content (85 lines) | stat: -rw-r--r-- 2,174 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 49;
use Test::Exception;

BEGIN {
    use_ok('Class::MOP');        
}

{
    my $attr = Class::MOP::Attribute->new('$test');
    is($attr->meta, Class::MOP::Attribute->meta, '... instance and class both lead to the same meta');
}

{
    my $meta = Class::MOP::Attribute->meta();
    isa_ok($meta, 'Class::MOP::Class');
    
    my @methods = qw(
        meta
        new clone
        
        initialize_instance_slot
        
        name
        has_accessor  accessor
        has_writer    writer
        has_reader    reader
        has_predicate predicate
        has_clearer   clearer
        has_init_arg  init_arg
        has_default   default    is_default_a_coderef
        
        slots
        get_value
        set_value
        has_value
        clear_value
        
        associated_class
        attach_to_class detach_from_class 
        
        accessor_metaclass
        
        associated_methods
        associate_method
        
        process_accessors
        install_accessors
        remove_accessors
        );
        
    is_deeply(
        [ sort $meta->get_method_list ],
        [ sort @methods ],
        '... our method list matches');        
    
    foreach my $method_name (@methods) {
        ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
    }
    
    my @attributes = qw(
        name accessor reader writer predicate clearer
        init_arg default associated_class associated_methods
        );

    is_deeply(
        [ sort $meta->get_attribute_list ],
        [ sort @attributes ],
        '... our attribute list matches');
    
    foreach my $attribute_name (@attributes) {
        ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');        
    }
    
    # We could add some tests here to make sure that 
    # the attribute have the appropriate 
    # accessor/reader/writer/predicate combinations, 
    # but that is getting a little excessive so I  
    # wont worry about it for now. Maybe if I get 
    # bored I will do it.
}