Open vendethiel opened 11 months ago
Not pretty, but this works:
use v5.30;
BEGIN {
package MyTest::Types;
use Type::Library -base, -utils;
use Types::Common qw( NumRange );
declare Level => as NumRange[ 0, 80 ];
}
package MyTest {
use Zydeco;
class Bucket {
has fill ( type => MyTest::Types::Level() );
}
}
say MyTest->new_bucket( fill => 100 );
I agree that a nicer way to declare aliases would be good.
Ah, thanks. I was wondering if Exporter::Almighty
had such a hatch, but this'll do for now. I also omit the ()
because otherwise,the type won't parse in method parameter type specifiers.
Hi! I recently found Zydeco and I've been toying with it recently.
I'm wondering if there's a way to declare a type alias, that has the same type as its underlying representation. Basically, something like
type Level = NumRange[1, 80];
. While investigating the libs behind Zydeco, I found out thatuse Type::Utils -all
would give me adeclare
function (though it seems to be a keyword at other points, because I seedeclare MyType
unquoted?), but I couldn't manage to get it to work doing it either from my main package or from myMAINPKG::Types
(that I created originally to work around #15), they both error either when declaring it or when using it (sometimes in an unrelated file that also uses Zydeco...).Thanks!