X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FBase.pm;h=50b478241c944fcee60ffea8672553aa3faafb4e;hb=f671b6308c4f2210255b2eaa12fc47a49621d436;hp=6927b292d12fc82cfc104b8f587c2b84ba2b39bc;hpb=8de81918c82b582587eaeb905bac03deaeef9061;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 6927b29..50b4782 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -18,13 +18,13 @@ use Class::Unload; use Class::Inspector (); use Scalar::Util 'looks_like_number'; use File::Slurp 'slurp'; -use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed/; +use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_without_redefine_warnings/; use DBIx::Class::Schema::Loader::Optional::Dependencies (); use Try::Tiny; use DBIx::Class (); use namespace::clean; -our $VERSION = '0.07001'; +our $VERSION = '0.07002'; __PACKAGE__->mk_group_ro_accessors('simple', qw/ schema @@ -551,8 +551,7 @@ sub new { if ($self->use_moose) { if (not DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('use_moose')) { - die sprintf "You must install the following CPAN modules to enable the use_moose option: %s.\nYou are missing: %s.\n", - "Moose, MooseX::NonMoose and namespace::autoclean", + die sprintf "You must install the following CPAN modules to enable the use_moose option: %s.\n", DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('use_moose'); } } @@ -662,7 +661,7 @@ EOF # determine if the existing schema was dumped with use_moose => 1 if (! defined $self->use_moose) { - $self->use_moose(1) if $old_gen =~ /^ (?!\s*\#) use \s+ Moose/xm; + $self->{use_moose} = 1 if $old_gen =~ /^ (?!\s*\#) use \s+ Moose/xm; } my $load_classes = ($old_gen =~ /^__PACKAGE__->load_classes;/m) ? 1 : 0; @@ -845,14 +844,7 @@ sub _load_external { $code = $self->_rewrite_old_classnames($code); if ($self->dynamic) { # load the class too - # kill redefined warnings - my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; - local $SIG{__WARN__} = sub { - $warn_handler->(@_) - unless $_[0] =~ /^Subroutine \S+ redefined/; - }; - eval $code; - die $@ if $@; + eval_without_redefine_warnings($code); } $self->_ext_stmt($class, @@ -893,14 +885,7 @@ been used by an older version of the Loader. * PLEASE RENAME THIS CLASS: from '$old_class' to '$class', as that is the new name of the Result. EOF - # kill redefined warnings - my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; - local $SIG{__WARN__} = sub { - $warn_handler->(@_) - unless $_[0] =~ /^Subroutine \S+ redefined/; - }; - eval $code; - die $@ if $@; + eval_without_redefine_warnings($code); } chomp $code; @@ -1126,12 +1111,9 @@ sub _reload_class { delete $INC{ $class_path }; # kill redefined warnings - my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; - local $SIG{__WARN__} = sub { - $warn_handler->(@_) - unless $_[0] =~ /^Subroutine \S+ redefined/; + eval { + eval_without_redefine_warnings ("require $class"); }; - eval "require $class;"; die "Failed to reload class $class: $@" if $@; } @@ -1316,6 +1298,10 @@ sub _write_classfile { $custom_content .= $self->_default_custom_content; } } + elsif (defined $self->use_moose && $old_gen) { + croak 'It is not possible to "downgrade" a schema that was loaded with use_moose => 1 to use_moose => 0, due to differing custom content' + if $old_gen =~ /use \s+ MooseX?\b/x; + } $custom_content = $self->_rewrite_old_classnames($custom_content);