File Coverage

blib/lib/AnyEvent/Finger/Request.pm
Criterion Covered Total %
statement 27 27 100.0
branch 14 16 87.5
condition n/a
subroutine 11 11 100.0
pod 7 7 100.0
total 59 61 96.7


line stmt bran cond sub pod time code
1             package AnyEvent::Finger::Request;
2              
3 6     6   67710 use strict;
  6         17  
  6         172  
4 6     6   30 use warnings;
  6         13  
  6         298  
5 6     6   1230 use overload '""' => sub { shift->as_string };
  6     12   956  
  6         46  
  12         74  
6              
7             # ABSTRACT: Simple asynchronous finger request
8             our $VERSION = '0.11'; # VERSION
9              
10              
11             sub new
12             {
13 28     28 1 23296 bless { raw => "$_[1]" }, $_[0];
14             }
15              
16              
17             sub verbose
18             {
19 18     18 1 3296 my($self) = @_;
20 18 50       188 defined $self->{verbose} ? $self->{verbose} : $self->{verbose} = ($self->{raw} =~ /^\/W/ ? 1 : 0);
    100          
21             }
22              
23              
24             sub username
25             {
26 39     39 1 92 my($self) = @_;
27            
28 39 100       106 unless(defined $self->{username})
29             {
30 22 50       124 if($self->{raw} =~ /^(?:\/W\s*)?([^@]*)/)
31 22         71 { $self->{username} = $1 }
32             }
33            
34 39         150 $self->{username};
35             }
36              
37              
38             sub hostnames
39             {
40 54     54 1 97 my($self) = @_;
41 54 100       311 return $self->{hostnames} if defined $self->{hostnames};
42 28 100       318 $self->{hostnames} = ($self->{raw} =~ /\@(.*)$/ ? [split '@', $1] : []);
43             }
44              
45              
46             sub as_string
47             {
48 12     12 1 23 my($self) = @_;
49 12         33 join('@', ($self->username, @{ $self->hostnames }));
  12         29  
50             }
51              
52              
53 8 100   8 1 26 sub listing_request { shift->username eq '' ? 1 : 0 }
54              
55              
56              
57 23 100   23 1 43 sub forward_request { @{ shift->hostnames } > 0 ? 1 : 0}
  23         50  
58              
59             1;
60              
61             __END__