StoredHash/LDMeta.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 81 CC 14 SCAR 52.8
CC
14
Cov
0%
meta
210.0
BEGIN
2.0
CRAP 196.1
1 # LD Meta Fetch
2  
3 # Sample ObjectClasses from a set of ents (use loadset with few attrs)
4 #
5 #use Net::LDAP::Schema;
6 package StoredHash::LDMeta;
7 use Data::Dumper;
8  
9 sub meta {
10 my ($p) = @_;
11 my ($ldap, $sc) = @$p{'dbh','table'};
12 my $schema = $ldap->schema();
13 # get objectClasses
14 my @ocs = $schema->all_objectclasses();
15
16 my @atts = $schema->all_attributes;
17 my %attsidx = map({$_->{'name'}, $_;} @atts);
18 # Attrs: 'max_length' 'single-value'
19 my $mka = sub {
20 my ($ats, $man, $ocn) = @_;
21 map({
22 #my $an = mkals($_);
23
24 {'tabname' => $ocn, 'attrname' => $_, 'notnull' => $man, };
25 } @$ats);
26 };
27 # Refine
28 for my $oc (@ocs) {
29 my $ocn = $oc->{'name'};
30 my ($am, $ao) = @$oc{'must', 'may'};
31 my $as = $oc->{'attrs'} = [$mka->($am, 1, $ocn), $mka->($ao, 0, $ocn)];
32 delete(@$oc{'must', 'may'});
33 map({
34 my $an = $_->{'attrname'};
35 my $ldm = $attsidx{$an};
36 if (my $v = $ldm->{'max_length'}) {$_->{'dlen'} = $v;}
37 if (my $v = $ldm->{'desc'}) {$_->{'longdesc'} = $v;}
38 # Prefer slightly longer alias if present
39 #if (length($ldm->{'name'} < 6) && ref($ldm->{'aliases'})) {
40 # $_->{'attrname'} = $ldm->{'aliases'}->[0];
41 #}
42 if ($ldm->{'single-value'}) {$_->{'multiplicity'} = 1;}
43 # Desive type from 'equality' 'substr'
44 my $eq = $ldm->{'equality'};
45 my ($dtype);
46 # distinguishedNameMatch
47 if ($eq =~ /caseIgnore/) {$dtype = 'char';}
48 elsif ($eq =~ /^integer/) {$dtype = 'int';}
49 elsif ($eq =~ /^numericString/) {$dtype = 'float';} # numeric
50 elsif ($eq =~ /^boolean/) {$dtype = 'bool';}
51 elsif ($eq =~ /^generalizedTime/) {$dtype = 'datetime';}
52 elsif ($eq =~ /^telephoneNumber/) {$dtype = 'char';}
53 elsif ($eq =~ /^octetString/) {$dtype = 'blob';}
54 elsif ($eq =~ /^caseExact/) {$dtype = 'char';}
55 #elsif ($eq =~ /bitStringMatch/) {$dtype = 'char';} # Mask ?
56 elsif ($eq =~ /^distinguishedName/) {$dtype = 'char';$optsrc = 'ldap';}
57 #elsif ($eq =~ /caseIgnore/) {$dtype = 'char';}
58 if ($ldm->{'desc'} =~ /binary$/) {$dtype = 'blob';}
59 $_->{'dtype'} = $dtype;
60 } @$as);
61
62 }
63 # Get the attributes
64 #my @atts = $schema->all_attributes;
65 print(Dumper(\@ocs));
66 #print(Dumper(\@atts));
67 }
68 1;