Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Type::Tiny 1.2 Coming Soon

by tobyink (Abbot)
on May 05, 2017 at 12:11 UTC ( #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.


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 (Parson) on May 05, 2017 at 12:22 UTC


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

    (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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlnews [id://1189565]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-07-21 00:20 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (442 votes). Check out past polls.