Current Issues with perlipc.pod - should they be fixed?

[email protected] (Shlomi Fish) Fri, 3 Dec 2010 14:49:31 +0200
Newsgroups perl.perl5.porters,perl.documentation
Message-ID <[email protected]>
Hi all,

after I posted my series of patches to perlipc.pod , I saw that tchrist pos=
ted=20
his version, which got accepted immediately. As a downside to that, I'll ha=
ve=20
to restart my work. However, I noticed that perlipc.pod still has many=20
perceived issues. Here is a list of things I noticed:

* =ABdefined($Config{sig_name})  || die "No sigs?"; =BB

Shouldn't it be using "or" instead of "||" or maybe an if?

*=20
<<<
foreach $name (split(" ", $Config{sig_name})) {
        $signo{$name} =3D $i;
        $signame[$i]  =3D $name;
        $i++;
    }
>>>

"foreach my $name" (Gotta practice what we preach). Furthermore, someone sa=
id=20
we should recommend using a CPAN module for that instead.

* unless (kill(0 =3D> $pid) || $!{EPERM}) {
        warn "$pid looks dead";
    }

unless and and ||? That's a bit confusing.

*=20

<<<
my $ALARM_EXCEPTION =3D "alarm clock restart";
    eval {
        local $SIG{ALRM} =3D sub { die $ALARM_EXCEPTION };
        alarm 10;
        flock(FH, 2)    # blocking write lock
                        || die "cannot flock: $!";
        alarm 0;
    };
    if ($@ && $@ !~ quotemeta($ALARM_EXCEPTION)) { die }
>>>

Non-lexical filehandle.

*=20

<<<
# system return val is backwards, so && not ||
#
$ENV{PATH} .=3D ":/etc:/usr/etc";
    if  (      system("mknod",  $path, "p")
            && system("mkfifo", $path) )
    {
        die "mk{nod,fifo} $path failed";
    }
>>>

We probably want local $ENV{PATH} here, and can't we expect the mkfifo syst=
em=20
call to work globally already?

*=20
<<<
 chdir();    # go home
    my $FIFO =3D ".signature";

    while (1) {
        unless (-p $FIFO) {
            unlink $FIFO;   # discard any failure, will catch later
            require POSIX;  # delayed loading of heavy module
            POSIX::mkfifo($FIFO, 0700)
                                || die "can't mkfifo $FIFO: $!";
        }

        # next line blocks till there's a reader
        open (FIFO, "> $FIFO")  || die "can't open $FIFO: $!";
        print FIFO "John Smith (smith\@host.org)\n", `fortune -s`;
        close(FIFO)             || die "can't close $FIFO: $!";
        sleep 2;                # to avoid dup signals
    }
>>>

Bareword filehandle, and 2-args open and || instead of or. I won't mention=
=20
bareword filehandles again, but the exist in many other places.

*=20
<<<
	use FileHandle;
    use IPC::Open2;
    $pid =3D open2(*Reader, *Writer, "cat -un");
    print Writer "stuff\n";
    $got =3D <Reader>;
>>>

We need to make it use strict friendly.

*=20
<<<
 #!/usr/bin/perl -w
>>>

use warnings instead of "-w".

*

<<<
my ($remote, $port, $iaddr, $paddr, $proto, $line);

    $remote  =3D shift || "localhost";
    $port    =3D shift || 2345;  # random port
    if ($port =3D~ /\D/) { $port =3D getservbyname($port, "tcp") }
    die "No port" unless $port;
    $iaddr   =3D inet_aton($remote)       || die "no host: $remote";
>>>
we should declare the variables at first assignment instead of all in one=20
place.

*=20
Shouldn't the example use IO::Socket and friends?

*
<<<
And here's a multithreaded version.  It's multithreaded in that
like most typical servers, it spawns (fork()s) a slave server to
handle the client request so that the master server can quickly
go back to service a new client.
>>>

The term "multithreaded" is misleading it. It is multi-processed - not=20
multithreaded, because it does not use threads.

*=20
<<<
Section 5 of CPAN's F<modules> file is devoted to "Networking, Device
Control (modems), and Interprocess Communication", and contains numerous
unbundled modules numerous networking modules, Chat and Expect operations,
CGI programming, DCE, FTP, IPC, NNTP, Proxy, Ptty, RPC, SNMP, SMTP, Telnet,
Threads, and ToolTalk--to name just a few.
>>>

We should no longer mention that modules file.

Should I send patches to correct all these issues (because the Perl=20
documentation should represent the best practices)? And I hope that this ti=
me=20
all my work will not be for naught again.

Regards,

	Shlomi Fish

=2D-=20
=2D----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .