OS Manuals

Types::Standard::Dict(3pm)

Types::Standard::Dict - exporter utility and utility functions for the Dict type constraint

Types::Standard::Dict(3) User Contributed Perl Documentation Types::Standard::Dict(3)

Types::Standard::Dict - exporter utility and utility functions for the Dict type constraint

This module is not covered by the Type-Tiny stability policy.

This is mostly internal code, but has one public-facing function.

Creates a combined type constraint, attempting to be permissive.

The following two types should be equivalent:

  my $type1 = Types::Standard::Dict::combine(
    Dict[ name => Str ],
    Dict[ age => Int, Slurpy[HashRef[Int]] ],
    Dict[ id => Str, name => ArrayRef, Slurpy[ArrayRef] ],
  );
  
  my $type2 = Dict[
    name => Str|ArrayRef,
    age => Int,
    id => Str,
    Slurpy[ HashRef[Int] | ArrayRef ],
  ];
    

Note that a hashref satisfying the combined type wouldn't satisfy any of the individual Dict constraints, nor vice versa!

This function can be exported:

  use Types::Standard -types;
  use Types::Standard::Dict combine => { -as => 'combine_dicts' };
  
  my $type1 = combine_dicts(
    Dict[ name => Str ],
    Dict[ age => Int, Slurpy[HashRef[Int]] ],
    Dict[ id => Str, name => ArrayRef, Slurpy[ArrayRef] ],
  );
    

Types::Standard::Dict can be used experimentally as an exporter.

  use Types::Standard 'Str';
  use Types::Standard::Dict Credentials => { of => [
    username => Str,
    password => Str,
  ] };

This will export the following functions into your namespace:

"Credentials"

Multiple types can be exported at once:

  use Types::Standard -types;
  
  use Types::Standard::Dict (
    Credentials => { of => [
      username => Str,
      password => Str,
    ] },
    Headers => { of => [
      'Content-Type' => Optional[Str],
      'Accept'       => Optional[Str],
      'User-Agent'   => Optional[Str],
    ] },
  );
  
  # Exporting this separately so it can use the types defined by
  # the first export.
  use Types::Standard::Dict (
    HttpRequestData => { of => [
      credentials => Credentials,
      headers     => Headers,
      url         => Str,
      method      => Enum[ qw( OPTIONS HEAD GET POST PUT DELETE PATCH ) ],
    ] },
  );
  
  assert_HttpRequestData( {
    credentials => { username => 'bob', password => 's3cr3t' },
    headers     => { 'Accept' => 'application/json' },
    url         => 'http://example.net/api/v1/stuff',
    method      => 'GET',
  } );

It's possible to further constrain the hashref using "where":

  use Types::Standard::Dict MyThing => { of => [ ... ], where => sub { ... } };

Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.

Types::Standard.

Toby Inkster <tobyink@cpan.org>.

This software is copyright (c) 2013-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.

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.

2026-10-26 perl v5.44.0

perl-type-tiny 2.010001-r5 · os · ingested 2026-10-27