]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - lib/Org/Element/Block.pm
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / lib / Org / Element / Block.pm
1 package Org::Element::Block;
2
3 use 5.010;
4 use locale;
5 use Moo;
6 extends 'Org::Element';
7
8 our $VERSION = '0.23'; # VERSION
9
10 has name => (is => 'rw');
11 has args => (is => 'rw');
12 has raw_content => (is => 'rw');
13 has begin_indent => (is => 'rw');
14 has end_indent => (is => 'rw');
15
16 my @known_blocks = qw(
17                          ASCII CENTER COMMENT EXAMPLE HTML
18                          LATEX QUOTE SRC VERSE
19                  );
20
21 sub BUILD {
22     my ($self, $args) = @_;
23     $self->name(uc $self->name);
24     $self->name ~~ @known_blocks or die "Unknown block name: ".$self->name;
25 }
26
27 sub element_as_string {
28     my ($self) = @_;
29     return $self->_str if defined $self->_str;
30     join("",
31          $self->begin_indent // "",
32          "#+BEGIN_".uc($self->name),
33          $self->args && @{$self->args} ?
34              " ".Org::Document::__format_args($self->args) : "",
35          "\n",
36          $self->raw_content,
37          $self->end_indent // "",
38          "#+END_".uc($self->name)."\n");
39 }
40
41 1;
42 # ABSTRACT: Represent Org block
43
44
45 =pod
46
47 =head1 NAME
48
49 Org::Element::Block - Represent Org block
50
51 =head1 VERSION
52
53 version 0.23
54
55 =head1 DESCRIPTION
56
57 Derived from L<Org::Element>.
58
59 =head1 ATTRIBUTES
60
61 =head2 name => STR
62
63 Block name. For example, #+begin_src ... #+end_src is an 'SRC' block.
64
65 =head2 args => ARRAY
66
67 =head2 raw_content => STR
68
69 =head2 begin_indent => STR
70
71 Indentation on begin line (before C<#+BEGIN>), or empty string if none.
72
73 =head2 end_indent => STR
74
75 Indentation on end line (before C<#+END>), or empty string if none.
76
77 =head1 METHODS
78
79 =for Pod::Coverage element_as_string BUILD
80
81 =head1 AUTHOR
82
83 Steven Haryanto <stevenharyanto@gmail.com>
84
85 =head1 COPYRIGHT AND LICENSE
86
87 This software is copyright (c) 2012 by Steven Haryanto.
88
89 This is free software; you can redistribute it and/or modify it under
90 the same terms as the Perl 5 programming language system itself.
91
92 =cut
93
94
95 __END__
96