Iterator-Flex

 view release on metacpan or  search on metacpan

lib/Iterator/Flex/Role/Next/ClosedSelf.pm  view on Meta::CPAN

package Iterator::Flex::Role::Next::ClosedSelf;

# ABSTRACT: Role for closure iterator which closes over self

use v5.28;
use strict;
use warnings;

our $VERSION = '0.34';

use Ref::Util;
use Scalar::Util;
use Iterator::Flex::Utils qw( NEXT _SELF throw_failure );

use Role::Tiny;
use experimental 'signatures';
use namespace::clean;









sub _construct_next ( $class, $ipar, $ ) {

    my $sub = $ipar->{ +NEXT } // throw_failure( parameter => q{Missing 'next' parameter} );
    Scalar::Util::weaken $ipar->{ +NEXT };

    throw_failure( parameter => q{Missing ability to set self} )
      unless exists $ipar->{ +_SELF };

    my $ref = $ipar->{ +_SELF };
    $$ref = $sub;
    Scalar::Util::weaken $$ref;
    return $sub;
}

sub next ( $self ) { &{$self}() }    ## no critic( BuiltinHomonyms )
*__next__ = \&next;

1;

#
# This file is part of Iterator-Flex
#
# This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
#
# This is free software, licensed under:
#
#   The GNU General Public License, Version 3, June 2007
#

__END__

=pod

=for :stopwords Diab Jerius Smithsonian Astrophysical Observatory

=head1 NAME

Iterator::Flex::Role::Next::ClosedSelf - Role for closure iterator which closes over self

=head1 VERSION

version 0.34

=head1 METHODS



( run in 0.913 second using v1.01-cache-2.11-cpan-e93a5daba3e )