Skip Menu |

This queue is for tickets about the Text-CSV CPAN distribution.

Report information
The Basics
Id: 106359
Status: rejected
Priority: 0/
Queue: Text-CSV

People
Owner: Nobody in particular
Requestors: gabor [...] szabgab.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Constructor silently fails on incorrect parameters
Date: Tue, 11 Aug 2015 10:23:49 +0300
To: bug-Text-CSV [...] rt.cpan.org
From: Gabor Szabo <gabor [...] szabgab.com>
If I forget to pass a hash ref and instead pass only key-value pairs: my $csv = Text:CSV->new( sep_char => 1 ); Text::CSV will return an undef without complaining. I guess this might be a common error. Would it be possible to check if the parameter the constructor gets is a hash -ref if there is any attribute, and die or at least warn if the user passed something that is not a hash-ref? Gabor
On Tue Aug 11 16:24:00 2015, gabor@szabgab.com wrote: Show quoted text
> If I forget to pass a hash ref and instead pass only key-value pairs: > > my $csv = Text:CSV->new( > sep_char => 1 > ); > > Text::CSV will return an undef without complaining. > > I guess this might be a common error. > > Would it be possible to check if the parameter the constructor gets is a > hash -ref > if there is any attribute, and die or at least warn if the user passed > something that is > not a hash-ref? > > Gabor
"new" constructor section clearly says as follows: If the "new ()" constructor call fails, it returns "undef", and makes the fail reason available through the "error_diag ()" method. And SYNOPSIS implicitly suggests to make sure Text::CSV->new() returns an object. It might be a common mistake, but it's a well-defined feature now. If you really think this is important, convince Tux (of Text::CSV_XS) first, because previously Text::CSV_XS died under such a situation. Marked rejected for now. Thanks.