Port ::Admin from Moose to Moo+Type::Tiny topic/mooification+type-tiny
Dagfinn Ilmari Mannsåker [Thu, 19 Mar 2015 22:26:22 +0000 (22:26 +0000)]
lib/DBIx/Class/Admin.pm
lib/DBIx/Class/Admin/Types.pm
lib/DBIx/Class/Optional/Dependencies.pm
t/admin/02ddl.t
t/admin/03data.t
xt/dist/pod_coverage.t

index ffc236e..f4956aa 100644 (file)
@@ -12,12 +12,11 @@ BEGIN {
 }
 
 use JSON::Any qw(DWIW PP JSON CPANEL XS);
-use Moose;
-use MooseX::Types::Moose qw/Int Str Any Bool/;
-use DBIx::Class::Admin::Types qw/DBICConnectInfo DBICHashRef/;
-use MooseX::Types::JSON qw(JSON);
-use MooseX::Types::Path::Class qw(Dir File);
-use MooseX::Types::LoadableClass qw(LoadableClass);
+use Moo;
+use Type::Utils qw(class_type);
+use Types::Standard qw(Int Str Any Bool);
+use DBIx::Class::Admin::Types qw(Dir File DBICConnectInfo DBICHashRef);
+use Types::LoadableClass qw(LoadableClass);
 use Try::Tiny;
 use namespace::clean;
 
@@ -85,8 +84,11 @@ A pre-connected schema object can be provided for manipulation
 
 has 'schema' => (
   is          => 'ro',
-  isa         => 'DBIx::Class::Schema',
-  lazy_build  => 1,
+  isa         => class_type('DBIx::Class::Schema'),
+  lazy        => 1,
+  builder     => 1,
+  predicate   => 1,
+  clearer     => 1,
 );
 
 sub _build_schema {
@@ -156,7 +158,10 @@ connect_info the arguments to provide to the connect call of the schema_class
 has 'connect_info' => (
   is          => 'ro',
   isa         => DBICConnectInfo,
-  lazy_build  => 1,
+  lazy        => 1,
+  builder     => 1,
+  predicate   => 1,
+  clearer     => 1,
   coerce      => 1,
 );
 
@@ -204,7 +209,10 @@ config_stanza will still be required.
 has config => (
   is          => 'ro',
   isa         => DBICHashRef,
-  lazy_build  => 1,
+  lazy        => 1,
+  builder     => 1,
+  predicate   => 1,
+  clearer     => 1,
 );
 
 sub _build_config {
@@ -292,12 +300,6 @@ has quiet => (
   isa => Bool,
 );
 
-has '_confirm' => (
-  is  => 'bare',
-  isa => Bool,
-);
-
-
 =head2 trace
 
 Toggle DBIx::Class debug output
@@ -562,9 +564,6 @@ sub select {
 sub _confirm {
   my ($self) = @_;
 
-  # mainly here for testing
-  return 1 if ($self->meta->get_attribute('_confirm')->get_value($self));
-
   print "Are you sure you want to do this? (type YES to confirm) \n";
   my $response = <STDIN>;
 
index c6f37c6..b3d46c7 100644 (file)
@@ -1,17 +1,26 @@
 package # hide from PAUSE
     DBIx::Class::Admin::Types;
 
-# Workaround for https://rt.cpan.org/Public/Bug/Display.html?id=83336
 use warnings;
 use strict;
 
-use MooseX::Types -declare => [qw(
+use Type::Library
+  -base,
+  -declare => qw(
+    Dir File
     DBICConnectInfo
     DBICArrayRef
     DBICHashRef
-)];
-use MooseX::Types::Moose qw/Int HashRef ArrayRef Str Any Bool/;
-use MooseX::Types::JSON qw(JSON);
+);
+use Type::Utils -all;
+use Types::Standard qw/HashRef ArrayRef Str/;
+use Path::Class;
+
+class_type Dir, { class => 'Path::Class::Dir' };
+class_type File, { class => 'Path::Class::File' };
+
+coerce Dir, from Str, via { dir($_) };
+coerce File, from Str, via { file($_) };
 
 subtype DBICArrayRef,
     as ArrayRef;
@@ -20,30 +29,23 @@ subtype DBICHashRef,
     as HashRef;
 
 coerce DBICArrayRef,
-  from JSON,
+  from Str,
   via { _json_to_data ($_) };
 
 coerce DBICHashRef,
-  from JSON,
+  from Str,
   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 { [ $_ ] };
+  from Str, via { _json_to_data($_) },
+  from HashRef, via { [ $_ ] };
 
 sub _json_to_data {
   my ($json_str) = @_;
+  require JSON::Any;
   my $json = JSON::Any->new(allow_barekey => 1, allow_singlequote => 1, relaxed=>1);
   my $ret = $json->jsonToObj($json_str);
   return $ret;
index dfe78e5..d673380 100644 (file)
@@ -21,14 +21,6 @@ sub croak {
 # POD is generated automatically by calling _gen_pod from the
 # Makefile.PL in $AUTHOR mode
 
-# *DELIBERATELY* not making a group for these - they must disappear
-# forever as optdeps in the first place
-my $moose_basic = {
-  'Moose'                         => '0.98',
-  'MooseX::Types'                 => '0.21',
-  'MooseX::Types::LoadableClass'  => '0.011',
-};
-
 my $dbic_reqs = {
 
   # NOTE: the rationale for 2 JSON::Any versions is that
@@ -105,12 +97,7 @@ my $dbic_reqs = {
   },
 
   admin => {
-    include => '_json_any',
-    req => {
-      %$moose_basic,
-      'MooseX::Types::Path::Class' => '0.05',
-      'MooseX::Types::JSON' => '0.02',
-    },
+    include => [qw(_json_any _types_common)],
     pod => {
       title => 'DBIx::Class::Admin',
       desc => 'Modules required for the DBIx::Class administrative library',
index b2414c3..90a553d 100644 (file)
@@ -14,6 +14,11 @@ use DBICTest;
 use DBIx::Class::_Util 'sigwarn_silencer';
 
 use DBIx::Class::Admin;
+BEGIN {
+  no warnings 'redefine';
+  # no questions asked
+  sub DBIx::Class::Admin::_confirm { 1 };
+}
 
 # lock early
 DBICTest->init_schema(no_deploy => 1, no_populate => 1);
@@ -96,7 +101,6 @@ clean_dir($ddl_dir);
 my $admin = DBIx::Class::Admin->new(
   schema_class  => 'DBICVersion::Schema',
   sql_dir      => $ddl_dir,
-  _confirm    => 1,
   connect_info  => \@connect_info,
 );
 
index d73f619..3fe6019 100644 (file)
@@ -10,6 +10,11 @@ use lib 't/lib';
 use DBICTest;
 
 use DBIx::Class::Admin;
+BEGIN {
+  no warnings 'redefine';
+  # no questions asked
+  sub DBIx::Class::Admin::_confirm { 1 };
+}
 
 { # test data maniplulation functions
 
index 144b058..c08c17c 100644 (file)
@@ -103,6 +103,9 @@ my $exceptions = {
     'DBIx::Class::Admin'        => {
         ignore => [ qw/
             BUILD
+            has_config
+            has_connect_info
+            has_schema
         /]
      },