| 1 | # Copyrights 2003-2018 by [Mark Overmeer <markov@cpan.org>]. | ||
| 2 | # For other contributors see ChangeLog. | ||
| 3 | # See the manual pages for details on the licensing terms. | ||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||
| 5 | # This code is part of distribution HTML-FromMail. Meta-POD processed with | ||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||
| 8 | |||
| 9 | package HTML::FromMail::Format::OODoc; | ||
| 10 | use vars '$VERSION'; | ||
| 11 | $VERSION = '0.12'; | ||
| 12 | |||
| 13 | use base 'HTML::FromMail::Format'; | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use warnings; | ||
| 17 | |||
| 18 | use Carp; | ||
| 19 | use OODoc::Template; | ||
| 20 | |||
| 21 | |||
| 22 | sub init($) | ||
| 23 | { my ($self, $args) = @_; | ||
| 24 | |||
| 25 | $self->SUPER::init($args) or return; | ||
| 26 | $self; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub export($@) | ||
| 30 | { my ($self, %args) = @_; | ||
| 31 | |||
| 32 | my $oodoc = $self->{HFFM_oodoc} = OODoc::Template->new; | ||
| 33 | |||
| 34 | my $output = $args{output}; | ||
| 35 | $self->log(ERROR => "Cannot write to $output: $!"), return | ||
| 36 | unless open my($out), ">", $output; | ||
| 37 | |||
| 38 | my $input = $args{input}; | ||
| 39 | $self->log(ERROR => "Cannot open template file $input: $!"), return | ||
| 40 | unless open my($in), "<", $input; | ||
| 41 | |||
| 42 | my $template = join '', <$in>; | ||
| 43 | close $in; | ||
| 44 | |||
| 45 | my %defaults = | ||
| 46 | ( DYNAMIC => sub { $self->expand(\%args, @_) } | ||
| 47 | ); | ||
| 48 | |||
| 49 | my $oldout = select $out; | ||
| 50 | $oodoc->parse($template, \%defaults); | ||
| 51 | select $oldout; | ||
| 52 | |||
| 53 | close $out; | ||
| 54 | $self; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | sub oodoc() { shift->{HFFM_oodoc} } | ||
| 59 | |||
| 60 | |||
| 61 | sub expand($$$) | ||
| 62 | { my ($self, $args, $tag, $attrs, $textref) = @_; | ||
| 63 | |||
| 64 | # Lookup the method to be called. | ||
| 65 | my $method = 'html' . ucfirst($tag); | ||
| 66 | my $prod = $args->{producer}; | ||
| 67 | |||
| 68 | return undef unless $prod->can($method); | ||
| 69 | |||
| 70 | my %info = (%$args, %$attrs, textref => $textref); | ||
| 71 | $prod->$method($args->{object}, \%info); | ||
| 72 | } | ||
| 73 | |||
| 74 | sub containerText($) | ||
| 75 | { my ($self, $args) = @_; | ||
| 76 | my $textref = $args->{textref}; | ||
| 77 | defined $textref ? $$textref : undef; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub processText($$) | ||
| 81 | { my ($self, $text, $args) = @_; | ||
| 82 | $self->oodoc->parse($text, {}); | ||
| 83 | } | ||
| 84 | |||
| 85 | sub lookup($$) | ||
| 86 | { my ($self, $what, $args) = @_; | ||
| 87 | $self->oodoc->valueFor($what); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub onFinalToken($) | ||
| 91 | { my ($self, $args) = @_; | ||
| 92 | not (defined $args->{textref} && defined ${$args->{textref}}); | ||
| 93 | } | ||
| 94 | |||
| 95 | 1; |