Crypt-HSXKPasswd
view release on metacpan or search on metacpan
lib/Crypt/HSXKPasswd/RNG/RandomDotOrg.pm view on Meta::CPAN
package Crypt::HSXKPasswd::RNG::RandomDotOrg;
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::Tiny; # for creating anonymous type definitions
use Type::Params qw( compile ); # for parameter validation with Type::Tiny objects
use Types::Standard qw( :types slurpy ); # for standard types like Str and Int etc.
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)';
# import (or not) modules not listed as required by Crypt::HSXKPasswd
Readonly my $_CAN_EMAIL_VALID => eval{
require Email::Valid; # for email address validation
} || 0;
Readonly my $_CAN_URI => eval{
require URI; # for assembling the query to the random.org API
} || 0;
Readonly my $_CAN_LWP_UA => eval{
require LWP::UserAgent; # for sending HTTP requests to the random.org API (requires Mozilla::CA be installed to work with HTTPS)
} || 0;
Readonly my $_CAN_HTTPS => eval{
require Mozilla::CA; # without this module LWP::UserAgent can't do HTTPS
} || 0;
# if all the 'non-standard' modules (for want of a better term) were not loaded, croak
unless($_CAN_EMAIL_VALID && $_CAN_URI && $_CAN_LWP_UA && $_CAN_HTTPS){
croak('Crypt::HSXKPasswd::RNG::RandomDotORg requires modules not required by any other classes in Crypt::HSXKPasswd, and one or more of them are not installed: Email::Valid, URI, LWP::UserAgent & Mozilla::CA');
}
# 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__;
# Random.org settings
Readonly my $RDO_URL => 'https://www.random.org/integers/';
Readonly my $RDO_MAX_INT => 100_000_000;
#
# --- Constructor -------------------------------------------------------------
#
#####-SUB-#####################################################################
# Type : CONSTRUCTOR (CLASS)
# Returns : An object of type Crypt::HSXKPasswd::RNG::RandomDotOrg
# Arguments : 1) the email address to include in the web service calls (the
# TOS requests that this informaiton be included in the
# UserAgent string when making API requests.
# 2) OPTIONAL - named arguments:
# num_passwords - the number of passwords to fetch random
# numbers for at a time (a multiplier to apply to the
# argument received by random_numbers()), defaults to 3
# num_absolute - the absolute number of random numbers to fetch
# at a time. If specified, this value will take precidence
# over num_passwords
# timeout - the timeout (in seconds) for the HTTP request to
( run in 0.527 second using v1.01-cache-2.11-cpan-39bf76dae61 )