in reply to Object::InsideOut with CODE_REF constructor argument

You declare the type as CODE_REF - what is that supposed to do? It is nowhere documented within Object::InsideOut.

Maybe if you use Type(CODE), you get a working type constraint for callbacks?

Replies are listed 'Best First'.
Re^2: Object::InsideOut with CODE_REF constructor argument
by Anonymous Monk on Jul 10, 2011 at 09:32 UTC
    No luck with Type(CODE) and various combinations of fn, &fn or \&fn as argument. Most frustrating.

      The following code works for me (in teh sense that Object::InsideOut doesn't immediately complain):

      #!/usr/bin/perl package CodeRef; use strict; { use Object::InsideOut; warn sprintf "Using %s version %s", 'Object::InsideOut::VERSION', $Object::InsideOut::VERSION ; my @code :Field :Std( Name => 'code', Private => 1 ) :Arg(Name => 'code', Mand =>1 ) :Type(CODE); sub call() { my $self = shift; my $code = $self->get_code(); return $code->(@_); } } 1; #===== package main; sub sum { my $sum =0 ; foreach my $num (@_) { $sum += $num; } return $sum; } my $cref = CodeRef->new( code => \&sum ); __END__ Using Object::InsideOut::VERSION version 3.81 at tmp.pl line 9.
Re^2: Object::InsideOut with CODE_REF constructor argument
by Anonymous Monk on Jul 10, 2011 at 09:33 UTC
    No luck with Type(CODE) and various combinations of fn, &fn or \&fn as argument. Most frustrating. Prefer O:IO if I can. Moose and I tend not to get along well.