Crypt-HSXKPasswd
view release on metacpan or search on metacpan
bin/hsxkpasswd view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use English qw( -no_match_vars );
use Fatal qw( :void open close binmode ); # make builtins throw exceptions
use Getopt::Long; # for argument processing
use Pod::Usage; # for help and usage
use JSON qw( decode_json ); # for decoding JSON strings
use Module::Load; # for dynamically loading modules
use File::HomeDir; # for finding the path to the user's home dir
use Types::Standard qw( :types ); # for basic type checking (Int Str etc.)
# include Crypt::HSXKPasswd Stuff
# DEV-ONLY
use lib './lib/';
use Crypt::HSXKPasswd;
use Crypt::HSXKPasswd::Types qw( :types );
# 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)';
# 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
# this file)
#
# === Constants ===============================================================#
#
# version info
use version; our $VERSION = qv('1.3');
#
# === Process Args ============================================================#
#
# parse the commandline options
my $verbose = 0;
my %cmd_args = ();
GetOptions(
#
# -- the 'do and exit' options --
#
'help|h' => sub{
pod2usage(
-exitval => 0,
-verbose => 2,
);
},
'version|v' => sub{
pod2usage(
-exitval => 0,
-verbose => 99,
-sections => 'NAME',
);
},
'test-config|t=s' => sub{
my ($opt_name, $val) = @_;
unless(-f $val){
byeee("file $val does not exist");
}
open my $CONFIG_FH, '<', $val or byee("failed to read file $val with error:\n* $OS_ERROR");
my $json_string = do{local $/ = undef; <$CONFIG_FH>};
close $CONFIG_FH;
my $config;
eval{
$config = decode_json($json_string);
1; # explicit evaluation
}or do{
byeee("failed to parse the config JSON string:\n* source file: $val\n* parse error: $EVAL_ERROR");
};
say 'Distilling the config down to just valid keys ...';
$config = Crypt::HSXKPasswd->distil_to_config_keys($config, warn_invalid_key_names => 1);
say q{}; # empty line
say 'Validing the distilled config ...';
( run in 2.162 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )