Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bc3a01ae

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID bc3a01aef9a58d5e22137dbcc38fec7abebfdb22
  • Vorgänger fc1490e8
  • Nachfolger c8e0c77f

Funktionen 'snakify' und 'camelify' nach SL::Util verschoben, gebugfixt, getestet

Unterschiede anzeigen:

SL/Util.pm
6 6

  
7 7
use Carp;
8 8

  
9
our @EXPORT_OK = qw(_hashify);
9
our @EXPORT_OK = qw(_hashify camelify snakify);
10 10

  
11 11
sub _hashify {
12 12
  my $keep = shift;
......
18 18
          ((1 + $keep) == scalar(@_)) && ((ref($_[$keep]) || '') eq 'HASH') ? %{ $_[$keep] } : @_[$keep..scalar(@_) - 1]);
19 19
}
20 20

  
21
sub camelify {
22
  my ($str) = @_;
23
  $str =~ s/_+([[:lower:]])/uc($1)/ge;
24
  ucfirst $str;
25
}
26

  
27
sub snakify {
28
  my ($str) = @_;
29
  $str =~ s/_([[:upper:]])/'_' . lc($1)/ge;
30
  $str =~ s/(?<!^)([[:upper:]])/'_' . lc($1)/ge;
31
  lc $str;
32
}
33

  
21 34
1;
22 35
__END__
23 36

  
......
61 74
    # Now do stuff, obviously!
62 75
  }
63 76

  
77
=item C<camilify $string>
78

  
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>.
82

  
83
L</snakify> does the reverse.
84

  
85
=item C<snakify $string>
86

  
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>.
90

  
91
L</camilify> does the reverse.
92

  
64 93
=back
65 94

  
66 95
=head1 BUGS

Auch abrufbar als: Unified diff