Server/AsyncEndpoint/Endpoints.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 104 CC 10 SCAR 38.9
CC
10
Cov
0%
wanted
110.0
init
2.0
BEGIN
2.0
CRAP 49.0
1 package POE::Component::Server::AsyncEndpoint::Endpoints;
2  
3 use warnings;
4 use strict;
5 our @EXPORT = qw( EP_STAT_NA EP_STAT_OK EP_STAT_WA EP_STAT_FA EP_STOPPED );
6 use base qw(Exporter);
7 use vars qw($VERSION);
8 $VERSION = '0.10';
9  
10 use constant EP_STAT_NA => 0; # not available
11 use constant EP_STAT_OK => 1; # ok
12 use constant EP_STAT_WA => 2; # waiting response
13 use constant EP_STAT_FA => 3; # fail
14 use constant EP_STOPPED => 5; # runtime stop
15  
16  
17 use File::Find;
18 use File::Util;
19  
20 use Carp qw(croak);
21  
22  
23 my @endpoints = ();
24  
25 sub init {
26 find(\&wanted, qw(.));
27 return @endpoints;
28 }
29  
30 sub wanted {
31 my $endpoints = shift @_;
32 if (/^endpoint$/) {
33  
34 my $name = $File::Find::dir;
35 my $pname = $File::Find::name;
36  
37 open(EPCONF, '<', './endpoint.conf')
38 or croak "No configuration file for Endpoint: $pname $!";
39  
40 my $ikc_addr = undef;
41 my $ikc_port = undef;
42 my $start = undef;
43  
44 while (<EPCONF>) {
45 if ($_ =~ /^\s*ikc_addr\s*=\s*([0-9a-zA-Z_.-]+)$/) {
46 $ikc_addr = $1 if defined $1;
47 }
48 if ($_ =~ /^\s*ikc_port\s*=\s*([0-9]+)$/) {
49 $ikc_port = $1 if defined $1;
50 }
51 if ($_ =~ /^\s*start\s*=\s*([01])$/) {
52 $start = $1 if defined $1;
53 $start = 0 unless $start;
54 }
55  
56 }
57  
58 close(EPCONF);
59  
60 croak "No valid ikc_addr and/or ikc_port in conf file for Endpoint: $pname"
61 unless ( (defined $ikc_addr) && (defined $ikc_port) );
62  
63 push @endpoints, {
64 name => $name,
65 pname => $pname,
66 ikc_addr => $ikc_addr,
67 ikc_port => $ikc_port,
68 stat => EP_STAT_NA,
69 retries => 0,
70 wheel => undef,
71 start => $start,
72 }
73 }
74  
75 }
76  
77 1;
78  
79 __END__