You'll have to use code generation. The result is that you get a subroutine that's hard-coded to use a list of stuff and you just change how it compiles if you need to alter it. I included a #line declaration so the compilation errors, if any, would come out on the right line.
package Foo::Bar; BEGIN { my @attributes = qw( ... ); eval '#line ' . (1+__LINE__) . ' "' . __FILE __ . '" sub ... { ... my ( ' . join( ', ', map { "\$$_" } @attributes ) . ' ) = @{$self}{qw(' . join( ' ', @attributes ) . ')}; ... }'; die $@ if $@; }
This node has been updated to fix some minor bugs including the omission of the elipses after the my declaration. This mistake on my part confused someone about my intentions. I did not intend to indicate that the subroutine had no more statements in it.
In reply to Re: Computed "my" declarations?
by diotalevi
in thread Computed "my" declarations?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |