| 1 | |||||||||||||||
| 2 | package Net::SSLeay::OO::Constants; | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | ▶ | use Net::SSLeay; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | =head1 NAME | ||||||||||||||
| 10 | |||||||||||||||
| 11 | Net::SSLeay::OO::Constants - Importer interface to Net::SSLeay constants | ||||||||||||||
| 12 | |||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||
| 14 | |||||||||||||||
| 15 | use Net::SSLeay::OO::Constants qw(OP_ALL); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | print OP_ALL; | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||
| 20 | |||||||||||||||
| 21 | This module allows L<Net::SSLeay> constants to be explicitly imported | ||||||||||||||
| 22 | into your program. | ||||||||||||||
| 23 | |||||||||||||||
| 24 | As well as avoiding using the verbose C<&Net::SSLeay::XXXX> syntax all | ||||||||||||||
| 25 | the time, they can then be spelt as bare words. It also means that | ||||||||||||||
| 26 | instead of waiting for run-time for your misspelt Net::SSLeay | ||||||||||||||
| 27 | constants to crash your program, you find out at compile time. | ||||||||||||||
| 28 | |||||||||||||||
| 29 | Some extra constants are allowed to be imported by this module, which | ||||||||||||||
| 30 | are hard-coded for the event that Net::SSLeay doesn't export them. | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =cut | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 6 | our $VERSION = "0.01"; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 6 | our %FALLBACK; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 6 | ▶ | BEGIN { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 39 | 6 | %FALLBACK = ( | |||||||||||||
| 40 | MODE_ENABLE_PARTIAL_WRITE => 1, | ||||||||||||||
| 41 | MODE_ACCEPT_MOVING_WRITE_BUFFER => 2, | ||||||||||||||
| 42 | MODE_AUTO_RETRY => 4, | ||||||||||||||
| 43 | MODE_NO_AUTO_CHAIN => 8, | ||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 9 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=6 SCAR=21.7
| |||||||||||||||
| 48 | 9 | my $class = shift; | |||||||||||||
| 49 | 9 | my $target = caller; | |||||||||||||
| 50 | 9 | ▶ | while ( my $thingy = shift ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | 8 | ▶ | if ( $thingy =~ m{^\d+} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 6 | ▶ | no warnings "numeric"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | 0 | ▶ | die "insufficient version $thingy" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | if 0 + $thingy < 0 + $VERSION; | ||||||||||||||
| 55 | } | ||||||||||||||
| 56 | else { | ||||||||||||||
| 57 | 6 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 58 | 8 | my $val = eval { &{"Net::SSLeay::$thingy"}() }; | |||||||||||||
| 59 | 8 | ▶ | if ( defined $val ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 60 | 0 | ▶ | *{ $target . "::" . $thingy } = sub() {$val}; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||
| 61 | } | ||||||||||||||
| 62 | elsif ( exists $FALLBACK{$thingy} ) { | ||||||||||||||
| 63 | 0 | $val = $FALLBACK{$thingy}; | |||||||||||||
| 64 | 0 | ▶ | *{ $target . "::" . $thingy } = sub() { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 65 | 0 | $val; | |||||||||||||
| 66 | 0 | }; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | else { | ||||||||||||||
| 69 | 0 | die | |||||||||||||
| 70 | "tried to import '$thingy', but SSLeay said: $@"; | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | } | ||||||||||||||
| 73 | } | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 6 | 1; | |||||||||||||
| 77 | |||||||||||||||
| 78 | __END__ | ||||||||||||||