aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Schema/Utils.pm
blob: 3fd6c79397171e5724826c1a602770920bf44899 (plain)
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
package Fripost::Schema::Utils;

use 5.010_000;
use warnings;
use strict;

our $VERSION = '0.01';


#######################################################################

sub mkDN {
    my $config = shift;

    my ($user, $domain) = split /\@/, $_[0], 2;

    my $dn;
    if (defined $domain) {
        $dn = join ',', ( 'uid='. $user
                        , 'dc='. $domain
                        , $config->{base_dn} );
    }
    elsif (defined $user) {
        $dn = join ',', ( 'dc='. $user
                        , $config->{base_dn} );
    }
    else {
        $dn = $config->{base_dn};
    }
    return $dn;
}

sub fromDN {
    my ($u,$d) = split /,/, $_[0], 3;
    join '@', ( map { (split /=/, $_, 2)[1] } ($u,$d) );
}

sub mkAndFilter {
    my @filters = @_;

    my $filter;
    if ($#filters == 0) {
        $filter = $filters[0];
    }
    elsif ($#filters > 0) {
        $filter = "(&" . (join '', @filters) . ")";
    }
}


#######################################################################

1;

=head1 NAME

Fripost::Schema::Type::User -

=head1 AUTHOR

Guilhem Moulin C<< <guilhem at fripost.org> >>

=head1 COPYRIGHT

Copyright 2012 Guilhem Moulin, all rights reserved.

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it
under the same terms as perl itself.

=cut

1; # End of Utils.pm

__END__