rw tests
[gitmo/MooseX-IsDefaults.git] / t / 002-rw.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More tests => 7;
5 use Test::Exception;
6
7 do {
8     package Person;
9     use Moose;
10     use MooseX::IsDefaults::RW;
11
12     has name => (
13         isa => 'Str',
14     );
15
16     has birth_year => (
17         is  => 'ro',
18         isa => 'Int',
19     );
20
21     has favorite_language => (
22         isa     => 'Str',
23         default => 'Perl',
24     );
25 };
26
27 can_ok(Person => qw(name birth_year favorite_language));
28
29 my $whacko = Person->new(name => 'Stevan', birth_year => 1924);
30 is($whacko->name, 'Stevan');
31 is($whacko->birth_year, 1924);
32 is($whacko->favorite_language, 'Perl');
33
34 $whacko->name('Stevan Little');
35 $whacko->favorite_language('C#'); # he's dead to us now..
36
37 throws_ok {
38     $whacko->birth_year(1922);
39 } qr/read-only accessor/;
40
41 is($whacko->name,              'Stevan Little');
42 is($whacko->favorite_language, 'C#');
43