blib/lib/Lingua/PigLatin/Bidirectional.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 49 / 49 CC 5 SCAR 7.4
CC
5
Cov
100%
to_piglatin
3.0
from_piglatin
3.0
BEGIN
1.0
CRAP 2.1
↑ Summary
1 package Lingua::PigLatin::Bidirectional;
2 3 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our @EXPORT = qw(to_piglatin from_piglatin);
9  
10 3 our $VERSION = "0.01";
11  
12 4 ▶sub to_piglatin {
Subroutine to_piglatin: called CC=3 SCAR=11.0
Pod documented
13 4 my $str = shift;
14  
15 4 $str =~ s{\b # See if each given word starts w/ or w/o
16 ( qu # 1. qu (e.g. question => estionquay)
17 | [cgpstw]h # 2. digraphs
18 | [^\W0-9_aeiou] # 3. any "word" character other than
19 # 0-9, _ and vowels
20 )?
21 ( [a-z]+ ) # and then alphabet character(s)
22 }
23 {
24 29 ▶ if ( my $pre = $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pre = $1) { } 21 8 29
25 # if the first rule applies, append former part and add -ay
26 21 my $post = $2;
27 21 ▶ $pre =~ /\A [A-Z]/x
Branch: 1 branch
BranchTrueFalseTotal
$pre =~ /\A [A-Z]/x ? : 5 16 21
28 ? ucfirst($post) . lcfirst($pre) . 'ay'
29 : $post . $pre . 'ay' ;
30 }
31 else {
32 # otherwise add -way
33 8 $2 . 'way';
34 }
35 }iegxms;
36  
37 4 return $str;
38 }
39  
40 4 ▶sub from_piglatin {
Subroutine from_piglatin: called CC=3 SCAR=11.0
Pod documented
41 4 my $str = shift;
42  
43 4 $str =~ s{ # See if each given word consists of...
44 ( [a-z]+ )way # alphabet character(s) followed by "way"
45 | # OR...
46 ( [a-z]+? ) # zero or alphabet character(s) followed by...
47 ( qu # 1. qu
48 | [cgpstw]h # 2. digraphs
49 | [^\W0-9_aeiou] # 3. any "word" character other than
50 # 0-9, _ and vowels
51 )ay # and trailing "ay"
52 \b}
53 {
54 29 ▶ if ($1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) { } 8 21 29
55 8 $1;
56 }
57 else {
58 21 my $pre = $2;
59 21 my $post = $3;
60 21 ▶ $pre =~ m/\A [A-Z]/x
Branch: 1 branch
BranchTrueFalseTotal
$pre =~ /\A [A-Z]/x ? : 5 16 21
61 ? ucfirst($post) . lcfirst($pre)
62 : $post . $pre ;
63 }
64 }iegxms;
65  
66 4 return $str;
67 }
68  
69 3 1;
70 __END__
↑ Summary