NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Passing hashref to constructor (Score:1)
Speed is not the only reason, and I believe its not the mains reason even.
My reason to always pass hashrefs is that if I leave out one of the arguments, the error message from perl will tell me the exact line number where I made the mistake, and not the line inside your constructor where you assign @_ to an hash (the common approach).
Having said that, if your constructor checks for a even number of parameters and croaks (or Carp::Clan croaks), then the message will show the correct line number again.
I haven't check the Object::Tiny yet, but I will. And this will probably the first think I'll look for :)
The module looks great BTW.
life is short
Reply to This
Re: (Score:1)
line number where I made the mistake, and not the line inside your
constructor where you assign @_ to an hash (the common approach).
That's what Perl Best Practices recommends too, I think,
although it looks terrible.
Re: (Score:1)
But truth be told, there is no need to use that trick to get the proper error line. If module authors that accept hashes add this line:
croak('FATAL: odd number of parameters, ') if @_ % 2;
(Use Carp qw( croak ) at the top also)
It would also work.
Best regards,
life is short