Algorithm-Odometer-Tiny

 view release on metacpan or  search on metacpan

lib/Algorithm/Odometer/Gray.pm  view on Meta::CPAN

	use overload '<>' => sub {
		my $self = shift;
		return $self->() unless wantarray;
		my @all;
		while (defined( my $x = $self->() ))
			{ push @all, $x }
		return @all;
	};
	sub new {  ## no critic (RequireArgUnpacking)
		my $class = shift;
		return bless odometer_gray(@_), $class;
	}
	sub odometer_gray {  ## no critic (RequireArgUnpacking)
		croak "no wheels specified" unless @_;
		my @w = @_;
		croak "all wheels must have at least two positions"
			if grep {@$_<2} @w;
		my @c = (0) x @w;
		my @f =  0 .. @w;
		my @o = (1) x @w;
		my $done;

lib/Algorithm/Odometer/Tiny.pm  view on Meta::CPAN

	use overload '<>' => sub {
		my $self = shift;
		return $self->() unless wantarray; 
		my @all;
		while (defined( my $x = $self->() ))
			{ push @all, $x }
		return @all;
	};
	sub new {  ## no critic (RequireArgUnpacking)
		my $class = shift;
		return bless odometer(@_), $class;
	}
	sub odometer {  ## no critic (RequireArgUnpacking)
		croak "no wheels specified" unless @_;
		my @w = map { [ 1, ref eq 'ARRAY' ? @$_ : $_ ] } @_;
		my $done;
		return sub {
			if ($done) { $done=0; return }
			my @cur = map {$$_[$$_[0]]} @w;
			for(my $i=$#w;$i>=0;$i--) {
				last if ++$w[$i][0]<@{$w[$i]};



( run in 0.487 second using v1.01-cache-2.11-cpan-de7293f3b23 )