use Test::More;
use String::CamelCase 'wordsplit';
use Carp::Clan qw/^DBIx::Class/;
+use Scalar::Util 'looks_like_number';
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/;
+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_]+/;
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.
close $fh;
}
+sub array_eq($$) {
+ no warnings 'uninitialized';
+ my ($a, $b) = @_;
+
+ return unless @$a == @$b;
+
+ for (my $i = 0; $i < @$a; $i++) {
+ if (looks_like_number $a->[$i]) {
+ return unless $a->[$i] == $b->[$i];
+ }
+ else {
+ return unless $a->[$i] eq $b->[$i];
+ }
+ }
+ return 1;
+}
+
1;
# vim:et sts=4 sw=4 tw=0: