b275d1ce26815c85de4a58cdae3aaabac227cf00
[gitmo/Mouse.git] / t-failing / 020_attributes / 021_method_generation_rules.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10 $TODO = q{Mouse is not yet completed};
11 use Test::Exception;
12
13
14 =pod
15
16     is => rw, writer => _foo    # turns into (reader => foo, writer => _foo)
17     is => ro, writer => _foo    # turns into (reader => foo, writer => _foo) as before
18     is => rw, accessor => _foo  # turns into (accessor => _foo)
19     is => ro, accessor => _foo  # error, accesor is rw
20
21 =cut
22
23 sub make_class {
24     my ($is, $attr, $class) = @_;
25
26     eval "package $class; use Mouse; has 'foo' => ( is => '$is', $attr => '_foo' );";
27
28     return $@ ? die $@ : $class;
29 }
30
31 my $obj;
32 my $class;
33
34 $class = make_class('rw', 'writer', 'Test::Class::WriterRW');
35 ok($class, "Can define attr with rw + writer");
36
37 $obj = $class->new();
38
39 can_ok($obj, qw/foo _foo/);
40 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
41 is($obj->foo(), 1, "$class->foo is reader");
42 dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail
43 ok(!defined $obj->_foo(), "$class->_foo is not reader");
44
45 $class = make_class('ro', 'writer', 'Test::Class::WriterRO');
46 ok($class, "Can define attr with ro + writer");
47
48 $obj = $class->new();
49
50 can_ok($obj, qw/foo _foo/);
51 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
52 is($obj->foo(), 1, "$class->foo is reader");
53 dies_ok {$obj->foo(1)} "$class->foo is not writer";
54 isnt($obj->_foo(), 1, "$class->_foo is not reader");
55
56 $class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
57 ok($class, "Can define attr with rw + accessor");
58
59 $obj = $class->new();
60
61 can_ok($obj, qw/_foo/);
62 lives_ok {$obj->_foo(1)} "$class->_foo is writer";
63 is($obj->_foo(), 1, "$class->foo is reader");
64
65 dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";
66
67 done_testing;