Fix name and encoding
[dbsrgits/DBIx-Class-Schema-Loader.git] / script / dbicdump
index cb97638..895a202 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+=encoding UTF-8
+
 =head1 NAME
 
 dbicdump - Dump a schema using DBIx::Class::Schema::Loader
@@ -7,7 +9,8 @@ dbicdump - Dump a schema using DBIx::Class::Schema::Loader
 =head1 SYNOPSIS
 
   dbicdump <configuration_file>
-  dbicdump [-o <loader_option>=<value> ] <schema_class> <connect_info>
+  dbicdump [-I <lib-path>] [-o <loader_option>=<value> ] \
+                <schema_class> <connect_info>
 
 Examples:
 
@@ -15,10 +18,14 @@ Examples:
 
   $ dbicdump -o dump_directory=./lib \
     -o components='["InflateColumn::DateTime"]' \
-    MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
+    MyApp::Schema dbi:SQLite:./foo.db
 
   $ dbicdump -o dump_directory=./lib \
     -o components='["InflateColumn::DateTime"]' \
+    MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
+
+  $ dbicdump -Ilib -o dump_directory=./lib \
+    -o components='["InflateColumn::DateTime"]' \
     -o preserve_case=1 \
     MyApp::Schema dbi:mysql:database=foo user pass '{ quote_char => "`" }'
 
@@ -37,6 +44,8 @@ Configuration files must have schema_class and connect_info sections,
 an example of a general config file is as follows:
 
     schema_class MyApp::Schema
+
+    lib /extra/perl/libs
     
     # connection string
     <connect_info>
@@ -47,12 +56,15 @@ an example of a general config file is as follows:
     
     # dbic loader options
     <loader_options>
-        components  InflateColumn::DateTime
-        components  TimeStamp
+        dump_directory ./lib
+        components     InflateColumn::DateTime
+        components     TimeStamp
     </loader_options>
 
 Using a config file requires L<Config::Any> installed.
 
+The optional C<lib> key is equivalent to the C<-I> option.
+
 =head1 DESCRIPTION
 
 Dbicdump generates a L<DBIx::Class> schema using
@@ -72,12 +84,14 @@ L<DBIx::Class::Schema::Loader>, L<DBIx::Class>.
 
 =head1 AUTHOR
 
-Dagfinn Ilmari MannsÃ¥ker C<< <ilmari@ilmari.org> >>
+Dagfinn Ilmari MannsÃ¥ker C<< <ilmari@ilmari.org> >>
 
 =head1 CONTRIBUTORS
 
 Caelum: Rafael Kitover <rkitover@cpan.org>
 
+alnewkirk: Al Newkirk <awncorp@cpan.org>
+
 =head1 LICENSE
 
 This program is free software; you can redistribute it and/or modify it
@@ -90,12 +104,20 @@ use warnings;
 use Getopt::Long;
 use Pod::Usage;
 use DBIx::Class::Schema::Loader 'make_schema_at';
+use namespace::clean;
 use DBIx::Class::Schema::Loader::Base ();
 use DBIx::Class::Schema::Loader::Optional::Dependencies ();
+require lib;
 
 my $loader_options;
 
-GetOptions( 'loader-option|o=s%' => \&handle_option );
+Getopt::Long::Configure('gnu_getopt');
+
+GetOptions(
+    'I=s'                => sub { shift; lib->import(shift) },
+    'loader-option|o=s%' => \&handle_option,
+);
+
 $loader_options->{dump_directory} ||= '.';
 
 if (@ARGV == 1) {
@@ -117,6 +139,18 @@ if (@ARGV == 1) {
     unless (keys %{$c->{connect_info}} && $c->{schema_class}) {
         pod2usage(1);
     }
+
+    my @libs;
+
+    if ($c->{lib}) {
+        if (ref $c->{lib}) {
+            @libs = @{ $c->{lib} };
+        }
+
+        @libs = ($c->{lib});
+    }
+
+    lib->import($_) for @libs;
     
     my ($dsn, $user, $pass, $options) =
         map { $c->{connect_info}->{$_} } qw/dsn user pass options/;