Banal-Util-Mini

 view release on metacpan or  search on metacpan

lib/Banal/Util/Mini.pm  view on Meta::CPAN

use 5.010;
use utf8;
use strict;
use warnings;

package Banal::Util::Mini; # git description: v0.001-3-gfdd78c4
# vim: set ts=2 sts=2 sw=2 tw=115 et :
# ABSTRACT: Provide several utility functions with minimal dependencies.
# KEYWORDS: Util utility light-weight

our $VERSION = '0.002';
# AUTHORITY

use Carp                     qw(croak);
use Scalar::Util             qw(blessed  refaddr reftype);
use List::Util 1.45          qw(any first none pairs uniq);
use List::MoreUtils 0.426    qw(arrayify firstres listcmp); # arrayify and listcmp were introduced in 0.420; stabilized by 0.426
# use overload;              # TAU : Required by flatten() and hence arrayify(), when they are defined here, as copied from List::MoreUtils;



use Data::Printer       qw(p np);  # During development only. TODO: comment this line out later.

use namespace::autoclean;


use Exporter::Shiny;
use vars qw(@EXPORT_OK);
BEGIN {
   @EXPORT_OK = qw(
    msg
    polyvalent

    hash_access
    hash_lookup
    hash_lookup_staged

    inverse_dict
    inverse_mapping

    maybe
    maybe_kv
    peek

    tidy_arrayify
    first_viable
    invoke_first_existing_method

    affixed
    prefixed
    suffixed

    sanitize_env_var_name
    sanitize_subroutine_name
    sanitize_identifier_name
  );

  # Add function aliases with underscore prefixes (single & double)
  my @ok = @EXPORT_OK;
  foreach my $pfx ('_', '__') {
    { no strict 'refs';
      *{ __PACKAGE__ . '::' . $pfx . $_ } = \&{ __PACKAGE__ . '::' . $_ } for @ok ;
    }
    push @EXPORT_OK, ( map {; $pfx . $_ } (@ok) );
  }
}
#say STDERR 'EXPORT_OK : ' . np @EXPORT_OK;



#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
# UTILITY FUNCTIONS
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

#----------------------------------------------------------
# CLASS / OBJECT related functions
#----------------------------------------------------------

#######################################
sub polyvalent     {  # Helps with the parameter processing of polyvalent (object or class) methods
#######################################
  my $proto     = shift;
  my $self      = blessed $proto ? $proto : $proto->new();
  my $class     = blessed $self;



( run in 2.211 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )