The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::Random::HashType - Random hash type objects.

SYNOPSIS

 use Data::Random::HashType;

 my $obj = Data::Random::HashType->new(%params);
 my @hash_types = $obj->random;

METHODS

new

 my $obj = Data::Random::HashType->new(%params);

Constructor.

  • cb_id

    Callback to adding of id.

    Default value is subroutine which returns $self-{'id'}++>.

  • dt_start

    DateTime object with start date for random valid_from date. Range is dt_start and actual date.

    Default value is January 1. year ago.

  • id

    Minimal id for adding. Only if mode_id is set to 1.

    Default value is 1.

  • mode_id

    Boolean value if we are generating id in hash type object.

    Default value is 0.

  • num_generated

    Number of generated hash types.

    Default value is 1.

  • possible_hash_types

    Possible hash type names for result.

    Default value is list (SHA-256 SHA-384 SHA-512).

Returns instance of object.

random

 my @hash_types = $obj->random;

Get random hash type object.

Returns instance of Data::HashType.

ERRORS

 new():
         From Mo::utils:
                 Parameter 'dt_start' is required.
                 Parameter 'dt_start' must be a 'DateTime' object.
                         Value: %s
                         Reference: %s
                 Parameter 'mode_id' must be a bool (0/1).
                         Value: %s
                 Parameter 'num_generated' must be greater than %s.
                         Value: %s
                 Parameter 'num_generated' is required.
         Parameter 'possible_hash_types' must be a reference to array.
         Parameter 'possible_hash_types' must contain at least one hash type name.

EXAMPLE

 use strict;
 use warnings;

 use Data::Printer;
 use Data::Random::HashType;

 my $obj = Data::Random::HashType->new(
         'mode_id' => 1,
         'num_generated' => 2,
 );

 my @hash_types = $obj->random;

 # Dump hash types to out.
 p @hash_types;

 # Output like:
 # [
 #     [0] Data::HashType  {
 #             parents: Mo::Object
 #             public methods (6):
 #                 BUILD
 #                 Error::Pure:
 #                     err
 #                 Mo::utils:
 #                     check_isa, check_length, check_number, check_required
 #             private methods (0)
 #             internals: {
 #                 id           1,
 #                 name         "SHA-384",
 #                 valid_from   2023-03-17T00:00:00 (DateTime)
 #             }
 #         },
 #     [1] Data::HashType  {
 #             parents: Mo::Object
 #             public methods (6):
 #                 BUILD
 #                 Error::Pure:
 #                     err
 #                 Mo::utils:
 #                     check_isa, check_length, check_number, check_required
 #             private methods (0)
 #             internals: {
 #                 id           2,
 #                 name         "SHA-256",
 #                 valid_from   2023-01-27T00:00:00 (DateTime)
 #             }
 #         }
 # ]

DEPENDENCIES

Class::Utils, Data::HashType, DateTime, Error::Pure, Mo::utils, Random::Day, Readonly.

REPOSITORY

https://github.com/michal-josef-spacek/Data-Random-HashType

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2023-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.05