File Coverage

blib/lib/POE/Component/SSLify/ClientHandle.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 6 66.6
condition n/a
subroutine 5 5 100.0
pod n/a
total 30 32 93.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of POE-Component-SSLify
3             #
4             # This software is copyright (c) 2014 by Apocalypse.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9 13     13   51 use strict; use warnings;
  13     13   17  
  13         410  
  13         52  
  13         18  
  13         745  
10             package POE::Component::SSLify::ClientHandle;
11             $POE::Component::SSLify::ClientHandle::VERSION = '1.012';
12             our $AUTHORITY = 'cpan:APOCAL';
13              
14             # ABSTRACT: Client-side handle for SSLify
15              
16             # Import the SSL death routines
17 13     13   53 use Net::SSLeay 1.36 qw( die_now die_if_ssl_error );
  13         173  
  13         581  
18              
19             # We inherit from ServerHandle
20 13     13   5601 use parent 'POE::Component::SSLify::ServerHandle';
  13         3144  
  13         62  
21              
22             # Override TIEHANDLE because we create a CTX
23             sub TIEHANDLE {
24 29     29   62 my ( $class, $socket, $version, $options, $ctx, $connref ) = @_;
25              
26             # create a context, if necessary
27 29 100       81 if ( ! defined $ctx ) {
28 3         11 $ctx = POE::Component::SSLify::_createSSLcontext( undef, undef, $version, $options );
29             }
30              
31 29 50       278 my $ssl = Net::SSLeay::new( $ctx ) or die_now( "Failed to create SSL $!" );
32              
33 29         56 my $fileno = fileno( $socket );
34              
35 29         114 Net::SSLeay::set_fd( $ssl, $fileno ); # Must use fileno
36              
37             # Socket is in non-blocking mode, so connect() will return immediately.
38             # die_if_ssl_error won't die on non-blocking errors. We don't need to call connect()
39             # again, because OpenSSL I/O functions (read, write, ...) can handle that entirely
40             # by self (it's needed to connect() once to determine connection type).
41 29 50       2740 my $res = Net::SSLeay::connect( $ssl ) or die_if_ssl_error( 'ssl connect' );
42              
43 29         226 my $self = bless {
44             'ssl' => $ssl,
45             'ctx' => $ctx,
46             'socket' => $socket,
47             'fileno' => $fileno,
48             'client' => 1,
49             'status' => $res,
50             'on_connect' => $connref,
51             }, $class;
52              
53 29         234 return $self;
54             }
55              
56             1;
57              
58             __END__