Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Type::Tiny 1.2 Coming Soon

by tobyink (Canon)
on May 05, 2017 at 12:11 UTC ( [id://1189565]=perlnews: print w/replies, xml ) Need Help??

Or 1.002000, because it uses Moo-like versioning.

The Type::Tiny 1.1 (1.001_00x) development cycle has been going on since September 2014. Apparently I'm either very concerned about stability or very lazy. You can make up your own minds about that.

But Type::Tiny 1.2 should be released in a few weeks. If your application uses Type::Tiny, you may want to download the latest development release and check that nothing breaks. (It shouldn't, but you never know until you try.)

The headline changes are:

  • Type::Params now has compile_named and validate_named.
  • Type::Tiny's constraint parameter may be a string of code.
  • Fixed bug where Types::Standard::Int would sometimes accept an overloaded object. (It never should.)
  • Various performance enhancements and bug fixes.

I'll explain the first two in more detail, because they're interesting.

compile_named

Type::Params is a module for type-checking the parameters to functions. For example, specifying that the $quantity parameter should be an integer. It was mostly written with positional parameters in mind, like eat_apples(2, "red").

Named parameters like eat_apples( quantity=>2, colour=>"red" ) could be made to work, but it was a bit of a hack. The Type::Tiny 1.1 development versions introduced a better way of doing this. It's not only neater, but it provides better error messages and it benchmarks a lot faster. Below is some code showing the old way and the new way.

Examples on Gist

String Constraints

Normally when creating a type constraint, you'd provide a coderef which checks the variable $_ to see if it should pass the constraint. Recently the development versions of Type::Tiny have started accepting a string of Perl code instead. This can not only lead to very concise code, but is an easy way to allow Type::Tiny to optimize its checks. (You can manually optimize them even better by telling Type::Tiny how to inline type checks, but that requires a little bit of extra effort.)

Examples on Gist

Replies are listed 'Best First'.
Re: Type::Tiny 1.2 Coming Soon
by erix (Prior) on May 05, 2017 at 12:22 UTC

    thanks!

    I went to have a look and noticed that that second 'Examples on Gist' should be:

    https://gist.github.com/tobyink/747cab91e84eee7fa3f58a7dd8d909db

    (in the OP there is a stray terminal 2)

      Thanks. Fixed. (The double-quote mark is shift+2, and this laptop has a dodgy shift key.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlnews [id://1189565]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-23 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found