Crypt-HSXKPasswd

 view release on metacpan or  search on metacpan

lib/Crypt/HSXKPasswd/RNG/Math_Random_Secure.pm  view on Meta::CPAN

package Crypt::HSXKPasswd::RNG::Math_Random_Secure;

use parent Crypt::HSXKPasswd::RNG;

# import required modules
use strict;
use warnings;
use Carp; # for nicer 'exception' handling for users of the module
use Fatal qw( :void open close binmode ); # make builtins throw exceptions on failure
use English qw( -no_match_vars ); # for more readable code
use Readonly; # for truly constant constants
use Type::Params qw( compile ); # for parameter validation with Type::Tiny objects
use Crypt::HSXKPasswd::Types qw( :types ); # for custom type checking
use Crypt::HSXKPasswd::Helper; # exports utility functions like _error & _warn

# set things up for using UTF-8
use 5.016; # min Perl for good UTF-8 support, implies feature 'unicode_strings'
use Encode qw(encode decode);
use utf8;
binmode STDOUT, ':encoding(UTF-8)';

# try import Data::Entropy::Algorithms
Readonly my $_CAN_MATH_RANDOM_SECURE => eval{
    require Math::Random::Secure; # for random number generation
} || 0;

# Copyright (c) 2015, Bart Busschots T/A Bartificer Web Solutions All rights
# reserved.
#
# Code released under the FreeBSD license (included in the POD at the bottom of
# HSXKPasswd.pm)

#
# --- Constants ---------------------------------------------------------------
#

# version info
use version; our $VERSION = qv('1.2');

# utility variables
Readonly my $_CLASS => __PACKAGE__;

#
# --- Constructor -------------------------------------------------------------
#

#####-SUB-#####################################################################
# Type       : CONSTRUCTOR (CLASS)
# Returns    : An object of type Crypt::HSXKPasswd::RNG::Math_Random_Secure
# Arguments  : NONE
# Throws     : Croaks on invalid invocation and invalid args, or if the module
#              Math::Random::Secure is not available
# Notes      : 
# See Also   : 
sub new{
    my $class = shift;
    
    # validate the args
    _force_class($class);
    
    # croak if Math::Random::Secure is not avaialble
    unless($_CAN_MATH_RANDOM_SECURE){
        _error('This RNG module requires Math::Random::Secure, which is not installed');
    }
    
    # bless and return an empty object
    my $instance = {};
    bless $instance, $class;
    return $instance;
}

#
# --- Public Instance functions -----------------------------------------------
#

#####-SUB-#####################################################################
# Type       : INSTANCE



( run in 0.561 second using v1.01-cache-2.11-cpan-39bf76dae61 )