File Coverage

blib/lib/Org/Element/Text.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition 6 12 50.0
subroutine 5 5 100.0
pod 2 2 100.0
total 27 33 81.8


line stmt bran cond sub pod time code
1             package Org::Element::Text;
2              
3 24     24   1037 use 5.010;
  24         86  
4 24     24   125 use locale;
  24         45  
  24         951  
5 24     24   957 use Moo;
  24         44  
  24         162  
6             extends 'Org::Element';
7             with 'Org::ElementRole';
8             with 'Org::ElementRole::Inline';
9              
10             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11             our $DATE = '2023-07-12'; # DATE
12             our $DIST = 'Org-Parser'; # DIST
13             our $VERSION = '0.559'; # VERSION
14              
15             has text => (is => 'rw');
16             has style => (is => 'rw');
17              
18             our %mu2style = (''=>'', '*'=>'B', '_'=>'U', '/'=>'I',
19             '+'=>'S', '='=>'C', '~'=>'V');
20             our %style2mu = reverse(%mu2style);
21              
22             sub as_string {
23 194     194 1 42483 my ($self) = @_;
24 194   50     771 my $muchar = $style2mu{$self->style // ''} // '';
      50        
25              
26 194   50     713 join("",
27             $muchar,
28             $self->text // '', $self->children_as_string,
29             $muchar);
30             }
31              
32             sub as_text {
33 1     1 1 2 my $self = shift;
34 1   50     6 my $muchar = $style2mu{$self->style // ''} // '';
      50        
35              
36 1   50     5 join("",
37             $muchar,
38             $self->text // '', $self->children_as_text,
39             $muchar);
40             }
41              
42             1;
43             # ABSTRACT: Represent text
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             Org::Element::Text - Represent text
54              
55             =head1 VERSION
56              
57             This document describes version 0.559 of Org::Element::Text (from Perl distribution Org-Parser), released on 2023-07-12.
58              
59             =head1 DESCRIPTION
60              
61             Derived from L<Org::Element>.
62              
63             Org::Element::Text is an object that represents a piece of text. It has C<text>
64             and C<style> attributes. Simple text like C<Jakarta> or C<*Jakarta!*> will be
65             represented, respectively, as C<(text=Jakarta, style='')> and C<text=Jakarta!,
66             style=B> (for bold).
67              
68             This object can also hold other inline (non-block) elements, e.g. links, radio
69             targets, timestamps, time ranges. They are all put in the C<children> attribute.
70              
71             =for Pod::Coverage as_string
72              
73             =head1 ATTRIBUTES
74              
75             =head2 text => str
76              
77             Plain text for this object I<only>. Note that if you want to get a plain text
78             representation for the whole text (including child elements), you'd want the
79             C<as_text> method.
80              
81             =head2 style => str
82              
83             ''=normal, I=italic, B=bold, U=underline, S=strikethrough, V=verbatim,
84             C=code
85              
86             =head1 METHODS
87              
88             =head2 as_text => str
89              
90             From L<Org::ElementRole::Inline>.
91              
92             =head2 as_string => str
93              
94             From L<Org::Element>.
95              
96             =head1 HOMEPAGE
97              
98             Please visit the project's homepage at L<https://metacpan.org/release/Org-Parser>.
99              
100             =head1 SOURCE
101              
102             Source repository is at L<https://github.com/perlancar/perl-Org-Parser>.
103              
104             =head1 AUTHOR
105              
106             perlancar <perlancar@cpan.org>
107              
108             =head1 CONTRIBUTING
109              
110              
111             To contribute, you can send patches by email/via RT, or send pull requests on
112             GitHub.
113              
114             Most of the time, you don't need to build the distribution yourself. You can
115             simply modify the code, then test via:
116              
117             % prove -l
118              
119             If you want to build the distribution (e.g. to try to install it locally on your
120             system), you can install L<Dist::Zilla>,
121             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
122             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
123             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
124             that are considered a bug and can be reported to me.
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2023, 2022, 2021, 2020, 2019, 2017, 2016, 2015, 2014, 2013, 2012, 2011 by perlancar <perlancar@cpan.org>.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =head1 BUGS
134              
135             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Org-Parser>
136              
137             When submitting a bug or request, please include a test-file or a
138             patch to an existing test-file that illustrates the bug or desired
139             feature.
140              
141             =cut