File Coverage

blib/lib/String/CamelCase.pm
Criterion Covered Total %
statement 22 22 100.0
branch 6 6 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 3 3 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             ## ----------------------------------------------------------------------------
2             # String::CamelCase
3             # -----------------------------------------------------------------------------
4             # Mastering programmed by YAMASHINA Hio
5             #
6             # Copyright 2006 YAMASHINA Hio
7             # -----------------------------------------------------------------------------
8             # $Id$
9             # -----------------------------------------------------------------------------
10             package String::CamelCase;
11              
12 3     3   184018 use warnings;
  3         36  
  3         100  
13 3     3   17 use strict;
  3         7  
  3         118  
14              
15             our $VERSION = '0.04';
16              
17 3     3   18 use base qw(Exporter);
  3         15  
  3         1448  
18             our @EXPORT_OK = qw(camelize decamelize wordsplit);
19              
20             1;
21              
22             sub wordsplit
23             {
24 12     12 1 24 my $s = shift;
25 12         141 split( /[_\s]+|\b|(?
26             }
27              
28             sub camelize
29             {
30 6     6 1 85 my $s = shift;
31 6         41 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
  12         51  
32             }
33              
34             sub decamelize
35             {
36 8     8 1 90 my $s = shift;
37 8         56 $s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
38 12         25 my $fc = pos($s)==0;
39 12         62 my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
40 12 100 100     50 my $t = $p0 || $fc ? $p0 : '_';
41 12 100       32 $t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
    100          
42 12         49 $t;
43             }ge;
44 8         38 $s;
45             }
46              
47             __END__