Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Test::Specio

Name Test::Specio
Version 0.47
Located at /usr/share/perl5
File /usr/share/perl5/Test/Specio.pm
Is Core No
Search CPAN for this module Test::Specio
Documentation Test::Specio
Module Details Test::Specio


NAME

Test::Specio - Test helpers for Specio


VERSION

version 0.47


SYNOPSIS

  use Test::Specio qw( test_constraint :vars );
  test_constraint(
      t('Foo'), {
          accept => [ 'foo', 'bar' ],
          reject => [ 42,    {}, $EMPTY_STRING, $HASH_REF ],
      }
  );


DESCRIPTION

This package provides some helper functions and variables for testing Specio types.


EXPORTS

This module provides the following exports:

test_constraint( $type, $tests, [ $describer ] )

This subroutine accepts two arguments. The first should be a Specio type object. The second is hashref which can contain the keys accept and reject. Each key should contain an arrayref of values which the type accepts or rejects.

The third argument is optional. This is a sub reference which will be called to generate a description of the value being tested. This defaults to calling this package's describe sub, but you can provide your own.

describe($value)

Given a value, this subroutine returns a string describing that value in a useful way for test output. It know about the various classes used for the variables exported by this package and will do something intelligent when such a variable.

builtins_tests( $GLOB, $GLOB_OVERLOAD, $GLOB_OVERLOAD_FH )

This subroutine returns a hashref containing test variables for all builtin types. The hashref has a form like this:

  {
      Bool => {
          accept => [
              $ZERO,
              $ONE,
              $BOOL_OVERLOAD_TRUE,
              $BOOL_OVERLOAD_FALSE,
              ...,
          ],
          reject => [
              $INT,
              $NEG_INT,
              $NUM,
              $NEG_NUM,
              ...,
              $OBJECT,
          ],
      },
      Maybe => {...},
  }

You need to pass in a glob, an object which overloads globification, and an object which overloads globification to return an open filehandle. See below for more details on how to create these things.

Variables

This module also exports many variables containing values which are useful for testing constraints. Note that references are always empty unless stated otherwise. You can import these variables individually or import all of them with the :vars import tag.

Globs and the _T::GlobOverload package

To create a glob you can pass around for tests, use this code:

  my $GLOB = do {
      no warnings 'once';
      *SOME_GLOB;
  };

The _T::GlobOverload package is defined when you load Test::Specio so you can create your own glob overloading objects. Such objects cannot be exported because the glob they return does not transfer across packages properly.

You can create such a variable like this:

  local *FOO;
  my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );

If you want to create a glob overloading object that returns a filehandle, do this:

  local *BAR;
  open BAR, '<', $^X or die "Could not open $^X for the test";
  my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );


SUPPORT

Bugs may be submitted at https://github.com/houseabsolute/Specio/issues.

I am also usually active on IRC as 'autarch' on irc://irc.perl.org.


SOURCE

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


AUTHOR

Dave Rolsky <autarch@urth.org>


COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 - 2021 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.

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026