Monday, February 23, 2009

Perl tip: can returns coderef

well, I just released the MooseX::Dumper today.

miyagawa on irc.perl.org #moose just told me that ->can() returns the coderef, so that I don't need to do follows:
        if ( $self->dumper_class->can($meth) ) {
my $class = $self->dumper_class;
my $val = eval "${class}::${meth}(\@_)"; # no critic
return $val;
}
Instead, just do:
        if ( my $dump_code = $self->dumper_class->can($meth) ) {
return $dump_code->(@_);
}
Yup, much more simpler and cleaner.

Thanks, miyagawa. 0.02 is on the way. :)

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home