From: Shawn M Moore Date: Fri, 10 Jul 2009 06:02:21 +0000 (-0400) Subject: rw tests X-Git-Tag: 0.01~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9e9780de4bfe0036e6c565aa994be32a787eb2b3;p=gitmo%2FMooseX-HasDefaults.git rw tests --- diff --git a/t/002-rw.t b/t/002-rw.t new file mode 100644 index 0000000..a302519 --- /dev/null +++ b/t/002-rw.t @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 7; +use Test::Exception; + +do { + package Person; + use Moose; + use MooseX::IsDefaults::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#'); +