--- bin/ldap2model.pl 2008/05/01 14:30:06 103 +++ bin/ldap2model.pl 2008/05/02 14:38:45 108 @@ -2,11 +2,27 @@ use warnings; use strict; -# schema2model.pl - convert LDAP schema file into jifty model -# -# 04/30/08 20:55:21 CEST Dobrica Pavlinusic -# -# ./bin/ldap2model.pl --model hrEduOrg --path data/all.ldif +=head1 NAME + +schema2model.pl - convert LDAP schema file into jifty model + +=head1 DESCRIPTION + +Create model from ldif data + + ./bin/ldap2model.pl --model hrEduOrg --path data/all.ldif + +or directly from LDAP server + + ./bin/ldap2model.pl --model inetOrgPerson + ./bin/ldap2model.pl --model organization + +which must match C in C + +With C<--debug> switch all output will go to C +instead to files. + +=cut use lib 'lib'; @@ -17,11 +33,12 @@ use Data::Dump qw/dump/; use Getopt::Long; -my ( $path, $objectClass ); +my ( $path, $objectClass, $debug ); GetOptions( 'model|objectClass=s', => \$objectClass, 'path=s', => \$path, + 'debug+', => \$debug, ); die "usage: $0 --model netOrgPerson [--path path/to/schema.ldif]\n" unless $objectClass; @@ -57,7 +74,8 @@ my $name = $_->{name} || die "no name?"; $methods .= qq/sub $_ { \$_[0]->$name }\n/ foreach @{$_->{aliases}}; my $out = qq/\tcolumn $name =>\n\t\tlabel is _('$_->{desc}')/; - $out .= qq/,\n\t\t# single-value/ if $_->{'single-value'}; +# $out .= qq/,\n\t\t# single-value/ if $_->{'single-value'}; +# $out .= qq/,\n\t\tfilters are qw(A3C::Filter::Array)/ unless $_->{'single-value'}; $out .= qq/,\n\t\tmax_length is $_->{max_length}/ if $_->{'max_length'}; $out .= qq/,\n\t\t$add/ if $add; $out .= qq/;\n\n/; @@ -71,15 +89,15 @@ map { - warn "# $objectClass must: ",dump( $_ ); + warn "# $objectClass must: ",dump( $_ ) if $debug; $model .= entry( $_, 'is mandatory' ); - $create->{$_->{name}} = $_->{name}; + $create->{$_->{name}} = $_->{'single-value'} ? $_->{name} : [ $_->{name}, $_->{desc} ]; } $schema->must( $objectClass ); $model .= qq/\t# $objectClass may:\n\n/; map { - warn "# $objectClass may: ",dump( $_ ); + warn "# $objectClass may: ",dump( $_ ) if $debug; $model .= entry( $_ ); } $schema->may( $objectClass ); @@ -96,9 +114,13 @@ 1; /; -my $model_path = "lib/A3C/Model/$objectClass.pm"; -write_file( $model_path, $model ); -warn "Created $model_path\n"; +if ( $debug ) { + print "##### ----- created model test\n$model\n"; +} else { + my $model_path = "lib/A3C/Model/$objectClass.pm"; + write_file( $model_path, $model ); + print "Created $model_path\n"; +} my $test = <<'__END_OF_TEST__'; #!/usr/bin/env perl @@ -157,12 +179,16 @@ foreach my $round ( 1 .. 2 ) { my $data; - $data .= qq/\t\t'$_' => '$_ $round',\n/ foreach keys %$create; - warn "data = $data\n"; + $data .= qq/\t\t'$_' => / . dump( $create->{$_} ) . qq/,\n/ foreach keys %$create; + warn "$round data = $data\n" if $debug; $test =~ s/_create_${round}_/$data/gs; } -my $test_path = "t/00-model-$objectClass.t"; -write_file( $test_path, $test ); -warn "Created $test_path\n"; -chmod 0755, $test_path; +if ( $debug ) { + print "##### ----- template test\n$test\n"; +} else { + my $test_path = "t/00-model-$objectClass.t"; + write_file( $test_path, $test ); + print "Created $test_path\n"; + chmod 0755, $test_path; +}