| 1 | ## no critic: Modules::RequireExplicitPackage | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | package Org::Parser::Tiny; | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||
| 10 | 2 | our $DATE = '2020-02-07'; # DATE | |||||||||||||||||||||||||||||||||
| 11 | 2 | our $DIST = 'Org-Parser-Tiny'; # DIST | |||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.005'; # VERSION | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 16 | 0 | bless {}, $class; | |||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=17 SCAR=31.0
| |||||||||||||||||||||||||||||||||||
| 20 | 1 | my ($self, $lines, $opts) = @_; | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # stage 1: get todo keywords | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 1 | my @undone_keywords; | |||||||||||||||||||||||||||||||||
| 25 | my @done_keywords; | ||||||||||||||||||||||||||||||||||
| 26 | 1 | my $linenum = 0; | |||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | while ($linenum < @$lines) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 28 | 17 | my $line = $lines->[$linenum]; | |||||||||||||||||||||||||||||||||
| 29 | 17 | $linenum++; | |||||||||||||||||||||||||||||||||
| 30 | 17 | ▶ | if ($line =~ s/^#\+TODO:\s*//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my ($undone_keywords, $done_keywords) = | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | $line =~ /^\s*(.*?)\s*\|\s*(.*?)\s*$/ | ||||||||||||||||||||||||||||||||||
| 33 | or die "Line $linenum: Invalid #+TODO: please use ... | ..."; | ||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | while ($undone_keywords =~ /(\w+)/g) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | push @undone_keywords, $1; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | while ($done_keywords =~ /(\w+)/g) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | push @done_keywords, $1; | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | @undone_keywords = ("TODO") unless @undone_keywords; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | @done_keywords = ("DONE") unless @done_keywords; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 1 | my $undone_re = join("|", @undone_keywords); $undone_re= qr/(?:$undone_re)/; | |||||||||||||||||||||||||||||||||
| 45 | 1 | my $done_re = join("|", @done_keywords ); $done_re = qr/(?:$done_re)/; | |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | # stage 2: build nodes | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | # a linear list of nodes | ||||||||||||||||||||||||||||||||||
| 50 | 1 | my @nodes = ( | |||||||||||||||||||||||||||||||||
| 51 | Org::Parser::Tiny::Node::Document->new(), | ||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 1 | $linenum = 0; | |||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | while ($linenum < @$lines) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 17 | my $line = $lines->[$linenum]; | |||||||||||||||||||||||||||||||||
| 57 | 17 | $linenum++; | |||||||||||||||||||||||||||||||||
| 58 | 17 | ▶ | if ($line =~ /^(\*+) (.*)/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 59 | #say "D: got headline $line"; | ||||||||||||||||||||||||||||||||||
| 60 | 11 | my $level = length($1); | |||||||||||||||||||||||||||||||||
| 61 | 11 | my $title = $2; | |||||||||||||||||||||||||||||||||
| 62 | 11 | my $node = Org::Parser::Tiny::Node::Headline->new( | |||||||||||||||||||||||||||||||||
| 63 | _str => $line, | ||||||||||||||||||||||||||||||||||
| 64 | level => $level, | ||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | # extract todo state | ||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | if ($title =~ s/\s*($undone_re)\s+//) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | $node->{is_todo} = 1; | |||||||||||||||||||||||||||||||||
| 70 | 0 | $node->{is_done} = 0; | |||||||||||||||||||||||||||||||||
| 71 | 0 | $node->{todo_state} = $1; | |||||||||||||||||||||||||||||||||
| 72 | } elsif ($title =~ s/\s*($done_re)\s+//) { | ||||||||||||||||||||||||||||||||||
| 73 | 0 | $node->{is_todo} = 1; | |||||||||||||||||||||||||||||||||
| 74 | 0 | $node->{is_done} = 1; | |||||||||||||||||||||||||||||||||
| 75 | 0 | $node->{todo_state} = $1; | |||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||
| 77 | 11 | $node->{is_todo} = 0; | |||||||||||||||||||||||||||||||||
| 78 | 11 | $node->{is_done} = 0; | |||||||||||||||||||||||||||||||||
| 79 | 11 | $node->{todo_state} = ""; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | # extract tags | ||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | if ($title =~ s/\s+:((?:\w+:)+)$//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | 1 | my $tags = $1; | |||||||||||||||||||||||||||||||||
| 85 | 1 | my @tags; | |||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | while ($tags =~ /(\w+)/g) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 1 | push @tags, $1; | |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | 1 | $node->{tags} = \@tags; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 11 | $node->{title} = $title; | |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | # find the first node which has the lower level (or the root node) | ||||||||||||||||||||||||||||||||||
| 95 | # as the parent node | ||||||||||||||||||||||||||||||||||
| 96 | 11 | my $i = $#nodes; | |||||||||||||||||||||||||||||||||
| 97 | 11 | ▶ | while ($i >= 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 44 | ▶ | if ($i == 0 || $nodes[$i]{level} < $level) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i == 0 or $nodes[$i]{"level"} < $level
MC/DC100%2/2
$i == 0 or $nodes[$i]{"level"} < $level
$i == 0
$nodes[$i]{"level"} < $level
Truth table100%3/3
A or B
A= $i == 0B= $nodes[$i]{"level"} < $level
| |||||||||||||||||||||||||||||||||||
| 99 | 11 | $node->{parent} = $nodes[$i]; | |||||||||||||||||||||||||||||||||
| 100 | 11 | push @{ $nodes[$i]{children} }, $node; | |||||||||||||||||||||||||||||||||
| 101 | 11 | last; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | 33 | $i--; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | 11 | push @nodes, $node; | |||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||
| 107 | 6 | $nodes[-1]{preamble} .= $line; | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | 1 | $nodes[0]; | |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=10 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 115 | 1 | my ($self, $arg, $opts) = @_; | |||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | die "Please specify a defined argument to parse()\n" unless defined($arg); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 1 | my $lines; | |||||||||||||||||||||||||||||||||
| 121 | 1 | my $r = ref($arg); | |||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if (!$r) { | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 123 | 1 | $lines = [split /^/, $arg]; | |||||||||||||||||||||||||||||||||
| 124 | } elsif ($r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||
| 125 | 0 | $lines = [@$arg]; | |||||||||||||||||||||||||||||||||
| 126 | ▶ | } elsif ($r eq 'GLOB' || blessed($arg) && $arg->isa('IO::Handle')) { | |||||||||||||||||||||||||||||||||
|
Condition0%0/6
$r eq "GLOB" or blessed($arg) and $arg->isa("IO::Handle")
blessed($arg) and $arg->isa("IO::Handle")
MC/DC0%0/3
$r eq "GLOB" or blessed($arg) and $arg->isa("IO::Handle")
$r eq "GLOB"
blessed($arg)
$arg->isa("IO::Handle")
Truth table0%0/4
A or B and C
A= $r eq "GLOB"B= blessed($arg)C= $arg->isa("IO::Handle")
| |||||||||||||||||||||||||||||||||||
| 127 | #$lines = split(/^/, join("", <$arg>)); | ||||||||||||||||||||||||||||||||||
| 128 | 0 | $lines = [<$arg>]; | |||||||||||||||||||||||||||||||||
| 129 | } elsif ($r eq 'CODE') { | ||||||||||||||||||||||||||||||||||
| 130 | 0 | my @chunks; | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | while (defined(my $chunk = $arg->())) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | 0 | push @chunks, $chunk; | |||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | 0 | $lines = [split /^/, (join "", @chunks)]; | |||||||||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||||||||
| 136 | 0 | die "Invalid argument, please supply a ". | |||||||||||||||||||||||||||||||||
| 137 | "string|arrayref|coderef|filehandle\n"; | ||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||
| 139 | 1 | $self->_parse($lines, $opts); | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub parse_file { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 143 | 0 | my ($self, $filename, $opts) = @_; | |||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $opts ||= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 0 | my $content = do { | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | open my($fh), "<", $filename or die "Can't open $filename: $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | local $/; | |||||||||||||||||||||||||||||||||
| 149 | 0 | scalar(<$fh>); | |||||||||||||||||||||||||||||||||
| 150 | }; | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->parse($content, $opts); | |||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | # abstract class: Org::Parser::Tiny::Node | ||||||||||||||||||||||||||||||||||
| 157 | package Org::Parser::Tiny::Node; | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 160 | 12 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||
| 161 | 12 | ▶ | $args{children} //= []; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"children"} //= []
MC/DC0%0/1
$args{"children"} //= []
$args{"children"}
Truth table50%1/2
A
A= $args{"children"}
| |||||||||||||||||||||||||||||||||||
| 162 | 12 | bless \%args, $class; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||
|
Subroutine
parent: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 0 | $_[0]{parent} = $_[1]; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | 0 | $_[0]{parent}; | |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 11 | ▶ | sub children { | ||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||
| 173 | 11 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | 0 | $_[0]{children} = $_[1]; | |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||
| 176 | 11 | ▶ | $_[0]{children} || []; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub as_string { $_[0]{_str} } | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | 8 | ▶ | sub children_as_string { join("", map { $_->as_string } @{ $_[0]->children }) } | ||||||||||||||||||||||||||||||||
|
Subroutine
children_as_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | # abstract class: Org::Parser::Tiny::HasPreamble | ||||||||||||||||||||||||||||||||||
| 184 | package Org::Parser::Tiny::Node::HasPreamble; | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | 2 | our @ISA = qw(Org::Parser::Tiny::Node); | |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 189 | 12 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||
| 190 | 12 | ▶ | $args{preamble} //= ""; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"preamble"} //= ""
MC/DC0%0/1
$args{"preamble"} //= ""
$args{"preamble"}
Truth table50%1/2
A
A= $args{"preamble"}
| |||||||||||||||||||||||||||||||||||
| 191 | 12 | $class->SUPER::new(%args); | |||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | # class: Org::Parser::Tiny::Document: top level node | ||||||||||||||||||||||||||||||||||
| 196 | package Org::Parser::Tiny::Node::Document; | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 2 | our @ISA = qw(Org::Parser::Tiny::Node::HasPreamble); | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 201 | 0 | $_[0]->{preamble} . $_[0]->children_as_string; | |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | # class: Org::Parser::Tiny::Node::Headline: headline with its content | ||||||||||||||||||||||||||||||||||
| 206 | package Org::Parser::Tiny::Node::Headline; | ||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||
| 208 | 2 | our @ISA = qw(Org::Parser::Tiny::Node::HasPreamble); | |||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub level { | ||||||||||||||||||||||||||||||||
|
Subroutine
level: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{level} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 212 | 0 | $_[0]{level}; | |||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub title { | ||||||||||||||||||||||||||||||||
|
Subroutine
title: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{title} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 217 | 0 | $_[0]{title}; | |||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub is_todo { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_todo: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{is_todo} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 0 | $_[0]{is_todo}; | |||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub is_done { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_done: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{is_done} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | $_[0]{is_done}; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub todo_state { | ||||||||||||||||||||||||||||||||
|
Subroutine
todo_state: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{todo_state} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | 0 | $_[0]{todo_state}; | |||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub tags { | ||||||||||||||||||||||||||||||||
|
Subroutine
tags: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if (@_ > 1) { undef $_[0]{_str}; $_[0]{tags} = $_[1] } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $_[0]{tags} || []; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | sub header_as_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
header_as_string: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||
| 241 | ($_[0]->{_str} // | ||||||||||||||||||||||||||||||||||
| 242 | join('', | ||||||||||||||||||||||||||||||||||
| 243 | "*" x $_[0]{level}, | ||||||||||||||||||||||||||||||||||
| 244 | " ", | ||||||||||||||||||||||||||||||||||
| 245 | (length $_[0]{todo_state} ? "$_[0]{todo_state} " : ""), | ||||||||||||||||||||||||||||||||||
| 246 | "$_[0]{title}", | ||||||||||||||||||||||||||||||||||
| 247 | 8 | ▶ | (defined $_[0]{tags} ? " :".join(":", @{ $_[0]{tags} }).":" : ""), | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$_[0]{"_str"} // join("", "*" x $_[0]{"level"}, " ", length $_[0]{"todo_state"} ? qq[$_[0]{"todo_state"} ] : "", qq[$_[0]{"title"}], defined $_[0]{"tags"} ? ' :' . join(":", @{$_[0]{"tags"};}) . ':' : "", "\n")
MC/DC100%1/1
$_[0]{"_str"} // join("", "*" x $_[0]{"level"}, " ", length $_[0]{"todo_state"} ? qq[$_[0]{"todo_state"} ] : "", qq[$_[0]{"title"}], defined $_[0]{"tags"} ? ' :' . join(":", @{$_[0]{"tags"};}) . ':' : "", "\n")
$_[0]{"_str"}
Truth table100%2/2
A
A= $_[0]{"_str"}
| |||||||||||||||||||||||||||||||||||
| 248 | "\n", | ||||||||||||||||||||||||||||||||||
| 249 | )); | ||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 253 | $_[0]->header_as_string . | ||||||||||||||||||||||||||||||||||
| 254 | $_[0]->{preamble} . | ||||||||||||||||||||||||||||||||||
| 255 | 8 | $_[0]->children_as_string; | |||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 259 | # ABSTRACT: Parse Org documents with as little code (and no non-core deps) as possible | ||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||
| 261 | __END__ | ||||||||||||||||||||||||||||||||||