Tweaks for coercions
[gitmo/Mouse.git] / Moose-t-failing / 020_attributes / 021_method_generation_rules.t
CommitLineData
4060c871 1#!/usr/bin/perl
c47cf415 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4060c871 5
6use strict;
7use warnings;
8
c47cf415 9use Test::More;
10$TODO = q{Mouse is not yet completed};
4060c871 11use Test::Exception;
12
13
4060c871 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
23sub 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
31my $obj;
32my $class;
33
34$class = make_class('rw', 'writer', 'Test::Class::WriterRW');
35ok($class, "Can define attr with rw + writer");
36
37$obj = $class->new();
38
39can_ok($obj, qw/foo _foo/);
40lives_ok {$obj->_foo(1)} "$class->_foo is writer";
41is($obj->foo(), 1, "$class->foo is reader");
42dies_ok {$obj->foo(2)} "$class->foo is not writer"; # this should fail
43ok(!defined $obj->_foo(), "$class->_foo is not reader");
44
45$class = make_class('ro', 'writer', 'Test::Class::WriterRO');
46ok($class, "Can define attr with ro + writer");
47
48$obj = $class->new();
49
50can_ok($obj, qw/foo _foo/);
51lives_ok {$obj->_foo(1)} "$class->_foo is writer";
52is($obj->foo(), 1, "$class->foo is reader");
53dies_ok {$obj->foo(1)} "$class->foo is not writer";
54isnt($obj->_foo(), 1, "$class->_foo is not reader");
55
56$class = make_class('rw', 'accessor', 'Test::Class::AccessorRW');
57ok($class, "Can define attr with rw + accessor");
58
59$obj = $class->new();
60
61can_ok($obj, qw/_foo/);
62lives_ok {$obj->_foo(1)} "$class->_foo is writer";
63is($obj->_foo(), 1, "$class->foo is reader");
64
65dies_ok { make_class('ro', 'accessor', "Test::Class::AccessorRO"); } "Cant define attr with ro + accessor";
66
c47cf415 67done_testing;