Perl 6 module to assist with creating awesome subsets
Perl6
Switch branches/tags
Nothing to show
Latest commit 4b1233d Apr 27, 2017 @zoffixznet committed on GitHub Merge pull request #3 from samcv/SPDX-license
Use SPDX identifier in license field of META6.json
Permalink
Failed to load latest commit information.
examples first commit Apr 17, 2016
lib/Subset first commit Apr 17, 2016
logotype first commit Apr 17, 2016
t Wrote tests Apr 17, 2016
.gitignore first commit Apr 17, 2016
.travis.yml first commit Apr 17, 2016
Changes first commit Apr 17, 2016
LICENSE first commit Apr 17, 2016
META6.json Use SPDX identifier in license field of META6.json Apr 27, 2017
README.md Clearify note Apr 26, 2017

README.md

Build Status

NAME

Subset::Helper - create awesome subsets

SYNOPSIS

    use Subset::Helper;

    subset Positive of Int
        where subset-is * > 0, 'Value must be above zero';

    my Positive $x = 42; # success
    my Positive $x = -2; # Fails with 'Value must be above zero';

DESCRIPTION

This module solves two inconviniences with Perl 6's subsets:

1) Display of useful error messages when type check fails
2) Avoid evaluating subset's condition for `Any` values,
    which is what happens with optional parameters

EXPORTED SUBROUTINES

subset-is

    subset Positive of Int where subset-is * > 0;

    subset RoverCam of Str where subset-is
        { $_  set <MAST CHEMCAM FHAZ RHAZ> },
        'Valid cameras are MAST, CHEMCAM, FHAZ, and RHAZ';

Takes one mandatory positional argument, which is the code to execute to check the validity of value, and an optional descriptive error message to show when the value doesn't match the subset.

Note: undefined values are accepted by the subset. This exists to make it possible to cleanly define subsets for optional parameters, for which the type check is still called, even when they aren't provided in the sub/method calls.

CONFUSING ERRORS

You can't declare our scoped subsets within roles. If you're using this module, however, that error will instead point to the end of the declaration, saying expecting any of: postfix. Simply prefix your subset with my

BUGS AND LIMITATIONS

Rakudo may evaluate whether a value matches the subset TWICE: once to check the match and once to get sensible error information.

Thus, currently the error message you provide is printed twice.

Patches to fix this are welcome.


REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/perl6-Subset-Helper

BUGS

To report bugs or request features, please use https://github.com/zoffixznet/perl6-Subset-Helper/issues

AUTHOR

Zoffix Znet (http://zoffix.com/)

LICENSE

You can use and distribute this module under the terms of the The Artistic License 2.0. See the LICENSE file included in this distribution for complete details.