| 1 | package Role::TinyCommons::Collection::FindItem::Iterator; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Role::Tiny::With; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 7 | 1 | our $DATE = '2024-01-16'; # DATE | |||||||||
| 8 | 1 | our $DIST = 'Role-TinyCommons-Collection'; # DIST | |||||||||
| 9 | 1 | our $VERSION = '0.010'; # VERSION | |||||||||
| 10 | |||||||||||
| 11 | ### implements | ||||||||||
| 12 | |||||||||||
| 13 | 1 | with 'Role::TinyCommons::Collection::FindItem'; | |||||||||
| 14 | |||||||||||
| 15 | ### requires | ||||||||||
| 16 | |||||||||||
| 17 | 1 | requires 'each_item'; | |||||||||
| 18 | |||||||||||
| 19 | ### optionally depends | ||||||||||
| 20 | # 'cmp_items'; # Role::TinyCommons::Collection::CompareItems | ||||||||||
| 21 | |||||||||||
| 22 | ### provides | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub find_item { | ||||||||
|
Subroutine
find_item: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 25 | 0 | my ($self, %args) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $search_item = $args{item}; | |||||||||
| 28 | 0 | my $return_pos = $args{return_pos}; | |||||||||
| 29 | 0 | my $all = $args{all}; | |||||||||
| 30 | |||||||||||
| 31 | 0 | my @results; | |||||||||
| 32 | 0 | ▶ | if ($self->can('cmp_items')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | $self->each_item( | ||||||||||
| 34 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 35 | 0 | my ($iter_item, $obj, $pos) = @_; | |||||||||
| 36 | 0 | ▶ | if ($obj->cmp_items($iter_item, $search_item) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | ▶ | push @results, $return_pos ? $pos : $iter_item; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | ▶ | return 0 unless $all; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | 0 | 1; | |||||||||
| 41 | 0 | }); | |||||||||
| 42 | } else { | ||||||||||
| 43 | $self->each_item( | ||||||||||
| 44 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 45 | 0 | my ($iter_item, $obj, $pos) = @_; | |||||||||
| 46 | 0 | ▶ | if (($iter_item cmp $search_item) == 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | ▶ | push @results, $return_pos ? $pos : $iter_item; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | return 0 unless $all; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | } | ||||||||||
| 50 | 0 | 1; | |||||||||
| 51 | 0 | }); | |||||||||
| 52 | } | ||||||||||
| 53 | 0 | @results; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | 1; | |||||||||
| 57 | # ABSTRACT: Provides find_item() for iterators | ||||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||