[Catalyst] html-widget bug or design?

Matt S Trout dbix-class at trout.me.uk
Thu Mar 2 15:35:12 CET 2006


On Wed, Mar 01, 2006 at 12:23:42PM -0600, Brian Kirkbride wrote:
> Nilson Santos Figueiredo Junior wrote:
> > If you want an array ref call it like:
> > 
> > my $result = Class->method;
> > 
> > If you want a list of values call it like:
> > 
> > my ($result) = Class->method;
> > 
> 
> 
> I think that is what he was requesting, actually.  
> 
> His problem was with code like this:
> 
> sub method {
>   return $results[0] if scalar(@results) == 1;
>   return wantarray ? @results : \@results;
> }
> 
> Which really is a pain, IMHO.

IMO if you're going to return something else in scalar context you should
ensure it numifies to the number of entries that would have been returned
in list context. Otherwise code like this -

my @foo = $obj->foo;
my $x = scalar @foo;

my $y = scalar $obj->foo;

will result in $x and $y not being the same thing, which is horribly
unintuitive - hence why DBIx::Class::ResultSet objects numify to the number
of records.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list