- 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");
/* 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;
plan 'no_plan';
}
-my $i;
-
{
package Moose::XS;
ok( defined &Moose::XS::new_accessor, "new_accessor" );
ok( defined &Moose::XS::new_predicate, "new_predicate" );
+my $trigger;
+
{
package Foo;
use Moose;
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!" }
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" );