lib/Badger/Data/Facet/Text/Whitespace.pm

filter: Statementstmt 100% 18 / 18 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 87.5% 28 / 32 CC 6 SCAR 12.0
CC
6
Cov
88%
validate
4.0
init
3.1
BEGIN
1.0
CRAP 3.3
« lib/Badger/Codec/Chain.pm ↑ Summary lib/Badger/Filesystem/Base.pm »
1 package Badger::Data::Facet::Text::Whitespace;
2  
3 use Badger::Data::Facet::Class
4 1 ▶ version => 0.01,
Subroutine BEGIN: called CC=1 SCAR=0.0
5 type => 'text',
6 args => 'whitespace',
7 constant => {
8 PRESERVE => 0,
9 FOLD => 1,
10 COLLAPSE => 2,
11 1 };
12  
13 1 our $ACTION = {
14 preserve => PRESERVE,
15 fold => FOLD,
16 collapse => COLLAPSE,
17 };
18  
19  
20 2 ▶sub init {
Subroutine init: called CC=3 SCAR=11.4
Pod documented
21 2 my ($self, $config) = @_;
22  
23 2 ▶ $self->SUPER::init($config)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($config) or return 2 0 2
24 || return;
25  
26 # option must have an entry in $ACCEPT which we store in $self->{ action }
27 return $self->error_msg( whitespace => $self->{ whitespace }, join(', ', keys %$ACTION) )
28 2 ▶ unless defined ($self->{ action } = $ACTION->{ $self->{ whitespace } });
Branch: 1 branch
BranchTrueFalseTotal
unless defined($self->{"action"} = $$Badger::Data::Facet::Text::Whitespace::ACTION{$self->{"whitespace"}}) 0 2 2
29
30 2 return $self;
31 }
32  
33  
34 2 ▶sub validate {
Subroutine validate: called CC=4 SCAR=13.9
Pod documented
35 2 my ($self, $text, $type) = @_;
36 my $action = $self->{ action } # do nothing for PRESERVE
37 2 ▶ || return $text;
Condition50%1/2
$self->{'action'} || (return $text)
l!l
20
MC/DC0%0/1
$self->{'action'} || (return $text)
$self->{'action'}
Truth table50%1/2
A
A= $self->{'action'}
Aresult
11
00
38  
39 2 for ($$text) {
40 2 s/[\r\n\t]/ /g;
41 2 ▶ if ($action == COLLAPSE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action == 2) 1 1 2
42 1 s/ +/ /g;
43 1 s/^ +//;
44 1 s/ +$//;
45 }
46 }
47
48 2 return $text;
49 }
50  
51  
52 1 1;
53  
54 __END__
« lib/Badger/Codec/Chain.pm ↑ Summary lib/Badger/Filesystem/Base.pm »