The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
  $self->{_item_list}->{$key} = $val;
  $self->{_item_key_list}->[$index] = $key;

  return ;
}

NAME

Sorauta::Util::Iterator - Simple Iterator

SYNOPSIS

  use Sorauta::Util::Iterator;
  
  my $itr = Sorauta::Util::Iterator->new;

DESCRIPTION

Sorauta::Util::Iterator is simple iterator.

METHODS

$itr->add($val);

add new value in iterator

example: my $itr = Sorauta::Util::Iterator->new;

  $itr->add('num1', { data => 1, test => "fuck" });
  $itr->add('num2', [ 'data', 1, 'test', "fuck" ]);
  $itr->add('num3', 'kurenai');
  $itr->add('num4', 109238402389);
  $itr->add('sub_ref', $sub_ref); # $sub_ref = sub { print 'hoge' };
$itr->del($key);

delete value

example: my $itr = Sorauta::Util::Iterator->new;

  $itr->del('key');
$itr->get($key);

example: my $itr = Sorauta::Util::Iterator->new;

  my $val = $itr->get('num1');
$itr->get_by_index($index);

example: my $itr = Sorauta::Util::Iterator->new;

  my $val = $itr->get_by_index(3);
$item->next

loop

example: my $itr = Sorauta::Util::Iterator->new;

  while (my $val = $itr->next) {
    print Dumper($val);
  }
$item->hasNext

current iterate position has next?

example: my $itr = Sorauta::Util::Iterator->new;

  say $itr->hasNext ? 'you have next value' : 'none';
$itr->all

get all hash data

example: my $itr = Sorauta::Util::Iterator->new;

  # get all data by array or array_ref
  my $list = $itr->all;
  or
  my @list = $itr->all;
$itr->count

get hash count

example: my $itr = Sorauta::Util::Iterator->new;

  my $count = $itr->count;
$itr->hash2itr($hashref);

hash convert to iterator

example: my $itr2 = Sorauta::Util::Iterator->new; my $hash_list = { hoge => 1, sample => 2, wieht => [1,2,3,5,55,2524352345,23], hash => {shi => 1, weoith=>"2", weotj => "hoghehoge"} }; $itr2->hash2itr($hash_list);

  while (my $val = $itr2->next) {
    print Dumper($val); #=> 1, 2, {shi=>1,...}...
  }
$itr->reset; position reset

example: my $itr = Sorauta::Util::Iterator->new; $itr->reset;

AUTHOR

Yuki ANAI, <yuki@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Yuki ANAI

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 73:

=pod directives shouldn't be over one line long! Ignoring all 3 lines of content

Around line 302:

You forgot a '=back' before '=head1'