| 1 | package Iterator::Flex::Grep; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Grep Iterator Class | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use v5.28; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.33'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Iterator::Flex::Factory 'to_iterator'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Iterator::Flex::Utils qw[ THROW STATE EXHAUSTION :IterAttrs :IterStates ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Ref::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use parent 'Iterator::Flex::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | ▶ | sub new ( $class, $code, $iterable, $pars = {} ) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | throw_failure( parameter => q{'code' parameter is not a coderef} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | unless Ref::Util::is_coderef( $code ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | $class->SUPER::new( { code => $code, src => $iterable }, $pars ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ▶ | sub construct ( $class, $state ) { | |||||||||||||||||||||||||||
|
Subroutine
construct: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 7 | ▶ | throw_failure( parameter => q{'state' parameter must be a HASH reference} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | unless Ref::Util::is_hashref( $state ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 7 | my ( $code, $src ) = @{$state}{qw[ code src ]}; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | $src | |||||||||||||||||||||||||||
| 62 | = to_iterator( $src, { ( +EXHAUSTION ) => THROW } ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | my $self; | |||||||||||||||||||||||||||
| 65 | my $iterator_state; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | return { | ||||||||||||||||||||||||||||
| 68 | ( +_NAME ) => 'igrep', | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | ( +_SELF ) => \$self, | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | ( +STATE ) => \$iterator_state, | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | ( +NEXT ) => sub { | ||||||||||||||||||||||||||||
| 75 | 24 | ▶ | return $self->signal_exhaustion | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | if $iterator_state == IterState_EXHAUSTED; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | my $ret = eval { | ||||||||||||||||||||||||||||
| 79 | 24 | while ( 1 ) { | |||||||||||||||||||||||||||
| 80 | 35 | my $rv = $src->(); | |||||||||||||||||||||||||||
| 81 | 28 | local $_ = $rv; | |||||||||||||||||||||||||||
| 82 | 28 | ▶ | return $rv if $code->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | 1; | |||||||||||||||||||||||||||
| 85 | 24 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 7 | ▶ | die $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@)
$@->isa("Iterator::Flex::Failure::Exhausted")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
| |||||||||||||||||||||||||||||
| 87 | unless Ref::Util::is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||
| 88 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||
| 89 | 7 | return $self->signal_exhaustion; | |||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||
| 91 | 17 | return $ret; | |||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||
| 93 | ▶ | ( +RESET ) => sub { }, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 7 | ( +_DEPENDS ) => $src, | |||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | __PACKAGE__->_add_roles( qw[ | |||||||||||||||||||||||||||
| 99 | State::Closure | ||||||||||||||||||||||||||||
| 100 | Next::ClosedSelf | ||||||||||||||||||||||||||||
| 101 | Rewind::Closure | ||||||||||||||||||||||||||||
| 102 | Reset::Closure | ||||||||||||||||||||||||||||
| 103 | Current::Closure | ||||||||||||||||||||||||||||
| 104 | ] ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 5 | 1; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # | ||||||||||||||||||||||||||||
| 109 | # This file is part of Iterator-Flex | ||||||||||||||||||||||||||||
| 110 | # | ||||||||||||||||||||||||||||
| 111 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||
| 113 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||
| 115 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | __END__ | ||||||||||||||||||||||||||||