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 ... }

In reply to How would you simplify this code? by elTriberium

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.