| 1 | package UR::Doc::Writer::Pod; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use UR; | ||
| 7 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 8 | |||
| 9 | use UR::Doc::Section; | ||
| 10 | use Carp qw/croak/; | ||
| 11 | |||
| 12 | class UR::Doc::Writer::Pod { | ||
| 13 | is => 'UR::Doc::Writer', | ||
| 14 | }; | ||
| 15 | |||
| 16 | sub render { | ||
| 17 | my $self = shift; | ||
| 18 | $self->content(''); | ||
| 19 | $self->_render_header; | ||
| 20 | $self->_render_index; | ||
| 21 | map { $self->_render_section($_) } $self->sections; | ||
| 22 | $self->_render_footer; | ||
| 23 | return $self->content; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub _render_header { | ||
| 27 | my $self = shift; | ||
| 28 | |||
| 29 | $self->_append("\n\n=pod\n\n"); | ||
| 30 | if (my $title = $self->title) { | ||
| 31 | $self->_append("=head1 $title\n\n"); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | sub _render_index { | ||
| 36 | # no indexing for pod | ||
| 37 | } | ||
| 38 | |||
| 39 | sub _render_section { | ||
| 40 | my ($self, $section) = @_; | ||
| 41 | my $title = $section->title; | ||
| 42 | $self->_append("=head1 $title\n") if $title; | ||
| 43 | my $content = $section->content; | ||
| 44 | if ($section->format eq 'html') { | ||
| 45 | $self->warning_message("Skipping html section '$title' while rendering pod"); | ||
| 46 | } elsif ($section->format eq 'txt' or $section->format eq 'pod') { | ||
| 47 | $self->_append("\n\n=pod\n\n$content\n\n=cut\n\n"); | ||
| 48 | } else{ | ||
| 49 | croak "Unknown section type " . $section->type; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | sub _render_footer { | ||
| 54 | my $self = shift; | ||
| 55 | } | ||
| 56 | |||
| 57 | 1; |