Some cosmetic fixes in ANFANG
[dbsrgits/DBIx-Class.git] / script / dbicadmin
index 58ef4c8..414b582 100755 (executable)
@@ -4,11 +4,10 @@ use strict;
 use warnings;
 
 BEGIN {
-  use DBIx::Class;
-  die (  'The following modules are required for the dbicadmin utility: '
-       . DBIx::Class::Optional::Dependencies->req_missing_for ('admin_script')
-       . "\n"
-  ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('admin_script');
+  require DBIx::Class::Optional::Dependencies;
+  if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('admin_script') ) {
+    die "The following modules are required for the dbicadmin utility: $missing\n";
+  }
 }
 
 use DBIx::Class::Admin::Descriptive;
@@ -34,16 +33,16 @@ my ($opts, $usage) = describe_options(
     ['Actions'],
     ["action" => hidden => { one_of => [
       ['create' => 'Create version diffs needs preversion'],
-      ['upgrade' => 'Upgrade the database to the current schema '],
+      ['upgrade' => 'Upgrade the database to the current schema'],
       ['install' => 'Install the schema version tables to an existing database'],
       ['deploy' => 'Deploy the schema to the database'],
       ['select'   => 'Select data from the schema'],
       ['insert'   => 'Insert data into the schema'],
       ['update'   => 'Update data in the schema'],
       ['delete'   => 'Delete data from the schema'],
-      ['op:s' => 'compatiblity option all of the above can be suppied as --op=<action>'],
+      ['op:s' => 'compatibility option all of the above can be supplied as --op=<action>'],
       ['help' => 'display this help', { implies => { schema_class => '__dummy__' } } ],
-      ['selfinject-pod' => 'hidden', { implies => { schema_class => '__dummy__' } } ],
+      ['documentation-as-pod:s' => 'hidden', { implies => { schema_class => '__dummy__' } } ],
     ], required => 1 }],
     ['Arguments'],
     ["configuration" => hidden => { one_of => [
@@ -68,23 +67,26 @@ my ($opts, $usage) = describe_options(
   )
 );
 
-if($opts->{selfinject_pod}) {
-
-    die "This is an internal method, do not call!!!\n"
-      unless $ENV{MAKELEVEL};
-
-    $usage->synopsis($synopsis_text);
-    $usage->short_description($short_description);
-    exec (
-      $^X,
-      qw/-p -0777 -i -e/,
-      (
-        's/^# auto_pod_begin.*^# auto_pod_end/'
-      . quotemeta($usage->pod)
-      . '/ms'
-      ),
-      __FILE__
-    );
+if(defined (my $fn = $opts->{documentation_as_pod}) ) {
+  $usage->synopsis($synopsis_text);
+  $usage->short_description($short_description);
+
+  my $fh;
+  if ($fn) {
+    require DBIx::Class::_Util;
+    DBIx::Class::_Util::mkdir_p( DBIx::Class::_Util::parent_dir( $fn ) );
+    open( $fh, '>', $fn ) or die "Unable to open $fn: $!\n";
+  }
+  else {
+    $fh = \*STDOUT;
+  }
+
+  print $fh "\n";
+  print $fh $usage->pod;
+  print $fh "\n";
+
+  close $fh if $fn;
+  exit 0;
 }
 
 # FIXME - lowercasing will eventually go away when Getopt::Long::Descriptive is fixed
@@ -97,7 +99,7 @@ if($opts->{help}) {
   $usage->die();
 }
 
-# option compatability mangle
+# option compatibility mangle
 # (can not be joined in the spec, one is s% the other is s)
 if($opts->{connect}) {
   $opts->{connect_info} = delete $opts->{connect};
@@ -129,13 +131,6 @@ if ($action eq 'select') {
   }
 }
 
+1;
 
 __END__
-
-# auto_pod_begin
-#
-# This will be replaced by the actual pod when selfinject-pod is invoked
-#
-# auto_pod_end
-
-# vim: et ft=perl