The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CXC::Number::Sequence::Utils - Utilities for CXC::Number::Sequence generators

VERSION

version 0.04

SYNOPSIS

SUBROUTINES

buildargs_factory

  $sub = buildargs_factory( %args );

Generate a subroutine wrapper for "BUILDARGS" in Moo for use with "around" in Moo, e.g.

  around BUILDARGS => buildargs_factory(
      map       => \%ArgMap,
      build     => \%ArgBuild,
      xvalidate => \@ArgsCrossValidate
  );

It takes the following arguments:

map => \%hash

This hash maps a parameter name to a Type::Tiny type and a bitmask flag which uniquely identifies the parameter. The hash keys are the parameter names, and the values are hashes with elements keys type (the Type::Tiny type) and flag (an integer bitmask flag). For example,

  use enum qw( BITMASK: MIN MAX SOFT_MIN SOFT_MAX NBINS BINW RATIO GROW );

  my %ArgMap = (
     binw     => { type => BinWidth,               flag => BINW },
     max      => { type => Optional [BigNum],      flag => MAX },
     min      => { type => Optional [BigNum],      flag => MIN },
     nbins    => { type => Optional [PositiveInt], flag => NBINS },
     ratio    => { type => Ratio,                  flag => RATIO },
     soft_max => { type => Optional [BigNum],      flag => SOFT_MAX },
     soft_min => { type => Optional [BigNum],      flag => SOFT_MIN },
  );
build => \%hash

This hash maps combinations of parameters with subroutines which return parameters to be returned by "BUILDARGS" in Moo. The keys are masks which specify the parameters, and the values are subroutines which operate on $_ (an object with methods named for the parameters). For example,

    ( MIN | NBINS | BINW | RATIO ),
    sub {
        my $nbins = $_->nbins;
        if ( $_->binw > 0 ) {
          ...
        }
        ...
        { elements => { } };
    },
xvalidate => \@array

This optional argument provides subroutines to cross-validate parameters. The array elements are themselves arrays with two elements; the first is a mask which represents the combination of parameters to test, the second is a subroutine which operates on $_ (an object with methods named for the parameters). It should throw if the validation fails. Validation subroutines are called in the order presented in the array.

For example, the following entry ensures that the specified minimum values are less than maximum values:

 [
     MIN | MAX,
     sub {
         parameter_constraint->throw( "min < max\n" ) unless $_->min < $_->max;
     },
 ],
adjust => \&sub

This is an optional parameter providing a subroutine which is passed (via $_) a hash containing the passed build parameters. It can adjust them in place as required.

load_class

  $class_name = load_seq_class( $class_or_submodule );

$class_or_submodule is CamelCased.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number or by email to bug-cxc-number@rt.cpan.org.

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Please see those modules/websites for more information related to this module.

AUTHOR

Diab Jerius <djerius@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007