blib/lib/Text/Xslate/Bridge/Star.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 80.5% 29 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 100% 8 / 8 totaltotal 85.7% 96 / 112 CC 20 SCAR 11.9
CC
20
Cov
85%
__ANON__
6.0
replace
4.1
substr
4.0
CRAP 3.3
« blib/lib/Text/Xslate/Syntax/TTerse.pm ↑ Summary blib/lib/Text/Xslate/PP/Method.pm »
1 package Text::Xslate::Bridge::Star;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use parent qw(Text::Xslate::Bridge);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=12.2
7 2 ▶ if(my $code = re->can('is_regexp')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = 're'->can('is_regexp')) { } 2 0 2
8 2 *_is_rx = $code;
9 }
10 else {
11 0 require Scalar::Util;
12 0 ▶ *_is_rx = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
13 0 ▶ return Scalar::Util::blessed($_[0])
Condition0%0/3
builtin::blessed($_[0]) && $_[0]->isa('Regexp')
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_[0]) && $_[0]->isa('Regexp')
builtin::blessed($_[0]) $_[0]->isa('Regexp')
Truth table0%0/3
A && B
A= builtin::blessed($_[0])B= $_[0]->isa('Regexp')
ABresult
0X0
100
111
14 && $_[0]->isa('Regexp');
15 0 };
16 }
17 }
18  
19 6 ▶sub lc {
Subroutine lc: called CC=2 SCAR=6.9
Pod documented
20 6 ▶ return defined($_[0]) ? CORE::lc($_[0]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 4 2 6
21 }
22  
23 6 ▶sub uc {
Subroutine uc: called CC=2 SCAR=6.9
Pod documented
24 6 ▶ return defined($_[0]) ? CORE::uc($_[0]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 4 2 6
25 }
26  
27 8 ▶sub substr {
Subroutine substr: called CC=4 SCAR=13.9
Pod documented
28 8 my($str, $offset, $length) = @_;
29 8 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 2 6 8
30 6 ▶ $offset = 0 unless defined $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $offset 0 6 6
31 6 ▶ $length = length($str) unless defined $length;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 4 2 6
32 6 return CORE::substr($str, $offset, $length);
33 }
34  
35  
36 4 ▶sub sprintf {
Subroutine sprintf: called CC=3 SCAR=11.0
Pod documented
37 4 my $fmt = shift;
38 4 ▶ return undef unless defined $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt 0 4 4
39 4 ▶ if(@_) { # sprintf($fmt, ...)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 2 4
40 2 return sprintf $fmt, @_;
41 }
42 else { # $x | sprintf('%.02f')
43 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 2 sprintf $fmt, @_;
45 2 };
46 }
47 }
48  
49 12 ▶sub rx {
Subroutine rx: called CC=2 SCAR=7.6
Pod documented
50 12 ▶ return defined($_[0]) ? qr/$_[0]/ : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 12 0 12
51 }
52  
53 10 ▶sub match {
Subroutine match: called CC=4 SCAR=13.9
Pod documented
54 10 my($str, $pattern) = @_;
55 10 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 2 8 10
56 8 ▶ return undef unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 8 8
57  
58 8 ▶ $pattern = quotemeta($pattern) unless _is_rx($pattern);
Branch: 1 branch
BranchTrueFalseTotal
unless &_is_rx($pattern) 4 4 8
59 8 return scalar($str =~ m/$pattern/);
60 }
61  
62 8 ▶sub replace {
Subroutine replace: called CC=4 SCAR=14.0
Pod documented
63 8 my($str, $pattern, $replacement) = @_;
64 8 ▶ return undef unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 8 8
65 8 ▶ return undef unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 8 8
66  
67 8 ▶ $pattern = quotemeta($pattern) unless _is_rx($pattern);
Branch: 1 branch
BranchTrueFalseTotal
unless &_is_rx($pattern) 6 2 8
68 8 $str =~ s/$pattern/$replacement/g;
69 8 return $str;
70 }
71  
72 12 ▶sub split {
Subroutine split: called CC=4 SCAR=13.9
Pod documented
73 12 my($str,$pattern,$limit) = @_;
74 12 ▶ if (!defined $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pattern) 2 10 12
75 2 $pattern = ' ';
76 }
77 12 ▶ $pattern = quotemeta($pattern) unless _is_rx($pattern);
Branch: 1 branch
BranchTrueFalseTotal
unless &_is_rx($pattern) 8 4 12
78 12 ▶ if (defined $limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit) { } 2 10 12
79 2 return [CORE::split($pattern, $str, $limit)];
80 } else {
81 10 return [CORE::split($pattern, $str)];
82 }
83 }
84  
85 2 my %scalar_methods = (
86 lc => \&lc,
87 uc => \&uc,
88 substr => \&substr,
89 sprintf => \&sprintf,
90 rx => \&rx,
91 match => \&match,
92 replace => \&replace,
93 split => \&split,
94 );
95  
96 2 __PACKAGE__->bridge(
97 # nil => \%nil_methods,
98 scalar => \%scalar_methods,
99 # array => \%array_methods,
100 # hash => \%hash_methods,
101  
102 function => \%scalar_methods,
103 );
104  
105 2 1;
106 __END__
« blib/lib/Text/Xslate/Syntax/TTerse.pm ↑ Summary blib/lib/Text/Xslate/PP/Method.pm »