=cut
use Moo;
-use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
-use SQL::Translator::Types qw(schema_obj);
-use List::MoreUtils qw(uniq);
+use SQL::Translator::Utils qw(parse_list_arg ex2err throw uniq);
+use SQL::Translator::Types qw(schema_obj enum);
+use Sub::Quote qw(quote_sub);
extends 'SQL::Translator::Schema::Object';
-our $VERSION = '1.59';
+our $VERSION = '1.60';
=head2 new
has perform_action_when => (
is => 'rw',
- coerce => sub { defined $_[0] ? lc $_[0] : $_[0] },
- isa => sub {
- throw("Invalid argument '$_[0]' to perform_action_when")
- if defined $_[0] and $_[0] !~ m/^(before|after)$/i;
- },
+ coerce => quote_sub(q{ defined $_[0] ? lc $_[0] : $_[0] }),
+ isa => enum([qw(before after)], {
+ msg => "Invalid argument '%s' to perform_action_when",
+ allow_undef => 1,
+ }),
);
around perform_action_when => \&ex2err;
has database_events => (
is => 'rw',
- coerce => sub { [ map { lc } ref $_[0] eq 'ARRAY' ? @{$_[0]} : ($_[0]) ] },
+ coerce => quote_sub(q{ [ map { lc } ref $_[0] eq 'ARRAY' ? @{$_[0]} : ($_[0]) ] }),
isa => sub {
my @args = @{$_[0]};
my %valid = map { $_, 1 } qw[ insert update update_on delete ];
=cut
-has action => ( is => 'rw', default => sub { '' } );
+has action => ( is => 'rw', default => quote_sub(q{ '' }) );
sub is_valid {
=cut
-has name => ( is => 'rw', default => sub { '' } );
+has name => ( is => 'rw', default => quote_sub(q{ '' }) );
=head2 order
=cut
-has order => ( is => 'rw', default => sub { 0 } );
+has order => ( is => 'rw', default => quote_sub(q{ 0 }) );
around order => sub {
my ( $orig, $self, $arg ) = @_;
has scope => (
is => 'rw',
- isa => sub {
- my ($arg) = @_;
- throw( "Invalid scope '$arg'" )
- if defined $arg and $arg !~ /^(row|statement)$/i;
- },
+ isa => enum([qw(row statement)], {
+ msg => "Invalid scope '%s'", icase => 1, allow_undef => 1,
+ }),
);
around scope => \&ex2err;