http://qs1969.pair.com?node_id=897927

elTriberium has asked for the wisdom of the Perl Monks concerning the following question:

Hi all Monks,

Below I pasted a small code fragment. My plan is to allow each subroutine to set the object variables. If an argument is provided then it should overwrite the current object value. If an argument is not provided then it should use the current object variable value. It should die when no argument is provided for a variable and none is set yet. I'm basically only looking for a best practice here, as my solution looks too verbose.

If you think this in general is not a good design choice please also let me know why.

package Remote; use Moose; has 'resource' => (is => 'rw', isa => 'Str'); has 'username' => (is => 'rw', isa => 'Str'); sub remote_run { my ($self, %args) = @_; my $resource = $args{'resource'} || $self->resource; my $username = $args{'username'} || $self->username; die "Missing resource variable" if (!defined($resource)); die "Missing username variable" if (!defined($username)); $self->resource($resource); # In case this is a new value. $self->username($username); # Here comes the actual code ... }