Hash::KeyMorpher - Deep converter for naming conventions of hash keys
Deeply change the nameing conventions for keys in hash structures, or simply change strings between naming conventions. Converts to CamelCase, mixedCamel, delimited_string, UPPER, LOWER
use Hash::KeyMorpher; # import all, or use Hash::KeyMorpher qw (key_morph to_camel to_mixed to_under to_delim); # import specific subs # To use the string converters: $res = to_camel('my_string'); # MyString $res = to_mixed('my_string'); # myString $res = to_under('myString'); # my_string $res = to_delim('myString','-'); # my-string # To morph keys in a hash, key_morph($hash,$method,$delim); # method is one of camel,mixed,under,delim,upper,lower $h1 = { 'level_one' => { 'LevelTwo' => 'foo' } }; $mixed = key_morph($h1,'mixed'); # { 'levelOne' => { 'levelTwo' => 'foo' } }; $delim = key_morph($h1,'delim','-'); # { 'level-one' => { 'level-two' => 'foo' } }; # To morph acceccor keys $obj = Hash::Accessor->new(qw /CamelCase mixedCase delim_str UPPER lower/); $camel = key_morph($obj,'camel');
This module exports key_morph, to_camel, to_mixed, to_under and to_delim. You will probably only need key_morph unless you really want the others.
Splits a string into words, identifying boundaries using Capital Letters or Underscores etc. This sub is not exported
$method can be one of (camel, mixed, delim, upper, lower). $delim should be specified if using the delim method; by default its an empty string.
Convers string to CamelCase
Convers string to mixedCamelCase
Convers string to underscore_separated
Convers string to custom delimited-string (delimited by second parameter)
Returns the uppercase version of the rejoined string (removes undescores etc)
Returns the lowercase version of the rejoined string (removes undescores etc)
Copyright (c) Michael Holloway 2013 , <michael@thedarkwinter.com>
Perl Arstistic License
To install Hash::KeyMorpher, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::KeyMorpher
CPAN shell
perl -MCPAN -e shell install Hash::KeyMorpher
For more information on module installation, please visit the detailed CPAN module installation guide.