| 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
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 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"
MC/DC100%1/1
$opts{"title"} ||= "A koan by no other name"
$opts{"title"}
Truth table100%2/2
A
A= $opts{"title"}
| |||||||||||||||||||||||||||||
| 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."
MC/DC100%1/1
$opts{"body"} ||= "This koan offers little wisdom. It just is."
$opts{"body"}
Truth table100%2/2
A
A= $opts{"body"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 36 | 12 | chomp $p; | |||||||||||||||||||||||||||
| 37 | 12 | ▶ | if ($p =~ s/^(\s+)//) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | 2 | my $indent = length $1; | |||||||||||||||||||||||||||
| 39 | 2 | ▶ | if ($indent > $self->{current_indent}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||