| 1 | package App::OrgUtils; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Log::ger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Slurper::Dash 'read_text'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Org::Parser::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Sort::Sub; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 13 | 4 | our $DATE = '2026-07-22'; # DATE | |||||||||||||||||||||||||||
| 14 | 4 | our $DIST = 'App-OrgUtils'; # DIST | |||||||||||||||||||||||||||
| 15 | 4 | our $VERSION = '0.489'; # VERSION | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | our %SPEC; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | our %common_args1 = ( | |||||||||||||||||||||||||||
| 20 | files => { | ||||||||||||||||||||||||||||
| 21 | schema => ['array*' => of => 'filename*', min_len=>1], | ||||||||||||||||||||||||||||
| 22 | req => 1, | ||||||||||||||||||||||||||||
| 23 | pos => 0, | ||||||||||||||||||||||||||||
| 24 | greedy => 1, | ||||||||||||||||||||||||||||
| 25 | 'x.name.is_plural' => 1, | ||||||||||||||||||||||||||||
| 26 | }, | ||||||||||||||||||||||||||||
| 27 | time_zone => { | ||||||||||||||||||||||||||||
| 28 | schema => ['date::tz_name'], | ||||||||||||||||||||||||||||
| 29 | summary => 'Will be passed to parser\'s options', | ||||||||||||||||||||||||||||
| 30 | description => <<'MARKDOWN', | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | If not set, TZ environment variable will be picked as default. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | MARKDOWN | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | our %arg0_file = ( | |||||||||||||||||||||||||||
| 39 | file => { | ||||||||||||||||||||||||||||
| 40 | summary => 'Path to an Org file', | ||||||||||||||||||||||||||||
| 41 | description => <<'MARKDOWN', | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | "-" means standard input. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | MARKDOWN | ||||||||||||||||||||||||||||
| 46 | schema => 'filename*', | ||||||||||||||||||||||||||||
| 47 | default => '-', | ||||||||||||||||||||||||||||
| 48 | pos => 0, | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | our $_complete_state = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=45.0
| |||||||||||||||||||||||||||||
| 53 | 4 | ▶ | use experimental 'smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 0 | require Complete::Util; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # only return answer under CLI | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return unless my $cmdline = $args{cmdline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | my $r = $args{r}; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # force read config | ||||||||||||||||||||||||||||
| 63 | 0 | $r->{read_config} = 1; | |||||||||||||||||||||||||||
| 64 | 0 | my $res = $cmdline->parse_argv($r); | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | return unless $res->[0] == 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | my $args = $res->[2]; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # read org | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return unless $args->{files} && @{ $args->{files} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"files"} and @{$args->{"files"};}
MC/DC0%0/2
$args->{"files"} and @{$args->{"files"};}
$args->{"files"}
@{$args->{"files"};}
Truth table0%0/3
A and B
A= $args->{"files"}B= @{$args->{"files"};}
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $tz = $args->{time_zone} // $ENV{TZ} // "UTC"; | ||||||||||||||||||||||||||
|
Condition0%0/5
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"} // $ENV{"TZ"}
MC/DC0%0/2
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"}
$ENV{"TZ"}
Truth table0%0/3
A // B
A= $args->{"time_zone"}B= $ENV{"TZ"}
| |||||||||||||||||||||||||||||
| 71 | my %docs = App::OrgUtils::_load_org_files( | ||||||||||||||||||||||||||||
| 72 | 0 | [grep {-f} @{ $args->{files} }], {time_zone=>$tz}); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # get todo states | ||||||||||||||||||||||||||||
| 75 | 0 | my @states; | |||||||||||||||||||||||||||
| 76 | 0 | for my $doc (values %docs) { | |||||||||||||||||||||||||||
| 77 | 0 | for my $state (@{ $doc->todo_states }, @{ $doc->done_states }) { | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | push @states, $state unless grep { $_ eq $state } @states; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | Complete::Util::complete_array_elem(array=>\@states, word=>$args{word}); | |||||||||||||||||||||||||||
| 82 | 4 | }; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | our $_complete_priority = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=44.9
| |||||||||||||||||||||||||||||
| 85 | 4 | ▶ | use experimental 'smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 0 | require Complete::Util; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # only return answer under CLI | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return unless my $cmdline = $args{cmdline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | my $r = $args{r}; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # force read config | ||||||||||||||||||||||||||||
| 95 | 0 | $r->{read_config} = 1; | |||||||||||||||||||||||||||
| 96 | 0 | my $res = $cmdline->parse_argv($r); | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | return unless $res->[0] == 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my $args = $res->[2]; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # read org | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return unless $args->{files} && @{ $args->{files} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"files"} and @{$args->{"files"};}
MC/DC0%0/2
$args->{"files"} and @{$args->{"files"};}
$args->{"files"}
@{$args->{"files"};}
Truth table0%0/3
A and B
A= $args->{"files"}B= @{$args->{"files"};}
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $tz = $args->{time_zone} // $ENV{TZ} // "UTC"; | ||||||||||||||||||||||||||
|
Condition0%0/5
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"} // $ENV{"TZ"}
MC/DC0%0/2
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"}
$ENV{"TZ"}
Truth table0%0/3
A // B
A= $args->{"time_zone"}B= $ENV{"TZ"}
| |||||||||||||||||||||||||||||
| 103 | my %docs = App::OrgUtils::_load_org_files( | ||||||||||||||||||||||||||||
| 104 | 0 | [grep {-f} @{ $args->{files} }], {time_zone=>$tz}); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # get priorities | ||||||||||||||||||||||||||||
| 107 | 0 | my @prios; | |||||||||||||||||||||||||||
| 108 | 0 | for my $doc (values %docs) { | |||||||||||||||||||||||||||
| 109 | 0 | for my $prio (@{ $doc->priorities }) { | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | push @prios, $prio unless grep { $_ eq $prio } @prios; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | Complete::Util::complete_array_elem(array=>\@prios, word=>$args{word}); | |||||||||||||||||||||||||||
| 114 | 4 | }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | our $_complete_tags = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=40.9
| |||||||||||||||||||||||||||||
| 117 | 4 | ▶ | use experimental 'smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | 0 | require Complete::Util; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # only return answer under CLI | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return unless my $cmdline = $args{cmdline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | my $r = $args{r}; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # force read config | ||||||||||||||||||||||||||||
| 127 | 0 | $r->{read_config} = 1; | |||||||||||||||||||||||||||
| 128 | 0 | my $res = $cmdline->parse_argv($r); | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | return unless $res->[0] == 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | my $args = $res->[2]; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # read org | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return unless $args->{files} && @{ $args->{files} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args->{"files"} and @{$args->{"files"};}
MC/DC0%0/2
$args->{"files"} and @{$args->{"files"};}
$args->{"files"}
@{$args->{"files"};}
Truth table0%0/3
A and B
A= $args->{"files"}B= @{$args->{"files"};}
| |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $tz = $args->{time_zone} // $ENV{TZ} // "UTC"; | ||||||||||||||||||||||||||
|
Condition0%0/5
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"} // $ENV{"TZ"}
MC/DC0%0/2
($args->{"time_zone"} // $ENV{"TZ"}) // "UTC"
$args->{"time_zone"}
$ENV{"TZ"}
Truth table0%0/3
A // B
A= $args->{"time_zone"}B= $ENV{"TZ"}
| |||||||||||||||||||||||||||||
| 135 | my %docs = App::OrgUtils::_load_org_files( | ||||||||||||||||||||||||||||
| 136 | 0 | [grep {-f} @{ $args->{files} }], {time_zone=>$tz}); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # collect tags | ||||||||||||||||||||||||||||
| 139 | 0 | my @tags; | |||||||||||||||||||||||||||
| 140 | 0 | for my $doc (values %docs) { | |||||||||||||||||||||||||||
| 141 | $doc->walk( | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 143 | 0 | my $el = shift; | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | return unless $el->isa('Org::Element::Headline'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | for my $tag ($el->get_tags) { | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | push @tags, $tag unless grep { $_ eq $tag } @tags; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | ); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 0 | Complete::Util::complete_array_elem(array=>\@tags, word=>$args{word}); | |||||||||||||||||||||||||||
| 152 | 4 | }; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub _load_org_files { | ||||||||||||||||||||||||||
|
Subroutine
_load_org_files: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 155 | 0 | require Cwd; | |||||||||||||||||||||||||||
| 156 | 0 | require Digest::MD5; | |||||||||||||||||||||||||||
| 157 | 0 | require Org::Parser; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | my ($files, $opts0) = @_; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | $files or die "Please specify files"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | my $orgp = Org::Parser->new( | |||||||||||||||||||||||||||
| 163 | ignore_unknown_settings => 1, | ||||||||||||||||||||||||||||
| 164 | ignore_unknown_drawers => 1, | ||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||
| 166 | 0 | my %docs; | |||||||||||||||||||||||||||
| 167 | 0 | for my $file (@$files) { | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $opts = { %{$opts0 // {}} }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts0 // {}
MC/DC0%0/1
$opts0 // {}
$opts0
Truth table0%0/2
A
A= $opts0
| |||||||||||||||||||||||||||||
| 169 | # by default turn on cache, unless user specifically has | ||||||||||||||||||||||||||||
| 170 | # PERL_ORG_PARSER_CACHE set to 0. | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $opts->{cache} = 1 if $ENV{PERL_ORG_PARSER_CACHE} // 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{"PERL_ORG_PARSER_CACHE"} // 1
MC/DC0%0/1
$ENV{"PERL_ORG_PARSER_CACHE"} // 1
$ENV{"PERL_ORG_PARSER_CACHE"}
Truth table0%0/2
A
A= $ENV{"PERL_ORG_PARSER_CACHE"}
| |||||||||||||||||||||||||||||
| 172 | 0 | $docs{$file} = $orgp->parse_file($file, $opts); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | %docs; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub _parse_org_with_tiny { | ||||||||||||||||||||||||||
|
Subroutine
_parse_org_with_tiny: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 179 | 0 | require Org::Parser::Tiny; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my $file = shift; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | my $doc = Org::Parser::Tiny->new->parse(read_text($file)); | |||||||||||||||||||||||||||
| 184 | 0 | $doc; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub _sort { | ||||||||||||||||||||||||||
|
Subroutine
_sort: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 188 | 0 | my ($node, $level, $sorter, $sorter_meta) = @_; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my @children = @{ $node->children // [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$node->children // []
MC/DC0%0/1
$node->children // []
$node->children
Truth table0%0/2
A
A= $node->children
| |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return unless @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # recurse depth-first to sort the children's children | ||||||||||||||||||||||||||||
| 194 | 0 | for my $child (@children) { | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | next unless $child->can("children"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | my $grandchildren = $child->children; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | next unless $grandchildren && @$grandchildren; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$grandchildren and @$grandchildren
MC/DC0%0/2
$grandchildren and @$grandchildren
$grandchildren
@$grandchildren
Truth table0%0/3
A and B
A= $grandchildrenB= @$grandchildren
| |||||||||||||||||||||||||||||
| 198 | 0 | _sort($child, $level, $sorter, $sorter_meta); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $has_level_sub = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $_->isa("Org::Parser::Tiny::Node::Headline") && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | $_->level == $level | ||||||||||||||||||||||||||||
| 204 | 0 | }; | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | return unless grep { $has_level_sub->($_) } @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $child_has_level_sub = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $children[$_]->isa("Org::Parser::Tiny::Node::Headline") && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | $children[$_]->level == $level | ||||||||||||||||||||||||||||
| 210 | 0 | }; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | require Sort::SubList; | |||||||||||||||||||||||||||
| 213 | my @sorted_children = | ||||||||||||||||||||||||||||
| 214 | 0 | map { $children[$_] } | |||||||||||||||||||||||||||
| 215 | Sort::SubList::sort_sublist( | ||||||||||||||||||||||||||||
| 216 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($sorter_meta->{compares_record}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | my $rec0 = [$children[$_[0]]->as_string, $_[0]]; | |||||||||||||||||||||||||||
| 219 | 0 | my $rec1 = [$children[$_[1]]->as_string, $_[1]]; | |||||||||||||||||||||||||||
| 220 | 0 | $sorter->($rec0, $rec1); | |||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||
| 222 | 0 | $sorter->($children[$_[0]]->as_string, $children[$_[1]]->as_string); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | }, | ||||||||||||||||||||||||||||
| 225 | 0 | $child_has_level_sub, | |||||||||||||||||||||||||||
| 226 | 0..$#children); | ||||||||||||||||||||||||||||
| 227 | 0 | $node->children(\@sorted_children); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 4 | $Sort::Sub::argsopt_sortsub{sort_sub}{cmdline_aliases} = {S=>{}}; | |||||||||||||||||||||||||||
| 231 | 4 | $Sort::Sub::argsopt_sortsub{sort_args}{cmdline_aliases} = {A=>{}}; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | $SPEC{sort_org_headlines} = { | ||||||||||||||||||||||||||||
| 234 | 4 | v => 1.1, | |||||||||||||||||||||||||||
| 235 | summary => '', | ||||||||||||||||||||||||||||
| 236 | args => { | ||||||||||||||||||||||||||||
| 237 | %arg0_file, | ||||||||||||||||||||||||||||
| 238 | level => { | ||||||||||||||||||||||||||||
| 239 | schema => ['posint*'], | ||||||||||||||||||||||||||||
| 240 | default => 1, | ||||||||||||||||||||||||||||
| 241 | }, | ||||||||||||||||||||||||||||
| 242 | %Sort::Sub::argsopt_sortsub, | ||||||||||||||||||||||||||||
| 243 | }, | ||||||||||||||||||||||||||||
| 244 | result_naked => 1, | ||||||||||||||||||||||||||||
| 245 | }; | ||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub sort_org_headlines { | ||||||||||||||||||||||||||
|
Subroutine
sort_org_headlines: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $sortsub_routine = $args{sort_sub} // 'asciibetically'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"sort_sub"} // "asciibetically"
MC/DC0%0/1
$args{"sort_sub"} // "asciibetically"
$args{"sort_sub"}
Truth table0%0/2
A
A= $args{"sort_sub"}
| |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my $sortsub_args = $args{sort_args} // {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"sort_args"} // {}
MC/DC0%0/1
$args{"sort_args"} // {}
$args{"sort_args"}
Truth table0%0/2
A
A= $args{"sort_args"}
| |||||||||||||||||||||||||||||
| 251 | 0 | my ($sorter, $sorter_meta) = | |||||||||||||||||||||||||||
| 252 | Sort::Sub::get_sorter($sortsub_routine, $sortsub_args, 'with meta'); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $level = $args{level} // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"level"} // 1
MC/DC0%0/1
$args{"level"} // 1
$args{"level"}
Truth table0%0/2
A
A= $args{"level"}
| |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | my $doc = _parse_org_with_tiny($args{file}); | |||||||||||||||||||||||||||
| 257 | 0 | _sort($doc, $level, $sorter, $sorter_meta); | |||||||||||||||||||||||||||
| 258 | 0 | $doc->as_string; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | $SPEC{reverse_org_headlines} = { | ||||||||||||||||||||||||||||
| 262 | 4 | v => 1.1, | |||||||||||||||||||||||||||
| 263 | summary => 'Reverse Org headlines', | ||||||||||||||||||||||||||||
| 264 | args => { | ||||||||||||||||||||||||||||
| 265 | %arg0_file, | ||||||||||||||||||||||||||||
| 266 | level => { | ||||||||||||||||||||||||||||
| 267 | schema => ['posint*'], | ||||||||||||||||||||||||||||
| 268 | default => 1, | ||||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||
| 270 | }, | ||||||||||||||||||||||||||||
| 271 | result_naked => 1, | ||||||||||||||||||||||||||||
| 272 | }; | ||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub reverse_org_headlines { | ||||||||||||||||||||||||||
|
Subroutine
reverse_org_headlines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 274 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 275 | 0 | sort_org_headlines(%args, sort_sub=>'record_by_reverse_order'); | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 4 | 1; | |||||||||||||||||||||||||||
| 279 | # ABSTRACT: Some utilities for Org documents | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | __END__ | ||||||||||||||||||||||||||||