| 1 | package Org::Element::Headline; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use locale; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | extends 'Org::Element'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | with 'Org::ElementRole'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | with 'Org::ElementRole::Block'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 17 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | our $DATE = '2026-07-21'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | our $DIST = 'Org-Parser'; # DIST | |||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | our $VERSION = '0.563'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 17 | has level => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 17 | has title => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | has priority => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | has tags => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | has is_todo => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | has is_done => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 17 | has todo_state => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | has statistics_cookie => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # old name, deprecated since 2014-07-17, will be removed in the future | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub todo_priority { shift->priority(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
todo_priority: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 161 | ▶ | sub extra_walkables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extra_walkables: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 161 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 161 | grep {defined} ($self->title); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 24 | ▶ | sub header_as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_as_string: called CC=7 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 24 | ▶ | return $self->_str if defined $self->_str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | join("", | ||||||||||||||||||||||||||||||||||||||||||
| 38 | "*" x $self->level, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | " ", | ||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->is_todo ? $self->todo_state." " : "", | ||||||||||||||||||||||||||||||||||||||||||
| 41 | $self->priority ? "[#".$self->priority."] " : "", | ||||||||||||||||||||||||||||||||||||||||||
| 42 | $self->statistics_cookie ? "[".$self->statistics_cookie."] " : "", | ||||||||||||||||||||||||||||||||||||||||||
| 43 | $self->title->as_string, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->tags && @{$self->tags} ? | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | " :".join(":", @{$self->tags}).":" : "", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
$self->tags and @{$self->tags;}
MC/DC0%0/2
$self->tags and @{$self->tags;}
$self->tags
@{$self->tags;}
Truth table33%1/3
A and B
A= $self->tagsB= @{$self->tags;}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | "\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 24 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 24 | $self->header_as_string . $self->children_as_string; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub get_tags { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_tags: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | my @res = @{ $self->tags // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->tags // []
MC/DC100%1/1
$self->tags // []
$self->tags
Truth table100%2/2
A
A= $self->tags
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->walk_parents( | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 7 | my ($el, $parent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | return 1 unless $parent->isa('Org::Element::Headline'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if ($parent->tags) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | for my $tag (@{ $parent->tags }) { | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | push @res, $tag unless grep { $_ eq $tag } @res; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | }); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | for my $tag (@{ $self->document->tags }) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | push @res, $tag unless grep { $_ eq $tag } @res; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | @res; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub get_active_timestamp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_active_timestamp: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | for my $s ($self->title, $self) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | my $ats; | |||||||||||||||||||||||||||||||||||||||||
| 79 | $s->walk( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 24 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 24 | my ($el) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 24 | ▶ | return if $ats; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 19 | ▶ | $ats = $el if $el->isa('Org::Element::Timestamp') && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$el->isa("Org::Element::Timestamp") and $el->is_active
MC/DC100%2/2
$el->isa("Org::Element::Timestamp") and $el->is_active
$el->isa("Org::Element::Timestamp")
$el->is_active
Truth table100%3/3
A and B
A= $el->isa("Org::Element::Timestamp")B= $el->is_active
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | $el->is_active; | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | ▶ | return $ats if $ats; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | sub is_leaf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_leaf: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | return 1 unless $self->children; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | my $res; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | for my $child (@{ $self->children }) { | |||||||||||||||||||||||||||||||||||||||||
| 99 | $child->walk( | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | return if defined($res); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my ($el) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | if ($el->isa('Org::Element::Headline')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | $res = 0; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | goto EXIT_WALK; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | EXIT_WALK: | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | $res //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res //= 1
MC/DC0%0/1
$res //= 1
$res
Truth table50%1/2
A
A= $res
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | $res; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | sub promote_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
promote_node: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | my ($self, $num_levels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | $num_levels //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$num_levels //= 1
MC/DC100%1/1
$num_levels //= 1
$num_levels
Truth table100%2/2
A
A= $num_levels
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | ▶ | return if $num_levels == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | ▶ | $self->die("Please specify a positive number of levels") if $num_levels < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | for my $i (1..$num_levels) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | my $l = $self->level; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | ▶ | last if $l <= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 8 | $l--; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | $self->level($l); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | $self->_str(undef); | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | my $siblings = $parent->children; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | my $pos = $self->seniority; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # our children stay as children | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # our right sibling headline(s) become children | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 11 | my $s = $siblings->[$pos+1]; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | ▶ | last unless $s && $s->isa('Org::Element::Headline') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$s and $s->isa("Org::Element::Headline") and $s->level > $l
$s and $s->isa("Org::Element::Headline")
MC/DC66%2/3
$s and $s->isa("Org::Element::Headline") and $s->level > $l
$s
$s->isa("Org::Element::Headline")
$s->level > $l
Truth table75%3/4
A and B and C
A= $sB= $s->isa("Org::Element::Headline")C= $s->level > $l
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | && $s->level > $l; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | ▶ | $self->children([]) unless defined $self->children; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | push @{$self->children}, $s; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | splice @$siblings, $pos+1, 1; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | $s->parent($self); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # our parent headline can become sibling if level is the same | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | ▶ | if ($parent->isa('Org::Element::Headline') && $parent->level == $l) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parent->isa("Org::Element::Headline") and $parent->level == $l
MC/DC100%2/2
$parent->isa("Org::Element::Headline") and $parent->level == $l
$parent->isa("Org::Element::Headline")
$parent->level == $l
Truth table100%3/3
A and B
A= $parent->isa("Org::Element::Headline")B= $parent->level == $l
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | splice @$siblings, $pos, 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | my $gparent = $parent->parent; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | splice @{$gparent->children}, $parent->seniority+1, 0, $self; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $self->parent($gparent); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | sub demote_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
demote_node: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | my ($self, $num_levels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | ▶ | $num_levels //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$num_levels //= 1
MC/DC100%1/1
$num_levels //= 1
$num_levels
Truth table100%2/2
A
A= $num_levels
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | return if $num_levels == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | ▶ | $self->die("Please specify a positive number of levels") if $num_levels < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | for my $i (1..$num_levels) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | my $l = $self->level; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | $l++; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | $self->level($l); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | $self->_str(undef); | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # prev sibling can become parent | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | my $ps = $self->prev_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | if ($ps && $ps->isa('Org::Element::Headline') && $ps->level < $l) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ps and $ps->isa("Org::Element::Headline") and $ps->level < $l
$ps and $ps->isa("Org::Element::Headline")
MC/DC66%2/3
$ps and $ps->isa("Org::Element::Headline") and $ps->level < $l
$ps
$ps->isa("Org::Element::Headline")
$ps->level < $l
Truth table75%3/4
A and B and C
A= $psB= $ps->isa("Org::Element::Headline")C= $ps->level < $l
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | splice @{$self->parent->children}, $self->seniority, 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | $ps->children([]) if !defined($ps->children); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | push @{$ps->children}, $self; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | $self->parent($ps); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | sub promote_branch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
promote_branch: called CC=7 SCAR=20.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | my ($self, $num_levels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | $num_levels //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$num_levels //= 1
MC/DC0%0/1
$num_levels //= 1
$num_levels
Truth table50%1/2
A
A= $num_levels
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return if $num_levels == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | $self->die("Please specify a positive number of levels") if $num_levels < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | for my $i (1..$num_levels) { | |||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | last if $self->level <= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $_->promote_node() for $self->find('Headline'); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub demote_branch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
demote_branch: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my ($self, $num_levels) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | $num_levels //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$num_levels //= 1
MC/DC0%0/1
$num_levels //= 1
$num_levels
Truth table50%1/2
A
A= $num_levels
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | return if $num_levels == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | ▶ | $self->die("Please specify a positive number of levels") if $num_levels < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | for my $i (1..$num_levels) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $_->demote_node() for $self->find('Headline'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 13 | ▶ | sub get_drawer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_drawer: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 13 | ▶ | my $wanted_drawer_name = shift || "PROPERTIES"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'PROPERTIES'
MC/DC0%0/1
shift() || 'PROPERTIES'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 13 | ▶ | for my $d (@{$self->children||[]}) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->children || []
MC/DC0%0/1
$self->children || []
$self->children
Truth table50%1/2
A
A= $self->children
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 28 | log_trace("seeking $wanted_drawer_name drawer in child: %s (%s)", $d->as_string, ref($d)); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 28 | ▶ | next unless ($d->isa('Org::Element::Drawer') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$d->isa("Org::Element::Drawer") and $d->name eq $wanted_drawer_name and $d->properties
$d->isa("Org::Element::Drawer") and $d->name eq $wanted_drawer_name
MC/DC66%2/3
$d->isa("Org::Element::Drawer") and $d->name eq $wanted_drawer_name and $d->properties
$d->isa("Org::Element::Drawer")
$d->name eq $wanted_drawer_name
$d->properties
Truth table75%3/4
A and B and C
A= $d->isa("Org::Element::Drawer")B= $d->name eq $wanted_drawer_nameC= $d->properties
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | && $d->name eq $wanted_drawer_name | ||||||||||||||||||||||||||||||||||||||||||
| 215 | && $d->properties); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 13 | return $d; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 12 | ▶ | sub get_property { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_property: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 12 | my ($self, $name, $search_parent, $search_docprop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | #$log->tracef("-> get_property(%s, search_par=%s)", $name, $search_parent); | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 12 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 12 | my $propd = $self->get_drawer("PROPERTIES"); | |||||||||||||||||||||||||||||||||||||||||
| 226 | return $propd->properties->{$name} if | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 12 | ▶ | $propd && defined $propd->properties->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$propd and defined $propd->properties->{$name}
MC/DC50%1/2
$propd and defined $propd->properties->{$name}
$propd
defined $propd->properties->{$name}
Truth table66%2/3
A and B
A= $propdB= defined $propd->properties->{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | ▶ | if ($parent && $search_parent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$parent and $search_parent
MC/DC50%1/2
$parent and $search_parent
$parent
$search_parent
Truth table66%2/3
A and B
A= $parentB= $search_parent
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | ▶ | while ($parent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | if ($parent->isa('Org::Element::Headline')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | my $res = $parent->get_property($name, 0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | return $res if defined $res; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | $parent = $parent->parent; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | ▶ | if ($search_docprop // 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$search_docprop // 1
MC/DC100%1/1
$search_docprop // 1
$search_docprop
Truth table100%2/2
A
A= $search_docprop
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | log_trace("Getting property from document's .properties"); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | return $self->document->properties->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | sub update_statistics_cookie { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_statistics_cookie: called CC=18 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | my $statc = $self->statistics_cookie; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | return unless $statc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | my $num_done = 0; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | my $num_total = 0; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # count using checks on first-level list's children, or from first-level | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # subheadlines | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | for my $chld (@{ $self->children // [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->children // []
MC/DC100%1/1
$self->children // []
$self->children
Truth table100%2/2
A
A= $self->children
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | if ($chld->isa("Org::Element::Headline")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | for my $el (@{ $self->children }) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | next unless $el->isa("Org::Element::Headline"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | ▶ | if ($el->is_todo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | $num_total++; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 3 | ▶ | $num_done++ if $el->is_done; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } elsif ($chld->isa("Org::Element::List")) { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | for my $el (@{ $self->children }) { | |||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | next unless $el->isa("Org::Element::List"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | for my $el2 (@{ $el->children }) { | |||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | next unless $el2->isa("Org::Element::ListItem"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | my $state = $el2->check_state; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | ▶ | if (defined $state) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | $num_total++; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | ▶ | $num_done++ if $state eq 'X'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | undef $self->{_str}; # we modify content | |||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | ▶ | if ($statc =~ /%/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | ▶ | $self->statistics_cookie( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | sprintf("%d%%", $num_total == 0 ? 0 : $num_done/$num_total * 100)); | ||||||||||||||||||||||||||||||||||||||||||
| 287 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | $self->statistics_cookie(sprintf("%d/%d", $num_done, $num_total)); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 293 | # ABSTRACT: Represent Org headline | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | __END__ | ||||||||||||||||||||||||||||||||||||||||||