X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq8.pod;h=8682b4d45a1a7040c8d1bfffb8797a6c2fbeda36;hb=589a5df2575124305cbb6773b00c1d338c9b8553;hp=95305249cd76910243e6a335d8bad1474198a245;hpb=e1d16ab77edac901d7fbfed3aa4b801de9f3325e;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq8.pod b/pod/perlfaq8.pod index 9530524..8682b4d 100644 --- a/pod/perlfaq8.pod +++ b/pod/perlfaq8.pod @@ -1009,31 +1009,42 @@ perform these actions for you. =head2 How do I find out if I'm running interactively or not? -Good question. Sometimes C<-t STDIN> and C<-t STDOUT> can give clues, -sometimes not. - - if (-t STDIN && -t STDOUT) { - print "Now what? "; - } - -On POSIX systems, you can test whether your own process group matches -the current process group of your controlling terminal as follows: +(contributed by brian d foy) - use POSIX qw/getpgrp tcgetpgrp/; +This is a difficult question to answer, and the best answer is +only a guess. What do you really want to know? If you merely +want to know if one of your filehandles is connected to a terminal, +you can try the C<-t> file test: - # Some POSIX systems, such as Linux, can be - # without a /dev/tty at boot time. - if (!open(TTY, "/dev/tty")) { - print "no tty\n"; - } else { - $tpgrp = tcgetpgrp(fileno(*TTY)); - $pgrp = getpgrp(); - if ($tpgrp == $pgrp) { - print "foreground\n"; - } else { - print "background\n"; + if( -t STDOUT ) { + print "I'm connected to a terminal!\n"; + } + +However, you might be out of luck if you expect that means there is a +real person on the other side. With the C module, another +program can pretend to be a person. The program might even come close +to passing the Turing test. + +The C module does the best it can to give you an +answer. Its C function returns an output filehandle; +that filehandle points to standard output if the module thinks the +session is interactive. Otherwise, the filehandle is a null handle +that simply discards the output: + + use IO::Interactive; + + print { is_interactive } "I might go to standard output!\n"; + +This still doesn't guarantee that a real person is answering your +prompts or reading your output. + +If you want to know how to handle automated testing for your +distribution, you can check the environment. The CPAN +Testers, for instance, set the value of C: + + unless( $ENV{AUTOMATED_TESTING} ) { + print "Hello interactive tester!\n"; } - } =head2 How do I timeout a slow event? @@ -1173,50 +1184,44 @@ might not be perl's message. =head2 How do I install a module from CPAN? -The easiest way is to have a module also named CPAN do it for you. -This module comes with perl version 5.004 and later. - - $ perl -MCPAN -e shell - - cpan shell -- CPAN exploration and modules installation (v1.59_54) - ReadLine support enabled - - cpan> install Some::Module - -To manually install the CPAN module, or any well-behaved CPAN module -for that matter, follow these steps: - -=over 4 - -=item 1 - -Unpack the source into a temporary area. +(contributed by brian d foy) -=item 2 +The easiest way is to have a module also named CPAN do it for you by using +the C command the comes with Perl. You can give it a list of modules +to install: - perl Makefile.PL + $ cpan IO::Interactive Getopt::Whatever -=item 3 +If you prefer C, it's just as easy: - make + $ cpanp i IO::Interactive Getopt::Whatever + +If you want to install a distribution from the current directory, you can +tell C to install C<.> (the full stop): -=item 4 + $ cpan . - make test +See the documentation for either of those commands to see what else +you can do. -=item 5 +If you want to try to install a distribution by yourself, resolving +all dependencies on your own, you follow one of two possible build +paths. - make install +For distributions that use I: -=back + $ perl Makefile.PL + $ make test install + +For distributions that use I: -If your version of perl is compiled without dynamic loading, then you -just need to replace step 3 (B) with B and you will -get a new F binary with your extension linked in. + $ perl Build.PL + $ ./Build test + $ ./Build install -See L for more details on building extensions. -See also the next question, "What's the difference between require -and use?". +Some distributions may need to link to libraries or other third-party +code and their build and installation sequences may be more complicated. +Check any I or I files that you may find. =head2 What's the difference between require and use? @@ -1280,7 +1285,7 @@ You can configure CPAN.pm to automatically use this option too: INSTALL_BASE tells these tools to put your modules into F. See L for details on how to run your newly -installed moudles. +installed modules. There is one caveat with INSTALL_BASE, though, since it acts differently than the PREFIX and LIB settings that older versions of