Subject: | Sub::Util::set_prototype doesn't work at MODIFY_CODE_ATTRIBUTES time |
It is too early. This (silently!) fails to set the prototype:
*MODIFY_CODE_ATTRIBUTES = sub {
my ( $pkg, $code, @attrs ) = @_;
my @ret;
foreach my $attr ( @attrs ) {
if( $attr =~ m/^prototype\((.*)\)$/ ) {
my $prototype = "$1";
Sub::Util::set_prototype( $prototype, $code );
next;
}
push @ret, $attr;
}
return @ret;
};
This sort of work around by deferring it to UNITCHECK time is required:
my @prototypes;
*MODIFY_CODE_ATTRIBUTES = sub {
my ( $pkg, $code, @attrs ) = @_;
my @ret;
foreach my $attr ( @attrs ) {
if( $attr =~ m/^prototype\((.*)\)$/ ) {
my $prototype = "$1";
push @prototypes, [ $code, $prototype ];
next;
}
push @ret, $attr;
}
return @ret;
};
UNITCHECK {
foreach ( @prototypes ) {
my ( $code, $prototype ) = @$_;
Sub::Util::set_prototype( $_->[1], $_->[0] );
}
}
--
Paul Evans