#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; { package My; sub new { bless {}, shift } } use Function::Parameters; use Types::Standard qw( InstanceOf ); fun validate(InstanceOf['My'] $m) { # <- Fails :-( say "object:", $m; } my $m = 'My'->new; validate($m);
The exact error message is
In fun validate: missing type name after '[' at 1.pl line 13.
It seems both the modules extend the parser somehow and they step on each other's toes.
Fortunately, it's pretty easy to fix that: you can prevent Function::Parameters from interpreting the InstanceOf before Types::Standard handles it by enclosing it into parentheses:
fun validate((InstanceOf['My']) $m) { # <- Works :-) # ~ ~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Combining Function::Parameters with Type::Standard's InstanceOf
by etj (Priest) on Mar 18, 2022 at 16:49 UTC | |
by choroba (Cardinal) on Mar 18, 2022 at 17:01 UTC | |
by etj (Priest) on Mar 18, 2022 at 17:08 UTC |