8 use String::Escape qw(elide printable);
10 our $VERSION = '0.23'; # VERSION
15 $dump .= "A " if $ts->is_active;
16 my $dt = $ts->datetime;
17 my $tz = $dt->time_zone;
19 ($tz->is_floating ? "F" : $tz->short_name_for_datetime($dt));
24 my ($el, $indent_level) = @_;
25 __PACKAGE__->new->_dump($el, $indent_level);
34 my ($self, $el, $indent_level) = @_;
38 my $line = " " x $indent_level;
40 $type =~ s/^Org::(?:Element::)?//;
42 # per-element important info
43 if ($type eq 'Headline') {
44 $line .= " l=".$el->level;
45 $line .= " tags ".join(",", @{$el->tags}) if $el->tags;
46 $line .= " todo=".$el->todo_state if $el->todo_state;
47 } elsif ($type eq 'Footnote') {
48 $line .= " name=".($el->name // "");
49 } elsif ($type eq 'Block') {
50 $line .= " name=".($el->name // "");
51 } elsif ($type eq 'List') {
52 $line .= " ".$el->type;
53 $line .= "(".$el->bullet_style.")";
54 $line .= " indent=".length($el->indent);
55 } elsif ($type eq 'ListItem') {
56 $line .= " ".$el->bullet;
57 $line .= " [".$el->check_state."]" if $el->check_state;
58 } elsif ($type eq 'Text') {
59 #$line .= " mu_start" if $el->{_mu_start}; #TMP
60 #$line .= " mu_end" if $el->{_mu_end}; #TMP
61 $line .= " ".$el->style if $el->style;
62 } elsif ($type eq 'Timestamp') {
63 $line .= " ".$self->_dump_ts($el);
64 } elsif ($type eq 'TimeRange') {
65 } elsif ($type eq 'Drawer') {
66 $line .= " ".$el->name;
67 $line .= " "._format_properties($el->properties)
68 if $el->name eq 'PROPERTIES' && $el->properties;
70 unless ($el->children) {
72 printable(elide(($el->_str // $el->as_string), 50))."\"";
74 push @res, $line, "\n";
76 if ($type eq 'Headline') {
77 push @res, " " x ($indent_level+1), "(title)\n";
78 push @res, $self->_dump($el->title, $indent_level+1);
79 push @res, " " x ($indent_level+1), "(children)\n" if $el->children;
80 } elsif ($type eq 'Footnote') {
82 push @res, " " x ($indent_level+1), "(definition)\n";
83 push @res, $self->_dump($el->def, $indent_level+1);
85 push @res, " " x ($indent_level+1), "(children)\n" if $el->children;
86 } elsif ($type eq 'ListItem') {
88 push @res, " " x ($indent_level+1), "(description term)\n";
89 push @res, $self->_dump($el->desc_term, $indent_level+1);
91 push @res, " " x ($indent_level+1), "(children)\n" if $el->children;
95 push @res, $self->_dump($_, $indent_level+1) for @{ $el->children };
101 sub _format_properties {
103 #use Data::Dump::OneLine qw(dump1); return dump1($props);
105 for my $k (sort keys %$props) {
106 my $v = $props->{$k};
107 if (ref($v) eq 'ARRAY') {
108 $v = "[" . join(",", map {printable($_)} @$v). "]";
114 "{" . join(", ", @s) . "}";
118 #ABSTRACT: Show Org document/element object in a human-friendly format
127 Org::Dump - Show Org document/element object in a human-friendly format
137 =for Pod::Coverage new
139 =head2 dump_element($elem) => STR
143 Steven Haryanto <stevenharyanto@gmail.com>
145 =head1 COPYRIGHT AND LICENSE
147 This software is copyright (c) 2012 by Steven Haryanto.
149 This is free software; you can redistribute it and/or modify it under
150 the same terms as the Perl 5 programming language system itself.