in reply to Type::Library messages lost when used with named parameters in Type::Params

A workaround for the actual issue, but can you wrap the call in an eval() block, check the error eval catches (if it does catch anything), and print your custom message?

#!/usr/bin/perl use warnings; use strict; sub divide { return 1 / 0; } my $x; eval { $x = divide(); }; if ($@ =~ /Illegal division/){ print "Don't divide by zero, dummy!\n"; # die with called function's error if required die $@; } print "$x\n";

-stevieb

Replies are listed 'Best First'.
Re^2: Type::Library messages lost when used with named parameters in Type::Params
by 1nickt (Canon) on Jun 30, 2015 at 00:35 UTC

    Hi Stevie, thanks, yeah, that would work. But I assume that the Type::* modules do that under the hood ... If I had to eval a test to print a message, there wouldn't be much point in using the whole Type::* infrastructure....

    As the docs say, the default message is a "vaguely sensible default." So if I can't get my messages to print, it won't be the end of the world. But it's frustrating that it only stops working in a certain case.

    I'm going to see if I can figure out how to fix it in Type::Tiny before I give up :)