File Coverage

blib/lib/Hash/Iter.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package Hash::Iter;
2              
3 2     2   417681 use strict;
  2         4  
  2         80  
4 2     2   15 use warnings;
  2         14  
  2         144  
5              
6 2     2   17 use Exporter qw(import);
  2         5  
  2         505  
7              
8             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9             our $DATE = '2024-11-04'; # DATE
10             our $DIST = 'Hash-Iter'; # DIST
11             our $VERSION = '0.001'; # VERSION
12              
13             our @EXPORT_OK = qw(hash_iter pair_iter);
14              
15             sub hash_iter {
16 2     2 1 442291 my $hash = shift;
17 2         6 my $i = 0;
18              
19 2         9 my @ary = keys %$hash;
20             sub {
21 8 100   8   44 if ($i < @ary) {
22 6         14 my $key = $ary[$i++];
23 6         19 return ($key, $hash->{$key});
24             } else {
25 2         5 return ();
26             }
27 2         16 };
28             }
29              
30             sub pair_iter {
31 1     1 1 11192 hash_iter({@_});
32             }
33              
34             1;
35             # ABSTRACT: Generate a coderef iterator for a hash
36              
37             __END__