X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001-ro.t;fp=t%2F001-ro.t;h=fafb47be296a03b48a8a0f516b154de88c3b04b2;hb=8adff614c25684563d3560174bfac79978b9c809;hp=0000000000000000000000000000000000000000;hpb=4db16c58db34a7f8beb429e13ccf879ba2c86dd3;p=gitmo%2FMooseX-IsDefaults.git diff --git a/t/001-ro.t b/t/001-ro.t new file mode 100644 index 0000000..fafb47b --- /dev/null +++ b/t/001-ro.t @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 7; +use Test::Exception; + +do { + package Person; + use Moose; + use MooseX::IsDefaults::RO; + + has name => ( + isa => 'Str', + ); + + has birth_year => ( + isa => 'Int', + ); + + has favorite_language => ( + is => 'rw', + 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'); + +throws_ok { + $whacko->name('Stevan Little'); +} qr/read-only accessor/; + +throws_ok { + $whacko->birth_year(1922); +} qr/read-only accessor/; + +$whacko->favorite_language('C#'); # he's dead to us now.. +is($whacko->favorite_language, 'C#'); +