File: API.pm

package info (click to toggle)
lemonldap-ng 1.9.7-3%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 39,024 kB
  • sloc: perl: 37,552; makefile: 922; sh: 472; sql: 5
file content (85 lines) | stat: -rw-r--r-- 2,482 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package Lemonldap::NG::Handler::API;

use Exporter 'import';

our $VERSION = '1.9.1';
our ( %EXPORT_TAGS, @EXPORT_OK, @EXPORT );
our $mode;

BEGIN {
    %EXPORT_TAGS = (
        httpCodes => [
            qw( MP OK REDIRECT HTTP_UNAUTHORIZED FORBIDDEN DONE DECLINED SERVER_ERROR AUTH_REQUIRED MAINTENANCE )
        ],
        functions => [
            qw( &hostname &remote_ip &uri &uri_with_args
              &unparsed_uri &args &method &header_in )
        ]
    );
    push( @EXPORT_OK, @{ $EXPORT_TAGS{$_} } ) foreach ( keys %EXPORT_TAGS );
    $EXPORT_TAGS{all} = \@EXPORT_OK;

    if ( exists $ENV{MOD_PERL} ) {
        if ( $ENV{MOD_PERL_API_VERSION} and $ENV{MOD_PERL_API_VERSION} >= 2 ) {
            eval 'use constant MP => 2;';
        }
        else {
            eval 'use constant MP => 1;';
        }
    }
    else {
        eval 'use constant MP => 0;';
    }

}

sub AUTOLOAD {
    my $func = $AUTOLOAD;
    $func =~ s/^.*:://;

    # Launch appropriate specific API function:
    # - Apache (modperl 2),
    # - Apache (modperl1),
    # - Nginx
    if ( !$mode or $func eq 'newRequest' ) {

        #print STDERR "FONCTION $func\n";
        #for ( my $i = 0 ; $i < 7 ; $i++ ) {
        #    print STDERR "    $i: " . ( caller($i) )[0] . "\n";
        #}
        $mode =
          (
            ( caller(1) )[0] =~
              /^Lemonldap::NG::Handler::(?:Nginx|PSGI::Server)$/
              or ( caller(6)
                and ( caller(6) )[0] =~
                /^Lemonldap::NG::Handler::(?:Nginx|PSGI::Server)$/ )
          ) ? 'PSGI/Server'
          : (
            ( caller(0) )[0] =~ /^Lemonldap::NG::Handler::PSGI/
              or (
                (
                        ( caller(6) )[0]
                    and ( ( caller(6) )[0] =~ /^Lemonldap::NG::Handler::PSGI/ )
                )
              )
          ) ? 'PSGI'
          : ( $ENV{GATEWAY_INTERFACE}
              and !( ref $_[1] eq 'Apache2::RequestRec' ) ) ? 'CGI'
          : ( MP == 2 )        ? 'ApacheMP2'
          : ( MP == 1 )        ? 'ApacheMP1'
          : $main::{'nginx::'} ? 'ExperimentalNginx'
          :                      'CGI';
        unless ( $INC{"Lemonldap/NG/Handler/API/$mode.pm"} ) {
            $mode =~ s#/#::#g;
            eval
"use Lemonldap::NG::Handler::API::$mode (':httpCodes', ':functions');";
            die $@ if ($@);
        }
        $mode =~ s#/#::#g;
    }
    shift;
    return "Lemonldap::NG::Handler::API::${mode}"->${func}(@_);
}

1;