On Wed, May 10, 2006 at 08:38:10PM -0400, John Siracusa wrote: > On 5/10/06 6:03 PM, Jesse Brown wrote: > > Re: the scalar context return value - IS it available elsewhere? (the number > > of items added in that call) - total number of items, yes, but new ones? > > Yeah, because you're making the call! :) Example: > > $o->add_widgets(@widgets); # $count = @widgets > > $o->add_widgets({ ... }, { ... }); # $count == 2
Oh certainly, except for the case of.... $o->add_widgets(&load_widgets_from_somewhere); But i'll concede the point ;) > >> * Return a reference to an array of added objects > >> * Return the first added object. > >> > >> Hm, I'm not sure I like those much either. What I'm worried about is this: > >> > >> $widget = $o->add_widgets($some_widget); > >> > >> The only way that works is if add_widgets() returns the first added > >> object when called in scalar context. But that's a pretty odd > >> behavior. Opinions? > > > > I agree on the last one being odd (though somewhat DWYIM?). Doing my > > ($widget) > > = $o->add_widgets(etc), seems to make enough sense? > > That's too subtle, IMO. I constantly forget to add the parens when I use > APIs like that. It annoys me :) Haha, I agree, just figured I would throw it out there. > > # Do some thing that MIGHT collect a bunch of new widgets > > my @widgets; > > > > if ( ! $o->add_widget(@widgets) ) { > > die "No widgets added! (none found?)"; > > } > > It's silly not to write that more directly: > > # Do some thing that MIGHT collect a bunch of new widgets > my @widgets = ... ; > > if(@widgets) { $o->add_widget(@widgets) } > else { die "No widgets found" } > > > Of course I'm not saying doing it that way is SANE (should always see if you > > have widgets to add first before trying to add them), but it seems that you > > would want to either raise a fatal exception (probably not?), or return > > false. > > If the add_* method returned the items added, or an empty list if no items > were added, then it'd work out okay. The only odd part is returning the > first item added when called in scalar context (to avoid requiring the > parens around the lvalue). But maybe that's not worthwhile. After all, the > method name is plural: add_...s(). > > I'll think about it a bit more... Agree on the plural thing, it sounds like either way it should work? Thanks for thinking about it! If you would like me to implement, just point me to the place the add_ code is defined and I'll send you a patch :) ----------------------------------------------------------- This message may contain confidential and/or privileged information. This information is intended to be read only by the individual or entity to whom it is addressed. If you are not the intended recipient, you are on notice that any review, disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete or destroy any copy of this message. ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object