Specio::Subs(3)

🌸 NAME 🌸

Specio::Subs β€” Make validation and coercion subs from Specio types. (Yup bestie, the manual name is Specio::Subs(3), and this is a User Contributed Perl Documentation moment. Hi πŸ’–)

πŸŽ€ VERSION πŸŽ€

version 0.49. Slay.

πŸ¦‹ SYNOPSIS πŸ¦‹

use Specio::Subs qw( Specio::Library::Builtins Specio::Library::Perl My::Lib );

if ( is_PackageName($var) ) { ... }

assert_Str($var);

my $person1 = to_Person($var);
my $person2 = force_Person($var);

✨ DESCRIPTION ✨

okay so bestie, this module generates a set of helpful validation and coercion subroutines for all of the types defined in one or more libraries. No cap.

To use it, simply import Specio::Subs passing a list of one or more library names. This module will load those libraries as needed. Convenient, right?

If any of the types in any libraries have names that do not work as part of a Perl subroutine name, this module will throw an exception. So watch those names, okay?

If you have Sub::Util or Sub::Name installed, one of those will be used to name the generated subroutines. Fancy naming energy.

πŸ’– EXPORTS πŸ’–

The following subs are created in the importing package:

is_$type($value)

This subroutine returns a boolean indicating whether or not the $value is valid for the type. Vibe check: passed or not?

assert_$type($value)

This subroutine dies if the $value is not valid for the type. It dies, no cap.

to_$type($value)

This subroutine attempts to coerce $value into the given type. If it cannot be coerced it returns the original $value. Best-effort coercion, iconic.

This is only created if the type has coercions. No coercions? No sub. Periodt.

force_$type($value)

This subroutine attempts to coerce $value into the given type, and dies if it cannot do so. All or nothing, bestie.

This is only created if the type has coercions. Same rule: coercions or it's not invited.

🌈 ADDITIONAL API 🌈

This module has a subroutine named subs_installed_into. It is not exported but it can be called by its fully qualified name. It accepts a single argument, a package name. It returns a list of subs that it generated and installed in the given package, if any. Package detective behavior.

This exists to make it easy to write a type library that combines other libraries and generates helper subs for export all at once. Big convenience energy.

See the Specio::Exporter docs for more details.

🫢 SUPPORT 🫢

Bugs may be submitted at https://github.com/houseabsolute/Specio/issues. Please be nice to the bugs.

🧚 SOURCE 🧚

The source code repository for Specio can be found at https://github.com/houseabsolute/Specio. Go look, bestie.

πŸ‘‘ AUTHOR πŸ‘‘

Dave Rolsky <autarch@urth.org>. Legend behavior.

This software is Copyright (c) 2012 - 2024 by Dave Rolsky.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the LICENSE file included with this distribution. Read the license, it's giving legal realness.


Okay that's the whole page, signed off by perl v5.42.0 on 2024-12-24 β€” mwah πŸ’‹

πŸ“¦ where this page comes from