Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.144.94.143
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : Mixin.pm
use 5.006;
use strict;
use warnings;

package Test::Net::LDAP::Mixin;

use Net::LDAP;
use Net::LDAP::Constant;
use Test::Builder;
use Test::Net::LDAP::Util;

for my $method (qw(search compare add modify delete moddn bind unbind abandon)) {
    no strict 'refs';
    
    *{__PACKAGE__.'::'.$method.'_ok'} = sub {
        my $self = shift;
        local $Test::Builder::Level = $Test::Builder::Level + 1;
        return $self->method_ok($method, @_);
    };
    
    *{__PACKAGE__.'::'.$method.'_is'} = sub {
        my $self = shift;
        local $Test::Builder::Level = $Test::Builder::Level + 1;
        return $self->method_is($method, @_);
    };
}

sub method_ok {
    my $ldap = shift;
    my $method = shift;
    my ($params, $name);
    
    if (ref $_[0] eq 'ARRAY') {
        ($params, $name) = @_;
    } else {
        $params = \@_;
    }
    
    my $expected = Net::LDAP::Constant::LDAP_SUCCESS;
    return $ldap->method_is($method, $params, $expected, $name);
}

sub method_is {
    my $ldap = shift;
    my $method = shift;
    my ($params, $expected, $name);
    
    if (ref $_[0] eq 'ARRAY') {
        ($params, $expected, $name) = @_;
    } else {
        $params = \@_;
    }
    
    my $mesg = $ldap->$method(@$params);
    
    unless (defined $name) {
        my $arg = Net::LDAP::_dn_options(@$params);
        
        $name = $method.'('.join(', ', map {
            my ($param, $value) = ($_, "$arg->{$_}");
            $value = substr($value, 0, 32).'...' if length($value) > 32;
            qq($param => "$value");
        } grep {
            defined $arg->{$_}
        } qw(base scope filter dn newrdn newsuperior)).')';
    }
    
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    Test::Net::LDAP::Util::ldap_result_is($mesg, $expected, $name);
    
    return $mesg;
}

1;
© 2025 GrazzMean