File Coverage

blib/lib/Net/TCP/Server.pm
Criterion Covered Total %
statement 18 46 39.1
branch 0 24 0.0
condition 0 33 0.0
subroutine 6 10 60.0
pod 2 4 50.0
total 26 117 22.2


line stmt bran cond sub pod time code
1             # Copyright 1997,2002 Spider Boardman.
2             # All rights reserved.
3             #
4             # Automatic licensing for this software is available. This software
5             # can be copied and used under the terms of the GNU Public License,
6             # version 1 or (at your option) any later version, or under the
7             # terms of the Artistic license. Both of these can be found with
8             # the Perl distribution, which this software is intended to augment.
9             #
10             # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11             # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12             # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13              
14             # rcsid: "@(#) $Id: Server.dat,v 1.16 2002/03/30 10:11:36 spider Exp $"
15              
16             package Net::TCP::Server;
17 1     1   1180 use 5.004_04;
  1         4  
  1         50  
18              
19 1     1   7 use strict;
  1         1  
  1         214  
20             #use Carp;
21 0     0 0   sub carp { require Carp; goto &Carp::carp; }
  0            
22 0     0 0   sub croak { require Carp; goto &Carp::croak; }
  0            
23 1     1   6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  1         3  
  1         131  
24              
25             BEGIN {
26 1     1   3 $VERSION = '1.0';
27 1         1700 eval "sub Version () { __PACKAGE__ . ' v$VERSION' }";
28             }
29              
30             #use AutoLoader;
31             #use Exporter (); # we inherit what we need here from Net::Gen
32             #use Net::Inet;
33             #use Net::Gen;
34 1     1   9 use Net::TCP 1.0;
  1         34  
  1         173  
35              
36              
37             BEGIN {
38 1     1   24 @ISA = 'Net::TCP';
39              
40             # Items to export into callers namespace by default
41             # (move infrequently used names to @EXPORT_OK below)
42 1         2 @EXPORT = qw(
43             );
44              
45             # Other items we are prepared to export if requested
46 1         2 @EXPORT_OK = qw(
47             );
48              
49             # Tags:
50 1         433 %EXPORT_TAGS = (
51             ALL => [@EXPORT, @EXPORT_OK],
52             );
53             # *AUTOLOAD = \$Net::Gen::AUTOLOAD;
54             }
55              
56             # sub AUTOLOAD inherited from Net::Gen (via Net::TCP)
57              
58             # However, since 5.003_96 will make simple subroutines not inherit AUTOLOAD...
59             #sub AUTOLOAD
60             #{
61             # #$Net::Gen::AUTOLOAD = $AUTOLOAD;
62             # goto &Net::Gen::AUTOLOAD;
63             #}
64              
65              
66             # Preloaded methods go here. Autoload methods go after __END__, and are
67             # processed by the autosplit program.
68              
69             # Can't autoload routines which we could get without autoloading by
70             # inheritance, so new() and init() have to be here.
71              
72             #& new(classname, [[hostspec,] service,] [\%params]) : {$self | undef}
73             sub new : locked
74             {
75 0     0 1   $_[0]->_trace(\@_,1);
76 0           my ($xclass, @Args) = @_;
77 0 0 0       if (@Args == 2 && ref $Args[1] && ref($Args[1]) eq 'HASH' or
      0        
      0        
      0        
78             @Args == 1 and not ref $Args[0]) {
79 0           unshift(@Args, undef); # thishost spec
80             }
81 0           my $self = $xclass->SUPER::new(@Args);
82 0 0         return undef unless $self;
83 0           $self->setparams({reuseaddr => 1}, -1);
84 0 0         $xclass = ref $xclass if ref $xclass;
85 0 0         if ($xclass eq __PACKAGE__) {
86 0 0         unless ($self->init(@Args)) {
87 0           local $!; # protect returned errno value
88 0           undef $self; # against excess closes in perl core
89 0           undef $self; # another statement needed for sequencing
90             }
91             }
92 0           $self;
93             }
94              
95             #& init($self, [@stuff]) : {$self | undef}
96             sub init : locked method
97             {
98 0     0 1   my ($self, @Args) = @_;
99 0 0 0       if (@Args == 2 && ref $Args[1] && ref $Args[1] eq 'HASH' or
      0        
      0        
      0        
100             @Args == 1 and not ref $Args[0]) {
101 0           unshift(@Args, undef); # thishost spec
102             }
103 0 0         return undef unless $self->_hostport('this',\@Args);
104 0 0         return undef unless $self->SUPER::init;
105 0 0 0       if ($self->getparam('srcaddrlist') && !$self->isbound) {
106 0 0         return undef unless $self->bind;
107             }
108 0 0 0       if ($self->isbound && !$self->didlisten) {
109 0 0 0       return undef unless $self->isconnected or $self->listen;
110             }
111 0           $self;
112             }
113              
114             # maybe someday add some fork+accept handling here?
115              
116             1;
117              
118             # autoloaded methods go after the END token (& pod) below
119              
120             __END__