in reply to API design - if you're expecting a scalar and an array ....

I'd say XML::Writer got it wrong and should have used a hash reference rather than a flattened list. Note that Perl Best Practices, page 182, advises you to pass a hash ref, not a list of name/value pairs, and so allow you to catch some errors at compile time, rather than run time. This point, along with many others related to API design, is dicussed in detail in On Interfaces and APIs.

  • Comment on Re: API design - if you're expecting a scalar and an array ....

Replies are listed 'Best First'.
Re^2: API design - if you're expecting a scalar and an array ....
by Porculus (Hermit) on May 23, 2009 at 23:32 UTC

    I'm not sure that using a hashref for XML attributes is automatically a good idea. You might want to be able to check the list for duplicates and warn about that, rather than silently discarding all but the last instance.

    Frankly this is one instance where PBP is on shaky ground. You don't actually get the error at compile time, and you don't get it reliably at all. You really aren't gaining much.