File: 002-rw.t

package info (click to toggle)
libmoosex-hasdefaults-perl 0.03-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 1,369; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (3)
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
43
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 7;
use Test::Exception;

do {
    package Person;
    use Moose;
    use MooseX::HasDefaults::RW;

    has name => (
        isa => 'Str',
    );

    has birth_year => (
        is  => 'ro',
        isa => 'Int',
    );

    has favorite_language => (
        isa     => 'Str',
        default => 'Perl',
    );
};

can_ok(Person => qw(name birth_year favorite_language));

my $whacko = Person->new(name => 'Stevan', birth_year => 1924);
is($whacko->name, 'Stevan');
is($whacko->birth_year, 1924);
is($whacko->favorite_language, 'Perl');

$whacko->name('Stevan Little');
$whacko->favorite_language('C#'); # he's dead to us now..

throws_ok {
    $whacko->birth_year(1922);
} qr/read-only accessor/;

is($whacko->name,              'Stevan Little');
is($whacko->favorite_language, 'C#');