<commit_before>package ORM::EnsEMBL::Utils::Helper;

use strict;
use warnings;

use Digest::MD5 qw(md5_hex);
use Exporter    qw(import);

use ORM::EnsEMBL::Utils::Exception;

our @EXPORT = qw(dynamic_use add_method random_string encrypt_password);

sub dynamic_use {
  ## Dynamically does a 'use' of the class with the given name
  ## @param Class name
  ## @return 1 if successful, 0 otherwise
  my $classname = shift;

  eval "require $classname";
  return 0 if $@;
  $classname->import;
  return 1;
}

sub add_method {
  ## Dynamically adds a method to a class
  ## @param  Class (or object instance of the class)
  ## @params List of method name and subroutine code (can be multiple)
  my $class = shift;
     $class = ref $class if ref $class;

  while (@_) {
    my ($method_name, $method) = splice @_, 0, 2;
    no strict qw(refs);
    *{"${class}::${method_name}"} = $method;
  }
}

sub random_string {
  ## Returns a random string of given length and constituting given characters only
  ## @param Length of the string (defaults to 8)
  ## @param Arrayref of characters that are allowed in the random string (optional)
  my $length  = (shift) + 0 || 8;
  my $random  = shift || ['a'..'z','A'..'Z','0'..'9','_'];

  return join '', map { $random->[ rand @$random ] } (1..$length);
}

sub encrypt_password {
  ## Returns encrypted password to be saved in the database
  ## @param Password string
  return md5_hex($_[0]);
}<commit_msg>only import the required methods<commit_after>package ORM::EnsEMBL::Utils::Helper;

use strict;
use warnings;

use Digest::MD5 qw(md5_hex);
use Exporter    qw(import);

use ORM::EnsEMBL::Utils::Exception;

our @EXPORT_OK = qw(dynamic_use add_method random_string encrypt_password);

sub dynamic_use {
  ## Dynamically does a 'use' of the class with the given name
  ## @param Class name
  ## @return 1 if successful, 0 otherwise
  my $classname = shift;

  eval "require $classname";
  return 0 if $@;
  $classname->import;
  return 1;
}

sub add_method {
  ## Dynamically adds a method to a class
  ## @param  Class (or object instance of the class)
  ## @params List of method name and subroutine code (can be multiple)
  my $class = shift;
     $class = ref $class if ref $class;

  while (@_) {
    my ($method_name, $method) = splice @_, 0, 2;
    no strict qw(refs);
    *{"${class}::${method_name}"} = $method;
  }
}

sub random_string {
  ## Returns a random string of given length and constituting given characters only
  ## @param Length of the string (defaults to 8)
  ## @param Arrayref of characters that are allowed in the random string (optional)
  my $length  = (shift) + 0 || 8;
  my $random  = shift || ['a'..'z','A'..'Z','0'..'9','_'];

  return join '', map { $random->[ rand @$random ] } (1..$length);
}

sub encrypt_password {
  ## Returns encrypted password to be saved in the database
  ## @param Password string
  return md5_hex($_[0]);
}

1;
{'fraction_non_alphanumeric': 0.13720770288858322, 'fraction_numerical': 0.011348005502063274, 'mean_word_length': 3.8402662229617306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866231', 'n_tokens_mistral': 1001, 'n_tokens_neox': 947, 'n_words': 343}