Koan.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 87.5% 14 / 16 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 9 / 9 Podpod 80.0% 4 / 5 totaltotal 89.8% 80 / 89 CC 13 SCAR 17.1
CC
13
Cov
90%
as_html
9.4
new
5.0
BEGIN
1.0
CRAP 5.6
↑ Summary Koans.pm »
1 package Zen::Koan;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.02';
7  
8 109 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
9 109 my $class = shift;
10 109 my %opts;
11 109 ▶ if (@_ == 1 and ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 103 6 109
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
60103
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
12 103 %opts = %{ $_[0] };
13 }
14 6 else { %opts = @_ }
15 109 ▶ $opts{title} ||= 'A koan by no other name';
Condition100%2/2
$opts{"title"} ||= "A koan by no other name"
l!l
1054
MC/DC100%1/1
$opts{"title"} ||= "A koan by no other name"
$opts{"title"}
Truth table100%2/2
A
A= $opts{"title"}
Aresult
11
00
16 109 ▶ $opts{body} ||= 'This koan offers little wisdom. It just is.';
Condition100%2/2
$opts{"body"} ||= "This koan offers little wisdom. It just is."
l!l
1063
MC/DC100%1/1
$opts{"body"} ||= "This koan offers little wisdom. It just is."
$opts{"body"}
Truth table100%2/2
A
A= $opts{"body"}
Aresult
11
00
17  
18 my $self = { title => $opts{title},
19 body => $opts{body},
20 109 indent_level => 0,
21 current_indent => 0,
22 };
23  
24 109 bless $self, $class;
25 109 return $self;
26 }
27  
28 5 ▶sub title { $_[0]->{title} }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
29 4 ▶sub body { $_[0]->{body} }
Subroutine body: called CC=1 SCAR=0.0
Pod documented
30  
31 4 ▶sub as_html {
Subroutine as_html: called CC=9 SCAR=22.4
Pod documented
32 4 my $self = shift;
33 4 my $body = '';
34 4 for my $p (split "\n", $self->{body}) {
35 13 ▶ next if $p =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /^\s*$/ 1 12 13
36 12 chomp $p;
37 12 ▶ if ($p =~ s/^(\s+)//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ s/^(\s+)//) { } 2 10 12
elsif ($self->{'indent_level'}) { } 1 9 10
38 2 my $indent = length $1;
39 2 ▶ if ($indent > $self->{current_indent}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($indent > $self->{'current_indent'}) { } 1 1 2
elsif ($indent < $self->{'current_indent'}) { } 0 1 1
40 1 $self->{indent_level}++;
41 1 $body .= "<blockquote>\n";
42 }
43 elsif ($indent < $self->{current_indent}) {
44 0 $self->{indent_level}--;
45 0 $body .= "</blockquote>\n";
46 }
47 2 $self->{current_indent} = $indent;
48 }
49 elsif ($self->{indent_level}) {
50 1 ▶ while ($self->{indent_level}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"indent_level"}) 1 1 2
51 1 $self->{indent_level}--;
52 1 $body .= "</blockquote>\n";
53 }
54 }
55 12 $body .= "<p>$p</p>\n";
56 }
57 4 ▶ while ($self->{indent_level}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"indent_level"}) 0 4 4
58 0 $self->{indent_level}--;
59 0 $body .= "</blockquote>\n";
60 }
61 4 return <<EOT;
62 <div id='koan_title'>$self->{title}</div>
63 <div id='koan_body'>
64 $body</div>
65 EOT
66 }
67  
68 102 ▶sub as_text {
Subroutine as_text: called CC=1 SCAR=0.0
Pod undocumented
69 102 my $self = shift;
70 102 return "\t$self->{title}\n\n$self->{body}";
71 }
72  
73 110 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
74 return <<EOT
75 You are expecting too much from this koan.
76  
77 Look within for more answers.
78 EOT
79 110 }
80  
81 3 1;
82  
83 __END__
↑ Summary Koans.pm »