Element/Setting.pm

filter: Statementstmt 100% 73 / 73 Branchbran 85.4% 41 / 48 Conditioncond 61.5% 8 / 13 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 7 / 7 Podpod 66.6% 2 / 3 totaltotal 88.0% 133 / 151 CC 33 SCAR 31.8
CC
33
Cov
91%
BUILD
30.4
as_string
5.0
BEGIN
1.0
CRAP 24.1
« Parser.pm ↑ Summary Element/Block.pm »
1 package Org::Element::Setting;
2  
3 10 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 extends 'Org::Element';
8 10 with 'Org::ElementRole';
9 10 with 'Org::ElementRole::Block';
10  
11 10 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
12 10 our $DATE = '2023-11-06'; # DATE
13 10 our $DIST = 'Org-Parser'; # DIST
14 10 our $VERSION = '0.561'; # VERSION
15  
16 10 our @known_settings = qw(
17 ARCHIVE
18 ASCII
19 ATTR_ASCII
20 ATTR_BEAMER
21 ATTR_HTML
22 ATTR_LATEX
23 ATTR_ODT
24 AUTHOR
25 BABEL
26 BEAMER
27 BEAMER_COLOR_THEME
28 BEAMER_FONT_THEME
29 BEAMER_INNER_THEME
30 BEAMER_OUTER_THEME
31 BEAMER_THEME
32 BEGIN
33 BEGIN_ASCII
34 BEGIN_BEAMER
35 BEGIN_CENTER
36 BEGIN_COMMENT
37 BEGIN_EXAMPLE
38 BEGIN_HTML
39 BEGIN_LATEX
40 BEGIN_QUOTE
41 BEGIN_SRC
42 BEGIN_SRC
43 BEGIN_VERSE
44 BIND
45 CALL
46 CAPTION
47 CATEGORY
48 COLUMNS
49 CONSTANTS
50 DATE
51 DESCRIPTION
52 DRAWERS
53 EMAIL
54 EXPORT_EXCLUDE_TAGS
55 EXPORT_INCLUDE_TAGS
56 FILETAGS
57 HEADER
58 HEADERS
59 HTML
60 HTML_HEAD
61 HTML_HEAD_EXTRA
62 HTML_INCLUDE_STYLE
63 INCLUDE
64 INDEX
65 INFOJS_OPT
66 KEYWORDS
67 LABEL
68 LANGUAGE
69 LAST_MOBILE_CHANGE
70 LATEX
71 LATEX_CLASS
72 LATEX_CLASS_OPTIONS
73 LATEX_HEADER
74 LATEX_HEADER_EXTRA
75 LINK
76 LINK_HOME
77 LINK_UP
78 MACRO
79 NAME
80 ODT_STYLES_FILE
81 OPTIONS
82 ORGLST
83 ORGTBL
84 PLOT
85 POSTID
86 PRIORITIES
87 PROPERTY
88 RESULTS
89 SEQ_TODO
90 SETUPFILE
91 SRCNAME
92 STARTUP
93 STYLE
94 TAGS
95 TBLFM
96 TEXT
97 TITLE
98 TOC
99 TODO
100 TYP_TODO
101 XSLT
102 );
103  
104 10 has name => (is => 'rw');
105 10 has raw_arg => (is => 'ro');
106 10 has args => (is => 'rw');
107 10 has indent => (is => 'rw');
108  
109 # static method
110 sub indentable_settings {
111 8 ▶ state $data = [qw/TBLFM/];
Subroutine indentable_settings: called CC=1 SCAR=0.0
Pod documented
112 8 $data;
113 }
114  
115 sub BUILD {
116 54 ▶ require Org::Document;
Subroutine BUILD: called CC=30 SCAR=34.2
Pod undocumented
117 54 my ($self, $build_args) = @_;
118 54 my $doc = $self->document;
119 54 ▶ my $pass = $build_args->{pass} // 1;
Condition50%1/2
$build_args->{"pass"} // 1
l!l
540
MC/DC0%0/1
$build_args->{"pass"} // 1
$build_args->{"pass"}
Truth table50%1/2
A
A= $build_args->{"pass"}
Aresult
11
00
120  
121 54 my $name = uc $self->name;
122 54 $self->name($name);
123  
124 54 my $args = $self->args;
125 54 ▶ if ($name eq 'DRAWERS') {
Branch: 5 branches
BranchTrueFalseTotal
if ($name eq 'DRAWERS') { } 2 52 54
elsif ($name eq 'FILETAGS') { } 5 47 52
elsif ($name eq 'PRIORITIES') { } 8 39 47
elsif ($name eq 'PROPERTY') { } 4 35 39
elsif ($name =~ /^(SEQ_TODO|TODO|TYP_TODO)$/l) { } 26 9 35
126 2 ▶ if ($pass == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 1) 1 1 2
127 1 for my $arg (@$args) {
128 2 push @{ $doc->drawer_names }, $arg
129 2 ▶ unless grep { $_ eq $arg } @{ $doc->drawer_names };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $arg;} @{$doc->drawer_names;} 2 0 2
130 }
131 }
132 } elsif ($name eq 'FILETAGS') {
133 5 ▶ if ($pass == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 1) 3 2 5
134 10 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 3 ▶ $args->[0] =~ /^$Org::Document::tags_re$/ or
Branch: 1 branch
BranchTrueFalseTotal
$args->[0] =~ /^$Org::Document::tags_re$/l or $self->die("Invalid argument for FILETAGS: $args->[0]") 1 2 3
136 $self->die("Invalid argument for FILETAGS: $args->[0]");
137 2 for my $tag (split /:/, $args->[0]) {
138 7 ▶ next unless length $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless length $tag 2 5 7
139 5 push @{ $doc->tags }, $tag
140 5 ▶ unless grep { $_ eq $tag } @{ $doc->tags };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $tag;} @{$doc->tags;} 5 0 5
141 }
142 }
143 } elsif ($name eq 'PRIORITIES') {
144 8 ▶ if ($pass == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 1) 4 4 8
145 4 for (@$args) {
146 17 push @{ $doc->priorities }, $_;
147 }
148 }
149 } elsif ($name eq 'PROPERTY') {
150 4 ▶ if ($pass == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 1) 2 2 4
151 2 ▶ @$args >= 2 or $self->die("Not enough argument for PROPERTY, minimum 2");
Branch: 1 branch
BranchTrueFalseTotal
@$args >= 2 or $self->die("Not enough argument for PROPERTY, minimum 2") 0 2 2
152 2 my $name = shift @$args;
153 2 ▶ $doc->properties->{$name} = @$args > 1 ? [@$args] : $args->[0];
Branch: 1 branch
BranchTrueFalseTotal
@$args > 1 ? : 0 2 2
154 }
155 } elsif ($name =~ /^(SEQ_TODO|TODO|TYP_TODO)$/) {
156 26 ▶ if ($pass == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 1) 13 13 26
157 13 my $done;
158 13 ▶ for (my $i=0; $i<@$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 50 13 63
159 50 my $arg = $args->[$i];
160 50 ▶ if ($arg eq '|') { $done++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq "|") 12 38 50
161 38 ▶ $done++ if !$done && @$args > 1 && $i == @$args-1;
Branch: 1 branch
BranchTrueFalseTotal
if not $done and @$args > 1 and $i == @$args - 1 1 37 38
Condition83%5/6
not $done and @$args > 1 and $i == @$args - 1
!ll&&!rl&&r
15221
not $done and @$args > 1
!ll&&!rl&&r
15023
MC/DC66%2/3
not $done and @$args > 1 and $i == @$args - 1
not $done @$args > 1 $i == @$args - 1
Truth table75%3/4
not(A) and B and C
A= not $doneB= @$args > 1C= $i == @$args - 1
ABCresult
0XX0
10X0
1100
1111
162 38 ▶ my $ary = $done ? $doc->done_states : $doc->todo_states;
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 16 22 38
163 38 ▶ push @$ary, $arg unless grep { $_ eq $arg } @$ary;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $arg;} @$ary 38 0 38
164 }
165 }
166 } else {
167 9 ▶ unless ($self->document->ignore_unknown_settings) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->document->ignore_unknown_settings) 9 0 9
168 9 ▶ $self->die("Unknown setting $name") unless grep { $_ eq $name } @known_settings;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $name;} @Org::Element::Setting::known_settings 1 8 9
169 }
170 }
171 }
172  
173 sub as_string {
174 2 ▶ my ($self) = @_;
Subroutine as_string: called CC=4 SCAR=16.1
Pod documented
175 join("",
176 $self->indent // "",
177 "#+".uc($self->name), ":",
178 2 ▶ $self->args && @{$self->args} ?
Branch: 1 branch
BranchTrueFalseTotal
$self->args && @{$self->args;} ? : 2 0 2
Condition40%2/5
$self->indent // ""
l!l
20
$self->args and @{$self->args;}
!ll&&!rl&&r
002
MC/DC0%0/1
$self->indent // ""
$self->indent
MC/DC0%0/2
$self->args and @{$self->args;}
$self->args @{$self->args;}
Truth table50%1/2
A
A= $self->indent
Aresult
11
00
Truth table33%1/3
A and B
A= $self->argsB= @{$self->args;}
ABresult
0X0
100
111
179 " ".Org::Document::__format_args($self->args) : "",
180 "\n"
181 );
182 }
183  
184 10 1;
185 # ABSTRACT: Represent Org in-buffer settings
186  
187 __END__
188  
189 =pod
190  
191 =encoding UTF-8
192  
193 =head1 NAME
194  
195 Org::Element::Setting - Represent Org in-buffer settings
196  
197 =head1 VERSION
198  
199 This document describes version 0.561 of Org::Element::Setting (from Perl distribution Org-Parser), released on 2023-11-06.
200  
201 =head1 DESCRIPTION
202  
203 Derived from L<Org::Element>.
204  
205 =for Pod::Coverage as_string BUILD
206  
207 =head1 ATTRIBUTES
208  
209 =head2 name => STR
210  
211 Setting name.
212  
213 =head2 raw_arg => ARRAY
214  
215 String, read-only (can only be set during instantiation). Setting's raw
216 arguments.
217  
218 =head2 args => ARRAY
219  
220 Setting's arguments.
221  
222 =head2 indent => STR
223  
224 Indentation (whitespaces before C<#+>), or empty string if none.
225  
226 =head1 METHODS
227  
228 =head2 Org::Element::Setting->indentable_settings -> ARRAY
229  
230 Return an arrayref containing the setting names that can be indented. In Org,
231 some settings can be indented and some can't. Setting names are all in
232 uppercase.
233  
234 =head1 HOMEPAGE
235  
236 Please visit the project's homepage at L<https://metacpan.org/release/Org-Parser>.
237  
238 =head1 SOURCE
239  
240 Source repository is at L<https://github.com/perlancar/perl-Org-Parser>.
241  
242 =head1 AUTHOR
243  
244 perlancar <perlancar@cpan.org>
245  
246 =head1 CONTRIBUTING
247  
248  
249 To contribute, you can send patches by email/via RT, or send pull requests on
250 GitHub.
251  
252 Most of the time, you don't need to build the distribution yourself. You can
253 simply modify the code, then test via:
254  
255 % prove -l
256  
257 If you want to build the distribution (e.g. to try to install it locally on your
258 system), you can install L<Dist::Zilla>,
259 L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
260 L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
261 Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
262 that are considered a bug and can be reported to me.
263  
264 =head1 COPYRIGHT AND LICENSE
265  
266 This software is copyright (c) 2023, 2022, 2021, 2020, 2019, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar <perlancar@cpan.org>.
267  
268 This is free software; you can redistribute it and/or modify it under
269 the same terms as the Perl 5 programming language system itself.
270  
271 =head1 BUGS
272  
273 Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Org-Parser>
274  
275 When submitting a bug or request, please include a test-file or a
276 patch to an existing test-file that illustrates the bug or desired
277 feature.
278  
279 =cut
« Parser.pm ↑ Summary Element/Block.pm »