blib/lib/Sys/Pipe.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 17 / 17 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Pipe.xs ↑ Summary
1 package Sys::Pipe;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 Sys::Pipe - C<pipe2()> in Perl
11  
12 =head1 SYNOPSIS
13  
14 use Fcntl;
15 use Sys::Pipe;
16  
17 Sys::Pipe::pipe( my $r, my $w, O_NONBLOCK ) or die "pipe: $!";
18  
19 =head1 DESCRIPTION
20  
21 Ever wish you could create a pipe that starts out non-blocking?
22 Linux and a number of other OSes can do this via a proprietary C<pipe2()>
23 system call; this little library exposes that functionality to Perl.
24  
25 =head1 WHEN IS THIS USEFUL?
26  
27 As shown above, this exposes the ability to create a pipe that starts
28 out non-blocking. If that’s all you need, then the gain here is mostly just
29 tidiness. It I<is> also faster than doing:
30  
31 pipe my $r, my $w or die "pipe: $!";
32 $r->blocking(0);
33 $w->blocking(0);
34  
35 … but the above is already quite fast, so that may not make a real-world
36 difference for you.
37  
38 In Linux, this also exposes the ability to create a “packet mode” pipe.
39 Other OSes may allow similar and/or other functionality. See your
40 system’s L<pipe2(2)> for more details.
41  
42 =head1 STATUS
43  
44 This module is best considered B<EXPERIMENTAL>. If you find a problem,
45 please file a bug report. Thank you!
46  
47 =head1 SEE ALSO
48  
49 Perl’s L<socket()|perlfunc/"socket-SOCKET,DOMAIN,TYPE,PROTOCOL">
50 built-in allows similar functionality on the relevant OSes, e.g.:
51  
52 use Socket;
53  
54 socket( my $s, AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0 ) or do {
55 die "socket(): $!";
56 };
57  
58 =head1 FUNCTIONS
59  
60 =head2 $success_yn = pipe( READHANDLE, WRITEHANDLE [, FLAGS] )
61  
62 A drop-in replacement for Perl’s C<pipe()> built-in that optionally
63 accepts a numeric I<FLAGS> argument. See your system’s L<pipe2(2)>
64 documentation for what values you can pass in there.
65  
66 Note that behavior is currently B<undefined> if I<FLAGS> is nonzero on
67 any system (e.g., macOS) that lacks C<pipe2()>. (As of this writing an
68 exception is thrown; that may change eventually.)
69  
70 =cut
71  
72 2 our ($VERSION);
73  
74 2 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 $VERSION = '0.02';
78 2 XSLoader::load();
79 }
80  
81 =head2 $yn = has_pipe2()
82  
83 Returns a boolean that indicates whether the underlying system can
84 implement C<pipe2()> mechanics.
85  
86 =head1 COPYRIGHT
87  
88 Copyright 2020 Gasper Software Consulting. All rights reserved.
89  
90 =cut
91  
92 2 1;
« Pipe.xs ↑ Summary