X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=script%2Fdbicadmin;h=2b6a456ebb4b6d431704207ce32fa0dfa38c5b63;hb=6a37181d2b36f085a20ebf5f037fe0b58c1fc86c;hp=35a600ab0a7eabaec5c642715f5cd2f92fbddb8b;hpb=0bf5c67eb6282d2efdd43652643a3f3d80ed7e66;p=dbsrgits%2FDBIx-Class.git diff --git a/script/dbicadmin b/script/dbicadmin index 35a600a..2b6a456 100755 --- a/script/dbicadmin +++ b/script/dbicadmin @@ -3,6 +3,13 @@ use strict; use warnings; +BEGIN { + use DBIx::Class; + die ( "The following modules are required for the dbicadmin utility\n" + . DBIx::Class::Optional::Dependencies->req_missing_for ('admin_script') + ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('admin_script'); +} + use Getopt::Long::Descriptive; use DBIx::Class::Admin; @@ -43,8 +50,7 @@ my ($opts, $usage) = describe_options( ) ); - -die "please only use one of --config or --connect-info" if ($opts->{config} and $opts->{connect_info}); +die "please only use one of --config or --connect-info\n" if ($opts->{config} and $opts->{connect_info}); # option compatability mangle if($opts->{connect}) { @@ -57,40 +63,33 @@ my $admin = DBIx::Class::Admin->new( %$opts ); my $action = $opts->{action}; $action = $opts->{op} if ($action eq 'op'); -my $res = $admin->$action(); -print "going to perform action $action\n"; +print "Performig action $action...\n"; + +my $res = $admin->$action(); if ($action eq 'select') { - my $csv_class; my $format = $opts->{format} || 'tsv'; die('Invalid format') if ($format!~/^tsv|csv$/s); - $csv_class = 'Text::CSV_XS'; - eval{ require Text::CSV_XS }; - if ($@) { - $csv_class = 'Text::CSV_PP'; - eval{ require Text::CSV_PP }; - die('The select op requires either the Text::CSV_XS or the Text::CSV_PP module') if ($@); - } - my $csv = $csv_class->new({ - sep_char => ( $format eq 'tsv' ? "\t" : ',' ), - }); + require Text::CSV; + + my $csv = Text::CSV->new({ + sep_char => ( $format eq 'tsv' ? "\t" : ',' ), + }); + foreach my $row (@$res) { $csv->combine( @$row ); print $csv->string()."\n"; } } - - =head1 AUTHOR -Aran Deltac - -refactored by -Gordon Irving +See L. =head1 LICENSE -You may distribute this code under the same terms as Perl itself. +You may distribute this code under the same terms as Perl itself + +=cut