Combine the aliasing of @_ arguments with the aliasing of for my $xxx (..things to alias..). Modifiable parameters with pretty, scoped names.
Subroutines called can apply the same strategy if appropriate. In may case, this is for a validation framework.
package Artificial::Example; use Carp; sub integer_rx { # params ($self, $item) ignore $self for my $item ($_[1]) { # alias unless ($item =~ s/^\s*([-+])?\s*(\d+)\s*$/$1$2/) { confess "You must provide a valid number, (not '$item')"; } } return 1; } sub validate_item { my $self = shift; for my $item ($_[0]) { # alias my $constraint = 'integer_rx'; $self->$constraint($item); return 1; } } my $slot = bless {} => __PACKAGE__; my @tests = ('123',' + 456 ', 'zzz'); for my $item (@tests) { print "'$item' before check\n"; $slot->validate_item($item); print "'$item' after check\n\n"; } 1; __END__ $ perl -w for_alias.pl '123' before check '123' after check ' + 456 ' before check '+456' after check 'zzz' before check You must provide a valid number, (not 'zzz') at for_alias.pl line 7 Artificial::Example::integer_rx('Artificial::Example=HASH(0x80 +f606c)', 'zzz') called at for_alias.pl line 19 Artificial::Example::validate_item('Artificial::Example=HASH(0 +x80f606c)', 'zzz') called at for_alias.pl line 29
|
|---|