1. You get the tag name visually distinct from its attributes...
You do? Just because the second token after the tag name is now a [? IMO, you get far better visual distinction by using whitespace. For instance:
$nest->nest('newlevel', attr1 => 1, attr2 => 2, attr3 => 3);
2. Your API clearly separates arguments that are separate
By that argument, we ought to write
printf "%d", [3.4];
3. Passing an array reference is more efficient than pass by value? Help me out here..
That depends. Certainly, pushing one reference on the stack is cheaper that pushing 96 key value pairs. But if you first have to create an array with those 96 key value pairs for the sole purpose of handing the sub a reference which is then has to dereference, all the gain is lost. Unless you know more about the calling code, you cannot say much about the overall gain or loss when using arrayrefs.
4. Easier to extend.
Maybe. Does a possible future extension outweight the negatives of code that now needs to change?

Note that by sacrificing point 4 you can get points 1, 2, 3 while remaining backwards compatible by doing something like:

sub nest { my $tagname = $_[0]; my $attributes = @_ == 2 ? $_[1] : [@_[1 .. $#_]]; ... }
Instead of forcing your ideas of API clearity and visual distinction of the tag name upon the users of your code, you leave it to the users to decide whether they find this important or not.

In reply to Re: API design - if you're expecting a scalar and an array .... by JavaFan
in thread API design - if you're expecting a scalar and an array .... by metaperl

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.