Fix issue reported by ArjenL in #moose
[gitmo/Mouse.git] / t / 033-readwrite.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More tests => 4;
5 use Test::Exception;
6
7 do {
8     package Class;
9     use Mouse;
10
11     # We want this attr to have a reader and writer with unconventional names,
12     # and not the default rw_attr method. -- rjbs, 2008-12-04
13     has 'rw_attr' => (
14         is     => 'rw',
15         reader => 'read_attr',
16         writer => 'write_attr',
17     );
18 };
19
20 my $object = Class->new;
21
22 TODO: {
23   local $TODO = 'requires some refactoring to implement';
24
25   ok(
26     !$object->can('rw_attr'),
27     "no rw_attr method because wasn't 'is' ro or rw"
28   );
29   ok($object->can('read_attr'),  "did get a reader");
30   ok($object->can('write_attr'), "did get a writer");
31
32   # eliminate these eval{} when out of TODO
33   eval { $object->write_attr(2); };
34
35   is(
36     eval { $object->read_attr },
37     2,
38     "writing to the object worked",
39   );
40 }