From: Dagfinn Ilmari Mannsåker Date: Mon, 21 Oct 2013 23:35:21 +0000 (+0100) Subject: Silence warnings from pure-perl Cwd::abs_path() X-Git-Tag: 0.07036_03~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cfaae7fc838818ad61ecd4839c40e1debd132074;hp=76e9a92a87d9a1f70179288c12f21a92a266d8dc;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Silence warnings from pure-perl Cwd::abs_path() --- diff --git a/Changes b/Changes index 02e9bca..0a0ff6a 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Restore support for PostgreSQL 8.3 (RT#87291) - Fix t/23dumpmore on perl 5.8.8 and earlier + - Silence warnings from pure-perl Cwd::abs_path() 0.07036_02 2013-09-25 - Skip many_to_many bridges involving might_have relationships diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 87c62a4..8528778 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -20,7 +20,7 @@ use File::Temp (); use Class::Unload; use Class::Inspector (); use Scalar::Util 'looks_like_number'; -use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file/; +use DBIx::Class::Schema::Loader::Utils qw/split_name dumper_squashed eval_package_without_redefine_warnings class_path slurp_file sigwarn_silencer/; use DBIx::Class::Schema::Loader::Optional::Dependencies (); use Try::Tiny; use DBIx::Class (); @@ -1421,6 +1421,8 @@ sub _find_file_in_inc { foreach my $prefix (@INC) { my $fullpath = File::Spec->catfile($prefix, $file); + # abs_path pure-perl fallback warns for non-existent files + local $SIG{__WARN__} = sigwarn_silencer(qr/^stat\(.*\Q$file\E\)/); return $fullpath if -f $fullpath # abs_path throws on Windows for nonexistent files and (try { Cwd::abs_path($fullpath) }) ne diff --git a/lib/DBIx/Class/Schema/Loader/Utils.pm b/lib/DBIx/Class/Schema/Loader/Utils.pm index 544d2ff..c2e5d43 100644 --- a/lib/DBIx/Class/Schema/Loader/Utils.pm +++ b/lib/DBIx/Class/Schema/Loader/Utils.pm @@ -11,7 +11,7 @@ use namespace::clean; use Exporter 'import'; use Data::Dumper (); -our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent slurp_file write_file array_eq/; +our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent slurp_file write_file array_eq sigwarn_silencer/; use constant BY_CASE_TRANSITION_V7 => qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/; @@ -50,15 +50,21 @@ sub dumper_squashed($) { return $dd->Values([ $val ])->Dump; } +# copied from DBIx::Class::_Util, import from there once it's released +sub sigwarn_silencer { + my $pattern = shift; + + croak "Expecting a regexp" if ref $pattern ne 'Regexp'; + + my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) }; + + return sub { &$orig_sig_warn unless $_[0] =~ $pattern }; +} + sub eval_package_without_redefine_warnings { my ($pkg, $code) = @_; - my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; - - local $SIG{__WARN__} = sub { - $warn_handler->(@_) - unless $_[0] =~ /^Subroutine \S+ redefined/; - }; + local $SIG{__WARN__} = sigwarn_silencer(qr/^Subroutine \S+ redefined/); # This hairiness is to handle people using "use warnings FATAL => 'all';" # in their custom or external content.