FSMethods/Org.pm

filter: Statementstmt 35.4% 22 / 62 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 6 / 12 Podpod 25.0% 1 / 4 totaltotal 27.1% 29 / 107 CC 15 SCAR 33.9
CC
15
Cov
25%
before_cp
72.0
new
30.0
__ANON__
6.0
CRAP 29.6
« FSMethods.pm ↑ Summary
1 package Tree::FSMethods::Org;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Code::Includable::Tree::NodeMethods;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Org::Parser::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use parent qw(Tree::FSMethods);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 1 our $DATE = '2021-10-07'; # DATE
14 1 our $DIST = 'Tree-FSMethods'; # DIST
15 1 our $VERSION = '0.004'; # VERSION
16  
17 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
18 0 my ($class, %args) = (shift, @_);
19 0 ▶ $args{filename_method} //= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
20 0 my $node = shift;
21 0 ▶ return undef unless $node->can("title"); ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless $node->can("title") 0 0 0
22 0 my $name = $node->title;
23 0 $name =~ s/\[.*?\]//g;
24 0 $name =~ s/\s{2,}/ /g;
25 0 $name =~ s/^\s+//;
26 0 $name =~ s/\s$//;
27 0 $name;
28 0 ▶ };
Condition0%0/3
$args{"filename_method"} //= sub { my $node = shift(); return undef unless $node->can("title"); my $name = $node->title; $name =~ s/\[.*?\]//g; $name =~ s/\s{2,}/ /g; $name =~ s/^\s+//; $name =~ s/\s$//; $name; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"filename_method"} //= sub { my $node = shift(); return undef unless $node->can("title"); my $name = $node->title; $name =~ s/\[.*?\]//g; $name =~ s/\s{2,}/ /g; $name =~ s/^\s+//; $name =~ s/\s$//; $name; }
$args{"filename_method"} sub { my $node = shift(); return undef unless $node->can("title"); my $name = $node->title; $name =~ s/\[.*?\]//g; $name =~ s/\s{2,}/ /g; $name =~ s/^\s+//; $name =~ s/\s$//; $name; }
Truth table0%0/3
A //= B
A= $args{"filename_method"}B= sub { my $node = shift(); return undef unless $node->can("title"); my $name = $node->title; $name =~ s/\[.*?\]//g; $name =~ s/\s{2,}/ /g; $name =~ s/^\s+//; $name =~ s/\s$//; $name; }
ABresult
1X1
011
000
29 0 ▶ if (defined $args{org_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"org_file"}) 0 0 0
30 $args{tree} = Org::Parser::Tiny->new->parse_file(
31 0 delete $args{org_file});
32 }
33 0 ▶ if (defined $args{org_file1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"org_file1"}) 0 0 0
34 $args{tree1} = Org::Parser::Tiny->new->parse_file(
35 0 delete $args{org_file1});
36 }
37 0 ▶ if (defined $args{org_file2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"org_file2"}) 0 0 0
38 $args{tree2} = Org::Parser::Tiny->new->parse_file(
39 0 delete $args{org_file2});
40 }
41 0 $class->SUPER::new(%args);
42 }
43  
44 0 ▶sub before_cp {
Subroutine before_cp: not called CC=8 SCAR=42.8
Pod undocumented
45 0 my ($self, $nodes_to_copy, $target_node) = @_;
46  
47 # adjust level, e.g. if we move level1 headings under another level1 heading
48 # then the level1 headings to be copied (as well as their descendants) will
49 # need to be demoted by 1 level.
50  
51 #say "D1: ", scalar(@$nodes_to_copy);
52 0 ▶ my $target_level = $target_node->can("level") ? $target_node->level : 0;
Branch: 1 branch
BranchTrueFalseTotal
$target_node->can('level') ? : 0 0 0
53 0 my $levels_to_increase;
54  
55 0 for my $node_to_copy (@$nodes_to_copy) {
56 0 ▶ unless (defined $levels_to_increase) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $levels_to_increase) 0 0 0
57 0 ▶ my $node_level = $node_to_copy->can("level") ? $node_to_copy->level : 0;
Branch: 1 branch
BranchTrueFalseTotal
$node_to_copy->can('level') ? : 0 0 0
58 0 $levels_to_increase = $target_level+1 - $node_to_copy->level;
59 0 ▶ $levels_to_increase = 0 if $levels_to_increase < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $levels_to_increase < 0 0 0 0
60 }
61 0 ▶ next unless $levels_to_increase;
Branch: 1 branch
BranchTrueFalseTotal
unless $levels_to_increase 0 0 0
62 0 ▶ $node_to_copy->level( $node_to_copy->level + $levels_to_increase )
Branch: 1 branch
BranchTrueFalseTotal
if $node_to_copy->can("level") 0 0 0
63 if $node_to_copy->can("level");
64 Code::Includable::Tree::NodeMethods::walk(
65 0 ▶ $node_to_copy, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
66 0 my $node = shift;
67 0 ▶ $node->level( $node->level + $levels_to_increase )
Branch: 1 branch
BranchTrueFalseTotal
if $node->can("level") 0 0 0
68 if $node->can("level");
69 0 });
70 }
71 }
72  
73 0 ▶sub before_mv {
Subroutine before_mv: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $self = shift;
75 0 $self->before_cp(@_);
76 }
77  
78 0 ▶sub on_mkdir {
Subroutine on_mkdir: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my ($self, $node, $filename) = @_;
80 0 my $child_node = Org::Parser::Tiny::Node::Headline->new;
81 0 ▶ $child_node->level($node->can("level") ? $node->level+1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$node->can('level') ? : 0 0 0
82 0 $child_node->title($filename);
83 0 $child_node->parent($node);
84 0 $node->children([ @{ $node->children }, $child_node ]);
85 0 $child_node;
86 }
87  
88 1 1;
89 # ABSTRACT: Perform filesystem-like operations on Org document tree
90  
91 __END__
« FSMethods.pm ↑ Summary