sub remote_run {
my ($self, %args) = @_;
$self->resource( $args{resource} ) if $args{resource};
$self->username( $args{username} ) if $args{username};
my $resource = $self->resource
or die("'resource' must be provided");
my $username = $self->username
or die("'username' must be provided");
# Here comes the actual code ...
}
Sure, you could use a loop, but I think it would reduce readability even though it would remove some redundancy.
This usage is rather odd, which is why there's no clear winning way of doing it. I'd use args or attributes, not this mixture.