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   85126 use warnings;
  3         9  
  3         97  
13 3     3   18 use strict;
  3         6  
  3         149  
14              
15             our $VERSION = '0.02';
16              
17 3     3   18 use base qw(Exporter);
  3         8  
  3         1474  
18             our @EXPORT_OK = qw(camelize decamelize wordsplit);
19              
20             1;
21              
22             sub wordsplit
23             {
24 12     12 1 26 my $s = shift;
25 12         178 split( /[_\s]+|\b|(?
26             }
27              
28             sub camelize
29             {
30 6     6 1 16 my $s = shift;
31 6         51 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
  12         54  
32             }
33              
34             sub decamelize
35             {
36 8     8 1 23 my $s = shift;
37 8         61 $s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
38 12         22 my $fc = pos($s)==0;
39 12         55 my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
40 12 100 100     64 my $t = $p0 || $fc ? $p0 : '_';
41 12 100       34 $t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
    100          
42 12         51 $t;
43             }ge;
44 8         44 $s;
45             }
46              
47             __END__