This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add note about scope in strict docs
[perl5.git] / cpan / libnet / t / pop3_ipv6.t
CommitLineData
2e173144
CBW
1#!perl
2
3use 5.008001;
4
5use strict;
6use warnings;
7
8use Config;
9use File::Temp 'tempfile';
10use Net::POP3;
11use Test::More;
12
13my $debug = 0; # Net::POP3->new( Debug => .. )
14
15my $inet6class = Net::POP3->can_inet6;
16plan skip_all => "no IPv6 support found in Net::POP3" if ! $inet6class;
17
18plan skip_all => "fork not supported on this platform"
19 unless $Config::Config{d_fork} || $Config::Config{d_pseudofork} ||
20 (($^O eq 'MSWin32' || $^O eq 'NetWare') and
21 $Config::Config{useithreads} and
22 $Config::Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/);
23
24my $srv = $inet6class->new(
25 LocalAddr => '::1',
26 Listen => 10
27);
28plan skip_all => "cannot create listener on ::1: $!" if ! $srv;
29my $saddr = "[".$srv->sockhost."]".':'.$srv->sockport;
162b417c 30note("server on $saddr");
2e173144
CBW
31
32plan tests => 1;
33
34defined( my $pid = fork()) or die "fork failed: $!";
35exit(pop3_server()) if ! $pid;
36
37my $cl = Net::POP3->new($saddr, Debug => $debug);
162b417c 38note("created Net::POP3 object");
2e173144
CBW
39if (!$cl) {
40 fail("IPv6 POP3 connect failed");
41} else {
42 $cl->quit;
43 pass("IPv6 success");
44}
45wait;
46
47sub pop3_server {
48 my $cl = $srv->accept or die "accept failed: $!";
49 print $cl "+OK localhost ready\r\n";
50 while (<$cl>) {
51 my ($cmd,$arg) = m{^(\S+)(?: +(.*))?\r\n} or die $_;
52 $cmd = uc($cmd);
53 if ($cmd eq 'QUIT' ) {
54 print $cl "+OK bye\r\n";
55 last;
56 } elsif ( $cmd eq 'CAPA' ) {
57 print $cl "+OK\r\n".
a4f8ff46 58 ".\r\n";
2e173144
CBW
59 } else {
60 diag("received unknown command: $cmd");
61 print "-ERR unknown cmd\r\n";
62 }
63 }
64
162b417c 65 note("POP3 dialog done");
2e173144 66}