From: Moritz Bunkus Date: Tue, 30 Apr 2013 14:10:03 +0000 (+0200) Subject: Funktionen 'snakify' und 'camelify' nach SL::Util verschoben, gebugfixt, getestet X-Git-Tag: release-3.1.0beta1~441 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bc3a01aef9a58d5e22137dbcc38fec7abebfdb22;p=kivitendo-erp.git Funktionen 'snakify' und 'camelify' nach SL::Util verschoben, gebugfixt, getestet --- diff --git a/SL/DB/Helper/Mappings.pm b/SL/DB/Helper/Mappings.pm index 35845a8ea..cc4d2abe1 100644 --- a/SL/DB/Helper/Mappings.pm +++ b/SL/DB/Helper/Mappings.pm @@ -3,6 +3,8 @@ package SL::DB::Helper::Mappings; use utf8; use strict; +use SL::Util qw(camelify); + require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(get_table_for_package get_package_for_table get_package_names); @@ -157,18 +159,6 @@ sub db { die "Can't resolve '$string' as a database model, sorry. Did you perhaps forgot to load it?"; } -sub camelify { - my ($str) = @_; - $str =~ s/_+(.)/uc($1)/ge; - ucfirst $str; -} - -sub snakify { - my ($str) = @_; - $str =~ s/(? + +Returns C<$string> converted from underscore-style to +camel-case-style, e.g. for the string C it will +return C. + +L does the reverse. + +=item C + +Returns C<$string> converted from camel-case-style to +underscore-style, e.g. for the string C it will +return C. + +L does the reverse. + =back =head1 BUGS diff --git a/t/helper/camelify.t b/t/helper/camelify.t new file mode 100644 index 000000000..0b5f8e3c6 --- /dev/null +++ b/t/helper/camelify.t @@ -0,0 +1,16 @@ +use Test::More tests => 8; + +use strict; + +use lib 't'; + +use SL::Util qw(camelify); + +is(camelify('hello'), 'Hello', 'hello'); +is(camelify('hello_world'), 'HelloWorld', 'hello_world'); +is(camelify('hello_world_'), 'HelloWorld_', 'hello_world_'); +is(camelify('charlie_the_unicorn'), 'CharlieTheUnicorn', 'charlie_the_unicorn'); +is(camelify('_charlie_the_unicorn'), 'CharlieTheUnicorn', '_charlie_the_unicorn'); +is(camelify('hello__world'), 'HelloWorld', 'hello__world'); +is(camelify('hELLO'), 'HELLO', 'hELLO'); +is(camelify('hellO_worlD'), 'HellOWorlD', 'hellO_worlD'); diff --git a/t/helper/snakify.t b/t/helper/snakify.t new file mode 100644 index 000000000..2a301bf40 --- /dev/null +++ b/t/helper/snakify.t @@ -0,0 +1,15 @@ +use Test::More tests => 7; + +use strict; + +use lib 't'; + +use SL::Util qw(snakify); + +is(snakify('Hello'), 'hello', 'Hello'); +is(snakify('HelloWorld'), 'hello_world', 'helloWorld'); +is(snakify('HelloWorld_'), 'hello_world_', 'helloWorld_'); +is(snakify('charlieTheUnicorn'), 'charlie_the_unicorn', 'charlieTheUnicorn'); +is(snakify('_CharlieTheUnicorn'), '_charlie_the_unicorn', '_CharlieTheUnicorn'); +is(snakify('HEllo'), 'h_ello', 'HEllo'); +is(snakify('HELlo'), 'h_e_llo', 'HELlo');