From: Yuval Kogman Date: Fri, 22 Aug 2008 08:38:11 +0000 (+0000) Subject: trigger X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d08b329903e8e2338cc18a1518be6fcc06b9ffbf;p=gitmo%2FMoose.git trigger --- diff --git a/Moose.xs b/Moose.xs index 6241b9d..4a65a48 100644 --- a/Moose.xs +++ b/Moose.xs @@ -663,11 +663,11 @@ STATIC void init_attr (MI *mi, ATTR *attr, AV *desc) { - attr->trigger = SvROK(params[6]) ? (CV *)SvRV(params[6]) : NULL; + attr->trigger = SvROK(params[8]) ? (CV *)SvRV(params[8]) : NULL; if ( attr->trigger && SvTYPE(attr->trigger) != SVt_PVCV ) croak("trigger is not a coderef"); - attr->initializer = SvROK(params[7]) ? (CV *)SvRV(params[7]) : NULL; + attr->initializer = SvROK(params[9]) ? (CV *)SvRV(params[9]) : NULL; if ( attr->initializer && SvTYPE(attr->initializer) != SVt_PVCV ) croak("initializer is not a coderef"); @@ -1097,7 +1097,7 @@ STATIC void attr_set_value(pTHX_ SV *self, ATTR *attr, SV *value) { /* we invoke the builder as a stringified method. This will not work for * $obj->$coderef etc, for that we need to use 'default' */ PUTBACK; - call_method(SvPV_nolen(attr->def.sv), G_VOID); + call_sv((SV *)attr->trigger, G_VOID); FREETMPS; LEAVE; diff --git a/t/700_xs/001_basic.t b/t/700_xs/001_basic.t index b96a6f6..9ad3e37 100644 --- a/t/700_xs/001_basic.t +++ b/t/700_xs/001_basic.t @@ -18,8 +18,6 @@ BEGIN { plan 'no_plan'; } -my $i; - { package Moose::XS; @@ -107,6 +105,8 @@ ok( defined &Moose::XS::new_writer, "new_writer" ); ok( defined &Moose::XS::new_accessor, "new_accessor" ); ok( defined &Moose::XS::new_predicate, "new_predicate" ); +my $trigger; + { package Foo; use Moose; @@ -130,7 +130,7 @@ ok( defined &Moose::XS::new_predicate, "new_predicate" ); has c => ( isa => "ClassName", is => "rw" ); has b => ( is => "ro", lazy_build => 1 ); # fixme type constraint checking has tc => ( is => "rw", isa => "FiveChars" ); - has t => ( is => "rw", trigger => sub { $i++ } ); + has t => ( is => "rw", trigger => sub { $trigger = "got: " . $_[1] } ); sub _build_b { "builded!" } @@ -212,9 +212,11 @@ is( $foo->ref, $ref, "attr set" ); undef $ref; is( $foo->ref(), undef, "weak ref destroyed" ); -is( $i, undef, "trigger not yet called" ); +is( $trigger, undef, "trigger not yet called" ); is( $foo->t, undef, "no value in t" ); -is( $i, undef, "trigger not yet called" ); +is( $trigger, undef, "trigger not yet called" ); +$foo->t("laaa"); +is( $trigger, "got: laaa", "trigger called" ); ok( !eval { $foo->a("not a ref"); 1 }, "ArrayRef" ); ok( !eval { $foo->a(3); 1 }, "ArrayRef" );