--- bin/ldap2model.pl 2008/05/01 14:30:06 103 +++ bin/ldap2model.pl 2008/05/01 16:31:00 105 @@ -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; @@ -71,7 +88,7 @@ map { - warn "# $objectClass must: ",dump( $_ ); + warn "# $objectClass must: ",dump( $_ ) if $debug; $model .= entry( $_, 'is mandatory' ); $create->{$_->{name}} = $_->{name}; } $schema->must( $objectClass ); @@ -79,7 +96,7 @@ $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 +113,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 @@ -158,11 +179,15 @@ foreach my $round ( 1 .. 2 ) { my $data; $data .= qq/\t\t'$_' => '$_ $round',\n/ foreach keys %$create; - warn "data = $data\n"; + 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; +}