| 1 | package HashData::Test::Spec::Basic; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 4 | 2 | our $DATE = '2021-06-01'; # DATE | |||||||||
| 5 | 2 | our $DIST = 'HashData'; # DIST | |||||||||
| 6 | 2 | our $VERSION = '0.1.1'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Role::Tiny::With; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | with 'HashDataRole::Spec::Basic'; | |||||||||
| 14 | |||||||||||
| 15 | 2 | my $hash = { | |||||||||
| 16 | five => "lima", | ||||||||||
| 17 | four => "empat", | ||||||||||
| 18 | one => "satu", | ||||||||||
| 19 | three => "tiga", | ||||||||||
| 20 | two => "dua", | ||||||||||
| 21 | }; | ||||||||||
| 22 | 2 | my $keys = [sort keys %$hash]; | |||||||||
| 23 | |||||||||||
| 24 | sub new { | ||||||||||
| 25 | 1 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | 1 | bless {pos=>0}, $class; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | sub _hash { | ||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_hash: not called CC=1 SCAR=6.9
| |||||||||||
| 31 | 0 | $hash; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub get_next_item { | ||||||||||
| 35 | 23 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_next_item: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | 23 | ▶ | die "StopIteration" unless $self->{pos} < @$keys; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 22 | my $key = $keys->[ $self->{pos}++ ]; | |||||||||
| 38 | 22 | [$key, $hash->{$key}]; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | sub has_next_item { | ||||||||||
| 42 | 20 | ▶ | my $self = shift; | ||||||||
|
Subroutine
has_next_item: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 43 | 20 | $self->{pos} < @$keys; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub get_iterator_pos { | ||||||||||
| 47 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_iterator_pos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 48 | 1 | $self->{pos}; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | sub reset_iterator { | ||||||||||
| 52 | 5 | ▶ | my $self = shift; | ||||||||
|
Subroutine
reset_iterator: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 53 | 5 | $self->{pos} = 0; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub get_item_at_key { | ||||||||||
| 57 | 2 | ▶ | my ($self, $key) = @_; | ||||||||
|
Subroutine
get_item_at_key: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 2 | ▶ | die "No such key '$key'" unless exists $hash->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 1 | $hash->{$key}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | sub has_item_at_key { | ||||||||||
| 63 | 2 | ▶ | my ($self, $key) = @_; | ||||||||
|
Subroutine
has_item_at_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | 2 | exists $hash->{$key}; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub get_all_keys { | ||||||||||
| 68 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_all_keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 69 | 1 | [@$keys]; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 2 | 1; | |||||||||
| 73 | |||||||||||
| 74 | # ABSTRACT: A test hash data | ||||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||