From: Rafael Kitover Date: Wed, 20 Jan 2010 19:54:29 +0000 (+0000) Subject: minor fixups X-Git-Tag: v0.08119~9^2~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=71ef99d5005601cf1c000b3183d945f79af2d30d;hp=8b7789c969e4088e62dfeea2dc87851f74a8c496 minor fixups --- diff --git a/Makefile.PL b/Makefile.PL index caa0e66..2715d8e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -59,7 +59,7 @@ my %admin_requires = ( 'MooseX::Types::Path::Class' => '0.05', 'MooseX::Types::JSON' => '0.02', 'Try::Tiny' => '0.02', - 'namespace::clean' => '0.11', + 'namespace::autoclean' => '0.09', 'parent' => '0.223', 'JSON::Any' => '0', 'Getopt::Long::Descriptive' => '0.081', diff --git a/lib/DBIx/Class/Admin.pm b/lib/DBIx/Class/Admin.pm index 545b826..862143f 100644 --- a/lib/DBIx/Class/Admin.pm +++ b/lib/DBIx/Class/Admin.pm @@ -1,46 +1,38 @@ package DBIx::Class::Admin; -use Moose; -use MooseX::Types -declare => [qw( DBICConnectInfo )]; -use MooseX::Types::Moose qw/Int HashRef ArrayRef Str Any/; -use MooseX::Types::JSON qw(JSON); -use MooseX::Types::Path::Class qw(Dir File); -use Try::Tiny; +# check deps +BEGIN { + my @_deps = qw( + Moose MooseX::Types MooseX::Types::JSON MooseX::Types::Path::Class + Try::Tiny parent JSON::Any Class::C3::Componentised + namespace::autoclean + ); + + my @_missing_deps; + foreach my $dep (@_deps) { + eval "require $dep"; + if ($@) { + push @_missing_deps, $dep; + } + } -use Carp::Clan qw/^DBIx::Class/; + if (@_missing_deps > 0) { + die "The following dependecies are missing " . join ",", @_missing_deps; + } +} -use parent 'Class::C3::Componentised'; +use Moose; use parent 'DBIx::Class::Schema'; +use Carp::Clan qw/^DBIx::Class/; +use MooseX::Types::Moose qw/Int HashRef ArrayRef Str Any Bool/; +use DBIx::Class::Admin::Types qw/DBICConnectInfo/; +use MooseX::Types::JSON qw(JSON); +use MooseX::Types::Path::Class qw(Dir File); +use Try::Tiny; use JSON::Any; - use namespace::autoclean; -my @_deps = qw(Moose MooseX::Types MooseX::Types::JSON MooseX::Types::Path::Class Try::Tiny parent JSON::Any Class::C3::Componentised namespace::autoclean); - -coerce ArrayRef, - from JSON, - via { _json_to_data ($_) }; - -coerce HashRef, - from JSON, - via { _json_to_data($_) }; - -subtype DBICConnectInfo, - as ArrayRef; - -coerce DBICConnectInfo, - from JSON, - via { return _json_to_data($_) } ; - -coerce DBICConnectInfo, - from Str, - via { return _json_to_data($_) }; - -coerce DBICConnectInfo, - from HashRef, - via { [ $_->{dsn}, $_->{user}, $_->{password} ] }; - =head1 NAME @@ -79,7 +71,7 @@ the class of the schema to load has 'schema_class' => ( is => 'ro', - isa => 'Str', + isa => Str, coerce => 1, ); @@ -199,7 +191,7 @@ designed for use with catalyst config files has 'config_stanza' => ( is => 'ro', - isa => 'Str', + isa => Str, ); @@ -249,7 +241,7 @@ Used for install, the version which will be 'installed' in the schema has version => ( is => 'rw', - isa => 'Str', + isa => Str, ); @@ -261,7 +253,7 @@ Previouse version of the schema to create an upgrade diff for, the full sql for has preversion => ( is => 'rw', - isa => 'Str', + isa => Str, ); @@ -273,7 +265,7 @@ Try and force certain operations. has force => ( is => 'rw', - isa => 'Bool', + isa => Bool, ); @@ -285,12 +277,12 @@ Be less verbose about actions has quiet => ( is => 'rw', - isa => 'Bool', + isa => Bool, ); has '_confirm' => ( is => 'bare', - isa => 'Bool', + isa => Bool, ); @@ -563,32 +555,6 @@ sub _find_stanza { return $cfg; } -sub _json_to_data { - my ($json_str) = @_; - my $json = JSON::Any->new(allow_barekey => 1, allow_singlequote => 1, relaxed=>1); - my $ret = $json->jsonToObj($json_str); - return $ret; -} - - -{ # deps check - -my @_missing_deps; -foreach my $dep (@_deps) { - eval "require $dep"; - if ($@) { - push @_missing_deps, $dep; - } -} - -if (@_missing_deps > 0) { - die "The following dependecies are missing " . join ",", @_missing_deps; -} - - -} - - =head1 AUTHORS See L. diff --git a/lib/DBIx/Class/Admin/Types.pm b/lib/DBIx/Class/Admin/Types.pm new file mode 100644 index 0000000..10a0a04 --- /dev/null +++ b/lib/DBIx/Class/Admin/Types.pm @@ -0,0 +1,40 @@ +package # hide from PAUSE + DBIx::Class::Admin::Types; + +use MooseX::Types -declare => [qw( + DBICConnectInfo +)]; +use MooseX::Types::Moose qw/Int HashRef ArrayRef Str Any Bool/; +use MooseX::Types::JSON qw(JSON); + +coerce ArrayRef, + from JSON, + via { _json_to_data ($_) }; + +coerce HashRef, + from JSON, + via { _json_to_data($_) }; + +subtype DBICConnectInfo, + as ArrayRef; + +coerce DBICConnectInfo, + from JSON, + via { return _json_to_data($_) } ; + +coerce DBICConnectInfo, + from Str, + via { return _json_to_data($_) }; + +coerce DBICConnectInfo, + from HashRef, + via { [ $_ ] }; + +sub _json_to_data { + my ($json_str) = @_; + my $json = JSON::Any->new(allow_barekey => 1, allow_singlequote => 1, relaxed=>1); + my $ret = $json->jsonToObj($json_str); + return $ret; +} + +1; diff --git a/script/dbicadmin b/script/dbicadmin index 51bbf0e..38caf6d 100755 --- a/script/dbicadmin +++ b/script/dbicadmin @@ -14,7 +14,7 @@ my ($opts, $usage) = describe_options( ['create|c' => 'Create version diffs needs preversion',], ['upgrade|u' => 'Upgrade the database to the current schema '], ['install|i' => 'Install the schema to the database',], - ['deploy|d' => 'Deploy the a to the database',], + ['deploy|d' => 'Deploy the schema to the database',], ['select|s' => 'Select data from the schema', ], ['insert|i' => 'Insert data into the schema', ], ['update|u' => 'Update data in the schema', ],