File Coverage

blib/lib/Iterator/Flex/Role/Wrap/Self.pm
Criterion Covered Total %
statement 23 34 67.6
branch n/a
condition n/a
subroutine 8 10 80.0
pod n/a
total 31 44 70.4


line stmt bran cond sub pod time code
1             package Iterator::Flex::Role::Wrap::Self;
2              
3             # ABSTRACT: Construct a next() method for a coderef which expects to be passed an object ref
4              
5             # is this actually used?
6              
7 1     1   203510 use v5.28;
  1         5  
8 1     1   5 use strict;
  1         2  
  1         34  
9 1     1   5 use warnings;
  1         1  
  1         85  
10              
11             our $VERSION = '0.33';
12              
13 1     1   6 use Scalar::Util;
  1         2  
  1         57  
14 1     1   575 use Iterator::Flex::Utils 'NEXT';
  1         3  
  1         165  
15              
16 1     1   633 use Role::Tiny;
  1         7233  
  1         8  
17 1     1   305 use experimental 'signatures';
  1         3  
  1         22  
18              
19 1     1   898 use namespace::clean;
  1         29363  
  1         9  
20              
21 0     0     sub _construct_next ( $, $ipar, $ ) {
  0            
  0            
22              
23             # ensure we don't hold any strong references in the subroutine
24 0           my $next = $ipar->{ +NEXT };
25 0           Scalar::Util::weaken $next;
26              
27 0           my $sub;
28 0     0     $sub = sub { $next->( $sub ) };
  0            
29              
30             # create a second reference to the subroutine before we weaken $sub,
31             # otherwise $sub will lose its contents, as it would be the only
32             # reference.
33 0           my $rsub = $sub;
34 0           Scalar::Util::weaken( $sub );
35 0           return $rsub;
36             }
37              
38             1;
39              
40             #
41             # This file is part of Iterator-Flex
42             #
43             # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
44             #
45             # This is free software, licensed under:
46             #
47             # The GNU General Public License, Version 3, June 2007
48             #
49              
50             __END__