in reply to Re: Object::InsideOut with CODE_REF constructor argument
in thread Object::InsideOut with CODE_REF constructor argument

No luck with Type(CODE) and various combinations of fn, &fn or \&fn as argument. Most frustrating.
  • Comment on Re^2: Object::InsideOut with CODE_REF constructor argument

Replies are listed 'Best First'.
Re^3: Object::InsideOut with CODE_REF constructor argument
by Corion (Patriarch) on Jul 10, 2011 at 09:38 UTC

    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.