| 1 | use Test::Morescip-perl cpan autobox-Core 1.33 Test/More/ qw(no_plan); |
| 2 | use strictscip-perl cpan autobox-Core 1.33 strict/; |
| 3 | use warningsscip-perl cpan autobox-Core 1.33 warnings/; |
| 4 | |
| 5 | use autobox::Corescip-perl cpan autobox-Core 1.33 autobox/Core/; |
| 6 | |
| 7 | my %hash = ( foo => 1, bar => 2, baz => 3 ); |
| 8 | |
| 9 | my @glued; |
| 10 | %hash->eachscip-perl cpan autobox-Core 1.33 main/each().( sub { pushscip-perl cpan autobox-Core 1.33 main/push(). @glued, $_scip-perl cpan autobox-Core 1.33 main/`@_`.[0] . $_scip-perl cpan autobox-Core 1.33 main/`@_`.[1] } ); |
| 11 | |
| 12 | is_deeply [ sortscip-perl cpan autobox-Core 1.33 main/sort(). @glued ], [ qw(bar2 baz3 foo1) ]; |
| 13 | |
| 14 | my @array = valuesscip-perl cpan autobox-Core 1.33 main/values(). %hash; |
| 15 | |
| 16 | my @added; |
| 17 | @array->eachscip-perl cpan autobox-Core 1.33 main/each().( sub { pushscip-perl cpan autobox-Core 1.33 main/push(). @added, $_scip-perl cpan autobox-Core 1.33 main/`@_`.[0] + 1 } ); |
| 18 | |
| 19 | is_deeply [ sortscip-perl cpan autobox-Core 1.33 main/sort(). @added ], [ qw(2 3 4) ]; |
| 20 | |
| 21 | # Ensure each() always iterates through the whole hash |
| 22 | { |
| 23 | my %want = (foo => 23, bar => 42, baz => 99, biff => 66); |
| 24 | |
| 25 | # Call each once on %want to start the iterator attached to %want |
| 26 | my($k,$v) = eachscip-perl cpan autobox-Core 1.33 main/each(). %want; |
| 27 | |
| 28 | my %have; |
| 29 | %want->eachscip-perl cpan autobox-Core 1.33 main/each().( sub { $have{$_scip-perl cpan autobox-Core 1.33 main/`@_`.[0]} = $_scip-perl cpan autobox-Core 1.33 main/`@_`.[1] } ); |
| 30 | |
| 31 | is_deeply \%have, \%want; |
| 32 | } |