]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - lib/Org/Element/Drawer.pm
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / lib / Org / Element / Drawer.pm
1 package Org::Element::Drawer;
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 properties => (is => 'rw');
12
13 sub BUILD {
14     my ($self, $args) = @_;
15     my $doc = $self->document;
16     my $pass = $args->{pass} // 1;
17
18     if ($pass == 2) {
19         die "Unknown drawer name: ".$self->name
20             unless $self->name ~~ @{$doc->drawer_names};
21     }
22 }
23
24 sub _parse_properties {
25     my ($self, $raw_content) = @_;
26     $self->properties({}) unless $self->properties;
27     while ($raw_content =~ /^[ \t]*:(\w+):[ \t]+
28                             ($Org::Document::args_re)[ \t]*(?:\R|\z)/mxg) {
29         my $args = Org::Document::__parse_args($2);
30         $self->properties->{$1} = @$args == 1 ? $args->[0] : $args;
31     }
32 }
33
34 sub as_string {
35     my ($self) = @_;
36     join("",
37          ":", $self->name, ":\n",
38          $self->children_as_string,
39          ":END:\n");
40 }
41
42 1;
43 # ABSTRACT: Represent Org drawer
44
45
46 =pod
47
48 =head1 NAME
49
50 Org::Element::Drawer - Represent Org drawer
51
52 =head1 VERSION
53
54 version 0.23
55
56 =head1 DESCRIPTION
57
58 Derived from L<Org::Element>.
59
60 =head1 ATTRIBUTES
61
62 =head2 name => STR
63
64 Drawer name.
65
66 =head2 properties => HASH
67
68 Collected properties in the drawer.
69
70 =head1 METHODS
71
72 =for Pod::Coverage BUILD as_string
73
74 =head1 AUTHOR
75
76 Steven Haryanto <stevenharyanto@gmail.com>
77
78 =head1 COPYRIGHT AND LICENSE
79
80 This software is copyright (c) 2012 by Steven Haryanto.
81
82 This is free software; you can redistribute it and/or modify it under
83 the same terms as the Perl 5 programming language system itself.
84
85 =cut
86
87
88 __END__
89