use Carp;
-our @EXPORT_OK = qw(_hashify);
+our @EXPORT_OK = qw(_hashify camelify snakify);
sub _hashify {
my $keep = shift;
((1 + $keep) == scalar(@_)) && ((ref($_[$keep]) || '') eq 'HASH') ? %{ $_[$keep] } : @_[$keep..scalar(@_) - 1]);
}
+sub camelify {
+ my ($str) = @_;
+ $str =~ s/_+([[:lower:]])/uc($1)/ge;
+ ucfirst $str;
+}
+
+sub snakify {
+ my ($str) = @_;
+ $str =~ s/_([[:upper:]])/'_' . lc($1)/ge;
+ $str =~ s/(?<!^)([[:upper:]])/'_' . lc($1)/ge;
+ lc $str;
+}
+
1;
__END__
# Now do stuff, obviously!
}
+=item C<camilify $string>
+
+Returns C<$string> converted from underscore-style to
+camel-case-style, e.g. for the string C<stupid_example_dude> it will
+return C<StupidExampleDude>.
+
+L</snakify> does the reverse.
+
+=item C<snakify $string>
+
+Returns C<$string> converted from camel-case-style to
+underscore-style, e.g. for the string C<EvenWorseExample> it will
+return C<even_worse_example>.
+
+L</camilify> does the reverse.
+
=back
=head1 BUGS