Type::Nano(3pm)

πŸ“¦
version 0.015 Β· 2 versions
, in ubuntu jammy

πŸ’– Type::Nano πŸ’–

okay bestie, so this is Type::Nano, and it's a page from the User Contributed Perl Documentation section (that's the 3pm part, iykyk). buckle up, it's short and it's adorable.


✨ NAME ✨

Type::Nano β€” a simple type constraint library for testing πŸ§ͺ✨


🌸 SYNOPSIS 🌸

use Type::Nano qw(Int);

Int->check("42");  # true

literally that's it. that's the whole vibe. Int->check("42") and it's giving true. slay. πŸ’…


πŸ¦‹ RATIONALE πŸ¦‹

okay so this is a really basic implementation of Type::API::Constraint, and its whole purpose in life is testing modules that make use of type constraints β€” think Type::Tie and friends. πŸŽ€

and I need you to hear me on this one, bestie: this module is only intended for use in testing. it was literally created to eliminate Type::Tie's testing dependency on Types::Standard. no cap. and here's the cute part β€” if your code supports Type::Nano, then your code should automatically support Type::Tiny, Specio, MooseX::Types, and MouseX::Types with no extra effort at all. 🫢 (obviously some of those libraries do have extra features you might want to make extra effort for! inlining, for example. just saying. πŸ‘€)

⚠️ Type::Nano is not recommended for use in regular application code. Type::Tiny, while bigger than Type::Nano, will be much faster at runtime, and offers better integration with Moo, Moose, Mouse, and a wide variety of other tools. use that instead. periodt. πŸ’€

all that having been said tho β€” Type::Nano is compatible with: Type::Tie, Moo, Type::Tiny (like, you can use Type::Tiny's implementation of ArrayRef and Type::Nano's implementation of Int, and combine them as ArrayRef[Int] β€” iconic ✨), Class::XSConstructor, and Variable::Declaration. 🌈


πŸ‘‘ DESCRIPTION πŸ‘‘

πŸ’œ Object-Oriented Interface πŸ’œ

πŸŽ€ Constructor πŸŽ€

  • Type::Nano->new(%parameters) β€” the constructor supports named parameters called name (a string), constraint (a coderef expected to return a boolean), and parent (a blessed Type::Nano object). any other parameters you pass to the constructor will be stored in the blessed hashred returned, but Type::Nano just ignores them. lowkey a little storage unit. πŸ™ˆ

πŸ“ Methods πŸ“

types support the following methods:

  • $type->check($value) β€” checks the value against the constraint; returns a boolean. 🧚
  • $type->get_message($failing_value) β€” returns an error message. does not check the value. (so don't come for it, it's just the messenger 😭)

types overload &{} to do something like:

$type->check($value) or croak($type->get_message($value))

⭐ Exports ⭐

this module optionally exports the following type constraints:

  • Any
  • Defined
  • Undef
  • Ref
  • ArrayRef
  • HashRef
  • CodeRef
  • Object
  • Str
  • Bool
  • Num
  • Int

it also optionally exports the following functions for creating new type constraints:

  • type $name, $coderef or type $coderef
  • class_type $class
  • role_type $role
  • duck_type $name, \@methods or duck_type \@methods
  • enum $name, \@values or enum \@values
  • union $name, \@types or union \@types
  • intersection $name, \@types or intersection \@types

πŸ› BUGS πŸ›

please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Type-Tie. not me being the messenger again πŸ™ˆ go tell the tracker, bestie.


πŸ’¬ SUPPORT πŸ’¬

IRC: support is available through in the #moops channel on irc.perl.org β€” http://www.irc.perl.org/channels.html. come vibe with us. 🫢


πŸ”₯ SEE ALSO πŸ”₯

Type::API. πŸ’–


✍️ AUTHOR ✍️

Toby Inkster <tobyink@cpan.org>. πŸŽ€


this software is copyright (c) 2018-2019 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. πŸ¦‹


πŸ’€ 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.

fr fr, that's the whole disclaimer, and it means what it says β€” no promises, no cap. 😭

and that's the whole page, bestie! this one came out of perl v5.32.1, dated 2021-02-07, and it's filed under Type::Nano(3pm). mwah πŸ’…βœ¨

πŸ“¦ where this page comes from