Skip to content

Commit

Permalink
Stop depending on String::CamelCase (closes GH#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Jul 14, 2017
1 parent c769107 commit 9acc923
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Stop depending on String::CamelCase (closes GH#15)
(Good find Peter Rabbitson!)

0.005002 2016-04-29 09:20:41-07:00 America/Los_Angeles
- Fix test issue when run under `prove -lr` (Thanks Peter Rabbitson!)
Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ requires 'DBIx::Class' => 0.08123;
requires 'Sub::Exporter' => 0.982;
requires 'namespace::clean' => 0.18;
requires 'MRO::Compat' => 0.11;
requires 'String::CamelCase' => 0;
requires 'Lingua::EN::Inflect' => 0;

on test => sub {
Expand Down
18 changes: 14 additions & 4 deletions lib/DBIx/Class/Candy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,29 @@ sub _extract_part {
}
}

my $decamelize = sub {
my $s = shift;
$s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
my $fc = pos($s)==0;
my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
my $t = $p0 || $fc ? $p0 : '_';
$t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
$t;
}ge;
$s;
};

sub gen_table {
my ( $self, $class, $version ) = @_;
if ($version eq 'singular') {
my $part = $self->_extract_part($class);
require String::CamelCase;
$part =~ s/:://g;
return String::CamelCase::decamelize($part);
return $decamelize->($part);
} elsif ($version == 1) {
my $part = $self->_extract_part($class);
require Lingua::EN::Inflect;
require String::CamelCase;
$part =~ s/:://g;
$part = String::CamelCase::decamelize($part);
$part = $decamelize->($part);
return join q{_}, split /\s+/, Lingua::EN::Inflect::PL(join q{ }, split /_/, $part);
}
}
Expand Down

0 comments on commit 9acc923

Please sign in to comment.