Inline String::CamelCase::wordsplit() due to RT#123030
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Utils.pm
index fca3c2f..66a92c7 100644 (file)
@@ -4,14 +4,13 @@ package # hide from PAUSE
 use strict;
 use warnings;
 use Test::More;
-use String::CamelCase 'wordsplit';
 use Carp::Clan qw/^DBIx::Class/;
-use Scalar::Util 'looks_like_number';
+use List::Util 'all';
 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 sigwarn_silencer/;
+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 apply firstidx uniq/;
 
 use constant BY_CASE_TRANSITION_V7 =>
     qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/;
@@ -22,6 +21,12 @@ use constant BY_NON_ALPHANUM =>
 my $LF   = "\x0a";
 my $CRLF = "\x0d\x0a";
 
+# Copied from String::CamelCase because of RT#123030
+sub wordsplit {
+    my $s = shift;
+    split /[_\s]+|\b|(?<![A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/, $s;
+}
+
 sub split_name($;$) {
     my ($name, $v) = @_;
 
@@ -61,6 +66,27 @@ sub sigwarn_silencer {
     return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
 }
 
+# Copied with stylistic adjustments from List::MoreUtils::PP
+sub firstidx (&@) {
+    my $f = shift;
+    foreach my $i (0..$#_) {
+        local *_ = \$_[$i];
+        return $i if $f->();
+    }
+    return -1;
+}
+
+sub uniq (@) {
+    my %seen = ();
+    grep { not $seen{$_}++ } @_;
+}
+
+sub apply (&@) {
+    my $action = shift;
+    $action->() foreach my @values = @_;
+    wantarray ? @values : $values[-1];
+}
+
 sub eval_package_without_redefine_warnings {
     my ($pkg, $code) = @_;
 
@@ -177,19 +203,9 @@ sub write_file($$) {
 
 sub array_eq($$) {
     no warnings 'uninitialized';
-    my ($a, $b) = @_;
+    my ($l, $r) = @_;
 
-    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;
+    return @$l == @$r && all { $l->[$_] eq $r->[$_] } 0..$#$l;
 }
 
 1;