Promiser/FDFHStore.pm untested

filter: Statementstmt 0.0% 0 / 4 Branchbran n/a Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 18 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
_create
2.0
get_fh
2.0
CRAP 2.0
1 package Net::Curl::Promiser::FDFHStore;
2  
3 # Mojo::IOLoop doesn’t track FDs, just Perl filehandles. That means
4 # that, in order to track libcurl’s file descriptors, we have to
5 # create Perl filehandles for them. But we also have to ensure that
6 # those filehandles aren’t garbage-collected (GC) because GC will
7 # cause Perl to close() the file descriptors, which will break
8 # libcurl.
9 #
10 # So we keep a reference to each created socket via this object.
11 #
12 # The above problem appears to affect IO::Async as well—even if
13 # you give file descriptors to IO::Async::Loop—but does not appear
14 # to affect AnyEvent.
15  
16 sub new { bless {}, shift }
17  
18 sub _create {
19 open my $s, '+>>&=' . $_[0] or die "FD ($_[0]) to Perl FH failed: $!";
20 $s;
21 }
22  
23 sub get_fh {
24  
25 # This used to stat() to ensure that the file descriptor wasn’t closed.
26 # But even if the FD had been closed and reopened, that would be
27 # transparent to Perl. So the stat() check shouldn’t be needed.
28 return $_[0]->{ $_[1] } ||= _create( $_[1] );
29 }
30  
31 1;