From: Graham Knop Date: Tue, 27 Aug 2013 11:53:02 +0000 (-0400) Subject: automatically abbreviate generated class names if they are too long X-Git-Tag: v1.003002~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FRole-Tiny.git;a=commitdiff_plain;h=bc615098b6623768411c0d60f87d2ff273d88700 automatically abbreviate generated class names if they are too long --- diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index 73b2053..40c3a88 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -104,6 +104,21 @@ sub apply_roles_to_object { $object; } +my $role_suffix = 'A000'; +sub _composite_name { + my ($me, $superclass, @roles) = @_; + + my $new_name = join( + '__WITH__', $superclass, my $compose_name = join '__AND__', @roles + ); + + if (length($new_name) > 252) { + $new_name = $COMPOSED{abbrev}{$new_name} + ||= substr($new_name, 0, 250 - length $role_suffix).'__'.$role_suffix++; + } + return wantarray ? ($new_name, $compose_name) : $new_name; +} + sub create_class_with_roles { my ($me, $superclass, @roles) = @_; @@ -118,9 +133,7 @@ sub create_class_with_roles { } } - my $new_name = join( - '__WITH__', $superclass, my $compose_name = join '__AND__', @roles - ); + my ($new_name, $compose_name) = $me->_composite_name($superclass, @roles); return $new_name if $COMPOSED{class}{$new_name};