5 use parent qw(Exporter);
 
   9 our @EXPORT_OK = qw(_hashify camelify snakify);
 
  14   croak "Invalid number of entries to keep" if 0 > $keep;
 
  16   return @_[0..scalar(@_) - 1] if $keep >= scalar(@_);
 
  17   return ($keep ? @_[0..$keep - 1] : (),
 
  18           ((1 + $keep) == scalar(@_)) && ((ref($_[$keep]) || '') eq 'HASH') ? %{ $_[$keep] } : @_[$keep..scalar(@_) - 1]);
 
  23   $str =~ s/_+([[:lower:]])/uc($1)/ge;
 
  29   $str =~ s/_([[:upper:]])/'_' . lc($1)/ge;
 
  30   $str =~ s/(?<!^)([[:upper:]])/'_' . lc($1)/ge;
 
  43 SL::Util - Assorted utility functions
 
  47 Most important things first:
 
  49 DO NOT USE C<@EXPORT> HERE! Only C<@EXPORT_OK> is allowed!
 
  55 =item C<_hashify $num, @args>
 
  57 Hashifies the very last argument. Returns a list consisting of two
 
  60 The first part are the first C<$num> elements of C<@args>.
 
  62 The second part depends on the remaining arguments. If exactly one
 
  63 argument remains and is a hash reference then its dereferenced
 
  64 elements will be used. Otherwise the remaining elements of C<@args>
 
  65 will be returned as-is.
 
  67 Useful if you want to write code that can be called from Perl code and
 
  68 Template code both. Example:
 
  70   use SL::Util qw(_hashify);
 
  73     my ($self, %params) = _hashify(1, @_);
 
  74     # Now do stuff, obviously!
 
  77 =item C<camilify $string>
 
  79 Returns C<$string> converted from underscore-style to
 
  80 camel-case-style, e.g. for the string C<stupid_example_dude> it will
 
  81 return C<StupidExampleDude>.
 
  83 L</snakify> does the reverse.
 
  85 =item C<snakify $string>
 
  87 Returns C<$string> converted from camel-case-style to
 
  88 underscore-style, e.g. for the string C<EvenWorseExample> it will
 
  89 return C<even_worse_example>.
 
  91 L</camilify> does the reverse.
 
 101 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>