#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 21;
+use Test::More;
use Test::Exception;
use Test::Mouse;
is $object->rw_attr, 100;
is $object->read_attr, 100;
+is $object->write_attr("piyo"), "piyo";
+is $object->rw_attr("yopi"), "yopi";
+
dies_ok {
Class->rw_attr();
};
dies_ok {
Class->write_attr(42);
};
+
+done_testing;
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More;
use Test::Exception;
my $lazy_run = 0;
is($object->lazy_value, "newp", "got new value");
is($lazy_run, 1, "lazy coderef invoked once");
+is($object->lazy(42), 42);
+is($object->lazy_value(3.14), 3.14);
+
my $object2 = Class->new(lazy => 'very', lazy_value => "heh");
is($lazy_run, 1, "lazy attribute not initialized when an argument is passed to the constructor");
is($object2->lazy_value, 'heh', 'value from the constructor');
is($lazy_run, 1, "lazy coderef not invoked, we already have a value");
+done_testing;
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More;
use Test::Exception;
my @trigger;
},
);
+ has foobar => ( # from Net::Google::DataAPI
+ is => 'rw',
+ isa => 'Str',
+
+ lazy => 1,
+ trigger => sub{ $_[0]->update },
+ default => sub{ 'piyo' },
+
+ clearer => 'clear_foobar',
+ );
+
+ sub update {
+ my($self) = @_;
+ $self->clear_foobar;
+ }
+
::lives_ok {
has not_error => (
is => 'ro',
is(@trigger, 1, "trigger was called on read");
is_deeply([splice @trigger], [[$object, 50, undef]], "correct arguments to trigger in the accessor");
+is($object->foobar, 'piyo');
+is($object->foobar('baz'), 'baz');
+is($object->foobar, 'piyo', "call clearer in triggers");
+
my $object2 = Class->new(attr => 100);
is(@trigger, 1, "trigger was called on new with the attribute specified");
is_deeply([splice @trigger], [[$object2, 100, undef]], "correct arguments to trigger in the constructor");
+done_testing;
SV* const trigger = mcall0s(MOUSE_mg_attribute(mg), "trigger");
dSP;
+ /* NOTE: triggers can remove value, so
+ value must be copied here,
+ revealed by Net::Google::DataAPI (DANJOU).
+ */
+ value = sv_mortalcopy(value);
+
PUSHMARK(SP);
EXTEND(SP, 2);
PUSHs(self);
PUTBACK;
call_sv(trigger, G_VOID | G_DISCARD);
/* need not SPAGAIN */
+
+ assert(SvTYPE(value) != SVTYPEMASK);
}
PUSH_VALUE(value, flags);