Skip to content

Commit

Permalink
Stop depending on String::CamelCase (closes GH#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Mar 12, 2017
1 parent 0e9a59f commit 2bef898
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Stop depending on String::CamelCase (closes GH#81)

2.033002 2016-10-31 16:03:23-07:00 America/Los_Angeles
- Fix ::ProxyResultSetMethod to work when calling ->update
Expand Down
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ requires 'Carp::Clan' => 6.04;
requires 'Sub::Exporter::Progressive' => 0.001006;
requires 'Lingua::EN::Inflect' => 0;
requires 'parent' => 0;
requires 'String::CamelCase' => 0;
requires 'namespace::clean' => 0.23;
requires 'List::Util' => 0;
requires 'DBIx::Class::Candy' => 0.003001;
Expand Down
23 changes: 17 additions & 6 deletions lib/DBIx/Class/Helper/Row/JoinTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use parent 'DBIx::Class::Row';

use DBIx::Class::Helpers::Util 'get_namespace_parts';
use Lingua::EN::Inflect ();
use String::CamelCase ();
use DBIx::Class::Candy::Exports;

export_methods [qw(
Expand All @@ -22,6 +21,18 @@ export_methods [qw(
add_join_columns
)];

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 _pluralize {
my $self = shift;
my $original = shift or return;
Expand All @@ -33,9 +44,9 @@ sub _defaults {
my ($self, $params) = @_;

$params->{namespace} ||= [ get_namespace_parts($self) ]->[0];
$params->{left_method} ||= String::CamelCase::decamelize($params->{left_class});
$params->{right_method} ||= String::CamelCase::decamelize($params->{right_class});
$params->{self_method} ||= String::CamelCase::decamelize($self);
$params->{left_method} ||= $decamelize->($params->{left_class});
$params->{right_method} ||= $decamelize->($params->{right_class});
$params->{self_method} ||= $decamelize->($self);
$params->{left_method_plural} ||= $self->_pluralize($params->{left_method});
$params->{right_method_plural} ||= $self->_pluralize($params->{right_method});
$params->{self_method_plural} ||= $self->_pluralize($params->{self_method});
Expand Down Expand Up @@ -312,8 +323,8 @@ If used in conjunction with L<DBIx::Class::Candy> this component will export:
=head2 NOTE
This module uses L<String::CamelCase> to default the method names and uses
L<Lingua::EN::Inflect> for pluralization.
This module uses (an internal fork of) L<String::CamelCase> to default the
method names and uses L<Lingua::EN::Inflect> for pluralization.
=head1 CHANGES BETWEEN RELEASES
Expand Down

0 comments on commit 2bef898

Please sign in to comment.