File Coverage

blib/lib/AnyEvent/Ident/Request.pm
Criterion Covered Total %
statement 22 23 95.6
branch 7 8 87.5
condition 6 9 66.6
subroutine 7 7 100.0
pod 3 4 75.0
total 45 51 88.2


line stmt bran cond sub pod time code
1             package AnyEvent::Ident::Request;
2              
3 5     5   34035 use strict;
  5         7  
  5         153  
4 5     5   21 use warnings;
  5         5  
  5         113  
5 5     5   17 use Carp qw( croak );
  5         7  
  5         1170  
6              
7             # ABSTRACT: Simple asynchronous ident response
8             our $VERSION = '0.07'; # VERSION
9              
10             sub new
11             {
12 15     15 0 635 my $class = shift;
13 15         36 my $self = bless {}, $class;
14 15 100       42 if(@_ == 1)
    50          
15             {
16 12         31 my $raw = $self->{raw} = shift;
17 12 100       56 if($raw =~ /^\s*(\d+)\s*,\s*(\d+)\s*$/)
18             {
19 10 100 33     370 croak "invalid port" if $1 == 0 || $2 == 0
      66        
      100        
20             || $1 > 65535 || $2 > 65535;
21 8         29 ($self->{server_port}, $self->{client_port}) = ($1, $2);
22             }
23             else
24             {
25 2         286 croak "bad request: $raw";
26             }
27             }
28             elsif(@_ == 2)
29             {
30 3         20 $self->{raw} = join(',', ($self->{server_port}, $self->{client_port}) = @_);
31             }
32             else
33             {
34 0         0 croak 'usage: AnyEvent::Ident::Request->new( [ $raw | $server_port, $client_port ] )';
35             }
36 11         24 $self;
37             }
38              
39              
40 17     17 1 831 sub server_port { shift->{server_port} }
41 14     14 1 79 sub client_port { shift->{client_port} }
42 2     2 1 5 sub as_string { shift->{raw} }
43              
44             1;
45              
46             __END__