Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^3: IF condition with a rangeby tobyink (Canon) |
on Jul 17, 2018 at 08:33 UTC ( [id://1218632]=note: print w/replies, xml ) | Need Help?? |
The majority of the size of the distribution is the test suite. With nearly 1200 CPAN modules depending on Type::Tiny directly or indirectly, having a comprehensive test suite seems a good idea. Documentation and examples make up most of the remaining size. In terms of dependancies, the module Type::Tiny itself has no non-core dependancies (apart from a few modules that are bundled with it).
As you can see, they're all in core, except:
The module I recommended, Types::Common::Numeric does have one additional non-core dependancy: Exporter::Tiny. Exporter::Tiny was originally called Exporter::TypeTiny and bundled as part of the distribution too. However, I was convinced by chocolateboy that it had merit as a standalone module, so I split it out as a separate CPAN distribution. Seems he was right as it now has nearly 4000 downstream dependants. I don't think the fact that some of the modules bundled with Type::Tiny (but not Type::Tiny itself) require Exporter::Tiny makes it unworthy of the "tiny" name. Yes, if it's just one range check in a script, requiring any module whatsoever seems like overkill. But realistically, problems like this don't come up in isolation. Most non-trivial programs will need to sanity-check data in loads of places checking the data passed to object constructors, checking function and method arguments, etc. Type::Tiny and its bundled modules provide a framework for this which is more concise and usually more correct and faster than handwritten code. As an example of correctness, spot the problem with this code:
Okay, so the obvious thing is we're not checking $age is a number. But if we do $object->set_age("old") we'll get a warning about doing a numeric comparison on a string, so we're covered, right? Wrong. $object->set_age([]) will be allowed. Numeric operations on references silently act on their reference address without triggering any warnings. Rewriting it to this:
And as a bonus, it will test that $self is an object, and will check that @_==2. None of the other answers to the OP's question even bothered checking $x was actually a number. IntRange will check that it's defined, it's a non-reference, and it's an integer before checking that it's in the right range.
In Section
Seekers of Perl Wisdom
|
|