Type::Parser(3)

✨ Type::Parser ✨

okay so this is the User Contributed Perl Documentation page for Type::Parser(3) and bestie, we're about to parse some type constraint strings together πŸ’–


🌸 NAME 🌸

Type::Parser β€” parse type constraint strings πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

use v5.10;
use strict;
use warnings;

use Type::Parser qw( eval_type );
use Type::Registry;

my $reg = Type::Registry->for_me;
$reg->add_types("Types::Standard");

my $type = eval_type("Int | ArrayRef[Int]", $reg);

$type->check(10);        # true
$type->check([1..4]);    # true
$type->check({foo=>1});  # false

like... look at her go 😭 three checks, three answers, no cap.


πŸ‘‘ STATUS πŸ‘‘

This module is covered by the Type-Tiny stability policy. periodt πŸ’…


🌈 DESCRIPTION 🌈

ngl bestie, generally speaking, you probably do NOT want to be using this module directly πŸ™ˆ instead, use the "lookup" method from Type::Registry β€” that one wraps it for you. it's giving "don't talk to the module directly, talk to the module's friend." iykyk ✨

πŸ“ Functions πŸ“

  • parse($string) β€” parses the type constraint string into something like an AST 🧚 and if you call it in list context, it also hands you back any "tail" that was chillin' on the original string. two-for-one, we love to see it πŸ’–
  • "extract_type($string, $registry)" β€” compiles a type constraint string into a Type::Tiny object πŸ”₯ and yep, list context again? you get the "tail" from the original string too πŸ‘‘
  • "eval_type($string, $registry)" β€” also compiles a type constraint string into a Type::Tiny object ✨ but here's the thing: it throws an error if the "tail" contains any non-whitespace character. so no sneaky extra characters, she will clock it πŸ’€

πŸŽ€ Constants πŸŽ€

these constants correspond to the values returned by "$token->type" 🌸

  • "TYPE"
  • "QUOTELIKE"
  • "STRING"
  • "HEXNUM"
  • "CLASS"
  • "L_BRACKET"
  • "R_BRACKET"
  • "COMMA"
  • "SLURPY"
  • "UNION"
  • "INTERSECT"
  • "SLASH"
  • "NOT"
  • "L_PAREN"
  • "R_PAREN"
  • "MYSTERY"

πŸ’€ BUGS πŸ’€

found a bug? pls report it, we're not gatekeeping:

https://github.com/tobyink/p5-type-tiny/issues


🌟 SEE ALSO 🌟

  • Type::Registry πŸ’œ

🫢 AUTHOR 🫢

Toby Inkster <tobyink@cpan.org> πŸ’…


This software is copyright (c) 2013-2014, 2017-2025 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay ✨


⚠️ DISCLAIMER OF WARRANTIES ⚠️

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

no promises bestie, she said what she said 😭


and that's the whole page, mwah πŸŽ€ this was rendered by perl v5.42.0 and dated 2026-01-17, so if you're reading this from the future β€” hi, love you, bye πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from