| 1 | package Linux::Perl; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Linux::Perl - Linux system calls with pure Perl | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | my $efd = Linux::Perl::eventfd->new(); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #...or, if you know your architecture: | ||||||||||||||||||||||||||||
| 14 | my $efd = Linux::Perl::eventfd::x86_64->new(); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | In memory-sensitive environments it is useful to minimize the number | ||||||||||||||||||||||||||||
| 19 | of XS modules that Perl loads. Oftentimes the CPAN modules that implement | ||||||||||||||||||||||||||||
| 20 | support for various Linux system calls, though, will bring in XS for the | ||||||||||||||||||||||||||||
| 21 | sake of writing platform-neutral code. | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Linux::Perl accommodates use cases where platform neutrality is less of | ||||||||||||||||||||||||||||
| 24 | a concern than minimizing memory usage. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 MODULES | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Each family of system calls lives in its own namespace under C<Linux::Perl>: | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =over | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =item * L<Linux::Perl::epoll> | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =item * L<Linux::Perl::inotify> | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =item * L<Linux::Perl::eventfd> | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item * L<Linux::Perl::getrandom> | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item * L<Linux::Perl::timerfd> | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item * L<Linux::Perl::memfd> | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item * L<Linux::Perl::signalfd> | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item * L<Linux::Perl::sigprocmask> | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item * L<Linux::Perl::aio> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item * L<Linux::Perl::uname> | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item * L<Linux::Perl::getdents> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =item * L<Linux::Perl::mq> | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =back | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | The distribution contains a number of other modules, none of which is | ||||||||||||||||||||||||||||
| 59 | currently intended for outside use. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 PLATFORM-SPECIFIC INVOCATION | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Each Linux::Perl system call implementation can be called with a | ||||||||||||||||||||||||||||
| 64 | platform-neutral syntax as well as with a platform-specific one; | ||||||||||||||||||||||||||||
| 65 | for example: | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | my $efd = Linux::Perl::eventfd->new(); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | my $efd = Linux::Perl::eventfd::x86_64->new(); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | The platform-specific call is a bit lighter because it avoids loading | ||||||||||||||||||||||||||||
| 72 | L<Config> to determine the current platform. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 PLATFORM SUPPORT | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | C<x86_64> and C<arm> are the best-supported platforms. C<i686> and C<i386> | ||||||||||||||||||||||||||||
| 77 | also have some support. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Support for adding new platforms just involves adding new modules with the | ||||||||||||||||||||||||||||
| 80 | necessary constants to the distribution. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Note also that a 64-bit Perl is generally assumed. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 35 | ▶ | use Linux::Perl::X (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 35 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 35 | our @_TOLERATE_ERRNO; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 169 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 169 | local $!; | |||||||||||||||||||||||||||
| 97 | 169 | my $ok = syscall(0 + $_[0], @_[1 .. $#_]); | |||||||||||||||||||||||||||
| 98 | 169 | ▶ | if ($ok == -1 && !grep { $_ == $! } @_TOLERATE_ERRNO) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok == -1 and not grep({$_ == $!;} @Linux::Perl::_TOLERATE_ERRNO)
MC/DC0%0/2
$ok == -1 and not grep({$_ == $!;} @Linux::Perl::_TOLERATE_ERRNO)
$ok == -1
not grep({$_ == $!;} @Linux::Perl::_TOLERATE_ERRNO)
Truth table66%2/3
A and not(B)
A= $ok == -1B= not grep({$_ == $!;} @Linux::Perl::_TOLERATE_ERRNO)
| |||||||||||||||||||||||||||||
| 99 | 0 | die Linux::Perl::X->create('Call', $_[0], $!); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 169 | return $ok; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 REPOSITORY | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | L<https://github.com/FGasper/p5-Linux-Perl> | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Felipe Gasper (FELIPE) | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Copyright 2018 by L<Gasper Software Consulting|http://gaspersoftware.com> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | This distribution is released under the same license as Perl. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 35 | 1; | |||||||||||||||||||||||||||