File: 103_Perl6Attribute_test.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 (42 lines) | stat: -rw-r--r-- 842 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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 10;
use File::Spec;

BEGIN { 
    use_ok('Class::MOP');    
    require_ok(File::Spec->catdir('examples', 'Perl6Attribute.pod'));
}

{
    package Foo;
    
    use metaclass;
    
    Foo->meta->add_attribute(Perl6Attribute->new('$.foo'));
    Foo->meta->add_attribute(Perl6Attribute->new('@.bar'));    
    Foo->meta->add_attribute(Perl6Attribute->new('%.baz'));    
    
    sub new  {
        my $class = shift;
        $class->meta->new_object(@_);
    }      
}

my $foo = Foo->new();
isa_ok($foo, 'Foo');

can_ok($foo, 'foo');
can_ok($foo, 'bar');
can_ok($foo, 'baz');

is($foo->foo, undef, '... Foo.foo == undef');

$foo->foo(42);
is($foo->foo, 42, '... Foo.foo == 42');

is_deeply($foo->bar, [], '... Foo.bar == []');
is_deeply($foo->baz, {}, '... Foo.baz == {}');