Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created November 17, 2008 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamipo/25629 to your computer and use it in GitHub Desktop.
Save kamipo/25629 to your computer and use it in GitHub Desktop.
{
use Catalyst::Utils ();
no warnings 'redefine';
sub Catalyst::Utils::class2prefix {
my $class = shift || '';
my $case = shift || 0;
my $prefix;
if ( $class =~ /^.+?::([MVC]|Model|View|Controller)::(.+)$/ ) {
$prefix = $case ? $2 : do {
$prefix = $2;
$prefix =~ s{([A-Z][a-z0-9]+)}{_$1}g;
$prefix =~ s{([A-Z][A-Z]+)}{_$1}g;
$prefix =~ s{(^|::)_(_*)([A-Z]+[a-z0-9]*)}{$1$2$3}g;
lc $prefix;
};
$prefix =~ s{::}{/}g;
}
return $prefix;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment