X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_mouse%2F009-default-code.t;fp=t%2F001_mouse%2F009-default-code.t;h=9693afb66cff4e1ac57b28abe76c682fc7b3f133;hb=920139b3efca66d2caeeef306c97fa0da62c6b73;hp=0000000000000000000000000000000000000000;hpb=b644ef5d28f6076859080482d8b44727c1410e1c;p=gitmo%2FMouse.git diff --git a/t/001_mouse/009-default-code.t b/t/001_mouse/009-default-code.t new file mode 100644 index 0000000..9693afb --- /dev/null +++ b/t/001_mouse/009-default-code.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 9; + +do { + package Class; + use Mouse; + + has 'x' => ( + is => 'rw', + default => sub { 10 }, + ); + + has 'y' => ( + is => 'rw', + default => sub { 20 }, + ); + + has 'z' => ( + is => 'rw', + ); +}; + +my $object = Class->new; +is($object->x, 10, "attribute has a default of 10"); +is($object->y, 20, "attribute has a default of 20"); +is($object->z, undef, "attribute has no default"); + +is($object->x(5), 5, "setting a new value"); +is($object->y(25), 25, "setting a new value"); +is($object->z(125), 125, "setting a new value"); + +is($object->x, 5, "setting a new value does not trigger default"); +is($object->y, 25, "setting a new value does not trigger default"); +is($object->z, 125, "setting a new value does not trigger default"); +