File Coverage

blib/lib/POE/Component/TLSify.pm
Criterion Covered Total %
statement 45 51 88.2
branch 12 20 60.0
condition 4 6 66.6
subroutine 11 11 100.0
pod 4 4 100.0
total 76 92 82.6


line stmt bran cond sub pod time code
1             package POE::Component::TLSify;
2             $POE::Component::TLSify::VERSION = '0.08';
3             #ABSTRACT: Makes using SSL/TLS in the world of POE easy!
4              
5 11     11   2207207 use strict;
  11         102  
  11         340  
6 11     11   65 use warnings;
  11         25  
  11         416  
7              
8 11     11   65 use Symbol qw[gensym];
  11         27  
  11         570  
9 11     11   72 use Scalar::Util qw[weaken];
  11         23  
  11         592  
10 11     11   5095 use POE::Component::TLSify::ClientHandle;
  11         39  
  11         406  
11 11     11   73 use POE::Component::TLSify::ServerHandle;
  11         26  
  11         264  
12              
13 11     11   54 use parent 'Exporter';
  11         29  
  11         66  
14             our @EXPORT_OK = qw[
15             Client_TLSify Server_TLSify TLSify_GetSocket TLSify_GetCipher
16             ];
17              
18             sub Server_TLSify {
19 18     18 1 87202 my ($socket,$args,$callback) = @_;
20              
21 18 50       73 if ( ! defined $socket ) {
22 0         0 die 'Did not get a defined socket';
23             }
24              
25 18 50       230 if ( ! defined $socket->blocking( 0 ) ) {
26 0         0 die "Unable to set nonblocking mode on socket: $!";
27             }
28              
29 18 50 66     119 if ( defined $callback && ref $callback ne 'CODE' ) {
30 0         0 undef $callback;
31             }
32              
33 18         81 my $newsock = gensym();
34 18 50       440 tie( *$newsock, 'POE::Component::TLSify::ServerHandle', $socket, $args, $callback ) or die "Unable to tie to our subclass: $!";
35              
36 18 100       60 if ( defined $callback ) {
37 4         12 tied( *$newsock )->{'orig_socket'} = $newsock;
38 4         21 weaken ( tied( *$newsock )->{'orig_socket'} );
39             }
40              
41 18         61 return $newsock;
42             }
43              
44             sub Client_TLSify {
45 18     18 1 17486 my ($socket,$args,$callback) = @_;
46              
47 18 50       66 if ( ! defined $socket ) {
48 0         0 die 'Did not get a defined socket';
49             }
50              
51 18 50       191 if ( ! defined $socket->blocking( 0 ) ) {
52 0         0 die "Unable to set nonblocking mode on socket: $!";
53             }
54              
55 18 50 66     105 if ( defined $callback && ref $callback ne 'CODE' ) {
56 0         0 undef $callback;
57             }
58              
59 18         78 my $newsock = gensym();
60 18 50       453 tie( *$newsock, 'POE::Component::TLSify::ClientHandle', $socket, $args, $callback ) or die "Unable to tie to our subclass: $!";
61              
62 18 100       87 if ( defined $callback ) {
63 4         19 tied( *$newsock )->{'orig_socket'} = $newsock;
64 4         30 weaken ( tied( *$newsock )->{'orig_socket'} );
65             }
66              
67 18         67 return $newsock;
68             }
69              
70             sub TLSify_GetSocket {
71 30     30 1 9628 my $sock = shift;
72 30         195 return tied( *$sock )->{'socket'};
73             }
74              
75             sub TLSify_GetCipher {
76 62     62 1 35712 my $sock = shift;
77 62         321 return tied( *$sock )->{'socket'}->get_cipher;
78             }
79              
80             qq[I TLSify!];
81              
82             __END__