CellBIS-Random
view release on metacpan or search on metacpan
lib/CellBIS/Random.pm view on Meta::CPAN
package CellBIS::Random;
use strict;
use warnings;
use utf8;
use Carp ();
use Scalar::Util qw(blessed weaken);
use List::SomeUtils qw(part);
# ABSTRACT: Tool for Randomize characters in strings.
our $VERSION = '0.3';
# Constructor :
# ------------------------------------------------------------------------
sub new {
my $class = shift;
my $self = {
string => shift,
result => 'null'
};
bless $self, $class;
return $self;
}
sub set_string {
my ($self, $string) = @_;
$self->{string} = $string;
}
sub get_result {
my $self = shift;
return $self->{result};
}
sub random {
my $self = shift;
my $arg_len = scalar @_;
my $string = '';
my $count_odd = 0;
my $count_even = 0;
my $nested = 0;
Carp::croak(q{Arguments is less than 2 or 3})
unless $arg_len == 2 or $arg_len >= 3;
if (blessed($self)) {
$string = $self->{string} if defined($self->{string});
$string //= 'Is Empty';
($count_odd, $count_even) = @_ if ($arg_len >= 2);
($string, $count_odd, $count_even) = @_ if ($arg_len >= 3);
} else {
($string, $count_odd, $count_even) = @_ if ($arg_len >= 3);
}
my $result = $string;
my $i = 0;
# For Nested loop == 1 :
if ($nested == 1) {
if ($count_odd != 0 and $count_even != 0) {
$i = 0;
while ($i < $count_odd) {
$result = $self->_union_odd_even($string);
$i++;
}
}
if ($count_odd != 0 and $count_even == 0) {
$i = 0;
( run in 1.796 second using v1.01-cache-2.11-cpan-39bf76dae61 )