blib/lib/String/CamelCase.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 100% 45 / 45 CC 5 SCAR 11.0
CC
5
Cov
100%
decamelize
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
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 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = '0.04';
16  
17 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 our @EXPORT_OK = qw(camelize decamelize wordsplit);
19  
20 4 1;
21  
22 sub wordsplit
23 12 ▶{
Subroutine wordsplit: called CC=1 SCAR=0.0
Pod documented
24 12 my $s = shift;
25 12 split( /[_\s]+|\b|(?<![A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/, $s );
26 }
27  
28 sub camelize
29 6 ▶{
Subroutine camelize: called CC=1 SCAR=0.0
Pod documented
30 6 my $s = shift;
31 6 join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s));
32 }
33  
34 sub decamelize
35 8 ▶{
Subroutine decamelize: called CC=5 SCAR=16.1
Pod documented
36 8 my $s = shift;
37 8 $s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
38 12 my $fc = pos($s)==0;
39 12 my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
40 12 ▶ my $t = $p0 || $fc ? $p0 : '_';
Branch: 1 branch
BranchTrueFalseTotal
$p0 || $fc ? : 8 4 12
Condition100%3/3
$p0 or $fc
l!l&&r!l&&!r
264
MC/DC100%2/2
$p0 or $fc
$p0 $fc
Truth table100%3/3
A or B
A= $p0B= $fc
ABresult
1X1
011
000
41 12 ▶ $t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
Branch: 2 branches
BranchTrueFalseTotal
$p3 ? : 10 2 12
$p1 ? : 4 6 10
42 12 $t;
43 }ge;
44 8 $s;
45 }
46  
47 __END__
↑ Summary