Clean up Crypt::SSLeay::MainContext
I don't even know why there was a home-made import method in that package.
Also got rid of a couple of package globals.
A. Sinan Unur
9 years ago
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use Carp (); |
6 | use Exporter qw ( import ); | |
7 | ||
8 | use vars qw( @EXPORT @EXPORT_OK ); | |
9 | @EXPORT = (); | |
10 | @EXPORT_OK = qw( main_ctx ); | |
6 | 11 | |
7 | 12 | require Crypt::SSLeay::CTX; |
8 | 13 | |
33 | 38 | ) |
34 | 39 | ); |
35 | 40 | |
36 | my $ctx = &main_ctx(); | |
37 | ||
38 | 41 | sub main_ctx { |
39 | 42 | my $ctx = Crypt::SSLeay::CTX->new( |
40 | defined $ENV{CRYPT_SSLEAY_ALLOW_SSLv3} | |
43 | $ENV{CRYPT_SSLEAY_ALLOW_SSLv3} ? 1 : 0 | |
41 | 44 | ); |
42 | 45 | |
43 | 46 | if ($ENV{CRYPT_SSLEAY_CIPHER}) { |
51 | 54 | $ctx; |
52 | 55 | } |
53 | 56 | |
54 | my %sub_cache = ('main_ctx' => \&main_ctx ); | |
55 | ||
56 | sub import { | |
57 | my $pkg = shift; | |
58 | my $callpkg = caller(); | |
59 | my @func = @_; | |
60 | for (@func) { | |
61 | s/^&//; | |
62 | Carp::croak("Can't export $_ from $pkg") if /\W/;; | |
63 | my $sub = $sub_cache{$_}; | |
64 | unless ($sub) { | |
65 | my $method = $_; | |
66 | $method =~ s/^main_ctx_//; # optional prefix | |
67 | $sub = $sub_cache{$_} = sub { $ctx->$method(@_) }; | |
68 | } | |
69 | no strict 'refs'; | |
70 | *{"${callpkg}::$_"} = $sub; | |
71 | } | |
72 | } | |
73 | ||
74 | 57 | 1; |