Port ::Admin from Moose to Moo+Type::Tiny
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Admin.pm
index 0eb6e0c..f4956aa 100644 (file)
@@ -1,21 +1,24 @@
 package DBIx::Class::Admin;
 
+use warnings;
+use strict;
+
 # check deps
 BEGIN {
-  use DBIx::Class;
-  die('The following modules are required for DBIx::Class::Admin ' . DBIx::Class::Optional::Dependencies->req_missing_for ('admin') )
-    unless DBIx::Class::Optional::Dependencies->req_ok_for ('admin');
+  require DBIx::Class::Optional::Dependencies;
+  if (my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('admin') ) {
+    die "The following extra modules are required for DBIx::Class::Admin: $missing\n";
+  }
 }
 
-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 JSON::Any qw(DWIW PP JSON CPANEL XS);
+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 JSON::Any qw(DWIW XS JSON);
-use namespace::autoclean;
+use namespace::clean;
 
 =head1 NAME
 
@@ -81,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 {
@@ -152,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,
 );
 
@@ -200,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 {
@@ -288,12 +300,6 @@ has quiet => (
   isa => Bool,
 );
 
-has '_confirm' => (
-  is  => 'bare',
-  isa => Bool,
-);
-
-
 =head2 trace
 
 Toggle DBIx::Class debug output
@@ -451,7 +457,7 @@ sub insert {
   $rs ||= $self->resultset();
   $set ||= $self->set();
   my $resultset = $self->schema->resultset($rs);
-  my $obj = $resultset->create( $set );
+  my $obj = $resultset->new_result($set)->insert;
   print ''.ref($resultset).' ID: '.join(',',$obj->id())."\n" if (!$self->quiet);
 }
 
@@ -558,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>;
 
@@ -582,13 +585,16 @@ sub _find_stanza {
   return $cfg;
 }
 
-=head1 AUTHOR
+=head1 FURTHER QUESTIONS?
 
-See L<DBIx::Class/CONTRIBUTORS>.
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
 
-=head1 LICENSE
+=head1 COPYRIGHT AND LICENSE
 
-You may distribute this code under the same terms as Perl itself
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
 
 =cut